diff --git a/scripts/gen_home_index.py b/scripts/gen_home_index.py index b69d10b..adf51e4 100644 --- a/scripts/gen_home_index.py +++ b/scripts/gen_home_index.py @@ -9,24 +9,37 @@ IDX = os.path.join(ROOT, 'wwwroot', 'index.ui') with io.open(IDX, encoding='utf-8') as f: old = f.read() -# 幂等:已生成过则先还原工作区分支(用 git show HEAD 由调用方保证,这里检测标记) -assert '{% if get_user() %}' not in old, 'index.ui 已经是双分支版本,勿重复生成(用 git checkout 还原后重跑)' +# 幂等:若已是双分支版本,先抽出工作台分支(old),再重拼门户分支 +PREFIX = '{% if get_user() %}\n' +MARK = '\n{% else %}\n{' +if old.startswith(PREFIX): + i = old.rfind(MARK) + assert i > 0, 'generated file but marker not found' + old = old[len(PREFIX):i] + '\n' +else: + assert '{% if get_user() %}' not in old, 'unexpected mixed file' def T(s, css=None, **kw): - """TextBase 三件套:otext+text+i18n(W1 规范)""" + """TextBase 三件套:otext+text+i18n(W1 规范)。binds/id 必须在 widget 顶层(bricks 不读 options.binds)。""" o = {'otext': s, 'text': s, 'i18n': True, 'halign': 'left'} if css: o['css'] = css + top = {k: kw.pop(k) for k in ('binds', 'id') if k in kw} o.update(kw) - return {'widgettype': 'Text', 'options': o} + w = {'widgettype': 'Text', 'options': o} + w.update(top) + return w def TN(s, css=None, **kw): - """不翻译的 Text(数字/英文装饰字)""" + """不翻译的 Text(数字/英文装饰字)。binds/id 同样提到顶层。""" o = {'text': s, 'halign': 'left'} if css: o['css'] = css + top = {k: kw.pop(k) for k in ('binds', 'id') if k in kw} o.update(kw) - return {'widgettype': 'Text', 'options': o} + w = {'widgettype': 'Text', 'options': o} + w.update(top) + return w def login_bind(): return {'wid': 'self', 'event': 'click', 'actiontype': 'urlwidget', 'target': 'self', diff --git a/wwwroot/index.ui b/wwwroot/index.ui index 2c6c029..4a3757a 100644 --- a/wwwroot/index.ui +++ b/wwwroot/index.ui @@ -724,6 +724,7 @@ } ] } + {% else %} { "id": "app", @@ -796,17 +797,17 @@ "i18n": true, "halign": "left", "css": "pl-nav", - "mobile_hidden": true, - "binds": [ - { - "wid": "self", - "event": "click", - "actiontype": "script", - "target": "self", - "script": "var e=document.getElementById(\"sec_caps\");if(e){e.scrollIntoView({behavior:'smooth',block:'start'});}" - } - ] - } + "mobile_hidden": true + }, + "binds": [ + { + "wid": "self", + "event": "click", + "actiontype": "script", + "target": "self", + "script": "var e=document.getElementById(\"sec_caps\");if(e){e.scrollIntoView({behavior:'smooth',block:'start'});}" + } + ] }, { "widgettype": "Text", @@ -816,17 +817,17 @@ "i18n": true, "halign": "left", "css": "pl-nav", - "mobile_hidden": true, - "binds": [ - { - "wid": "self", - "event": "click", - "actiontype": "script", - "target": "self", - "script": "var e=document.getElementById(\"sec_pipes\");if(e){e.scrollIntoView({behavior:'smooth',block:'start'});}" - } - ] - } + "mobile_hidden": true + }, + "binds": [ + { + "wid": "self", + "event": "click", + "actiontype": "script", + "target": "self", + "script": "var e=document.getElementById(\"sec_pipes\");if(e){e.scrollIntoView({behavior:'smooth',block:'start'});}" + } + ] }, { "widgettype": "Text", @@ -836,17 +837,17 @@ "i18n": true, "halign": "left", "css": "pl-nav", - "mobile_hidden": true, - "binds": [ - { - "wid": "self", - "event": "click", - "actiontype": "script", - "target": "self", - "script": "var e=document.getElementById(\"sec_flow\");if(e){e.scrollIntoView({behavior:'smooth',block:'start'});}" - } - ] - } + "mobile_hidden": true + }, + "binds": [ + { + "wid": "self", + "event": "click", + "actiontype": "script", + "target": "self", + "script": "var e=document.getElementById(\"sec_flow\");if(e){e.scrollIntoView({behavior:'smooth',block:'start'});}" + } + ] }, { "widgettype": "Button",