#!/usr/bin/env python3 """Build lightweight /learn/* pages without MindSpace injection.""" import re from pathlib import Path ROOT = Path(__file__).resolve().parents[1] SRC = ROOT / 'MindSpace/a70ff537-8908-486e-9b6c-042e07cc25db/public' OUT = ROOT / 'public/learn' VER = '20260915j' CHILD_PAGE = 'dcb1f3f0-db96-4dab-a009-7a9c393ebe77' PARENT_PAGE = 'f9c80392-9417-46fd-af89-a91a239d3bfc' def extract_style(html: str) -> str: m = re.search(r'', html) return m.group(1) if m else '' def extract_app_script(html: str) -> str: m = re.search(r'', html) if not m: raise ValueError('app script not found') return m.group(1) def shell(title: str, style: str, page_id: str, access: str, body: str, script: str) -> str: access_json = '{"pageId":"%s","accessMode":"%s"}' % (page_id, access) return f''' {title} {body} ''' def main(): OUT.mkdir(parents=True, exist_ok=True) child_src = (SRC / 'learning-assistant.html').read_text(encoding='utf-8') parent_src = (SRC / 'learning-assistant-parent.html').read_text(encoding='utf-8') child_style = extract_style(child_src) parent_style = extract_style(parent_src) child_script = extract_app_script(child_src) parent_script = extract_app_script(parent_src) child_script = child_script.replace('learning-assistant-parent.html', '/learn/parent.html') parent_script = parent_script.replace('learning-assistant.html', '/learn/') child_body = '''
加载中…
''' parent_body = '''
加载中…
''' (OUT / 'index.html').write_text( shell('我的学习小助手', child_style, CHILD_PAGE, 'public', child_body, child_script), encoding='utf-8', ) (OUT / 'parent.html').write_text( shell('家长后台', parent_style, PARENT_PAGE, 'password', parent_body, parent_script), encoding='utf-8', ) data_js = (SRC / 'learning-assistant-data.js').read_text(encoding='utf-8') data_js = re.sub(r'DATA_VER="[^"]+"', f'DATA_VER="{VER}"', data_js) (OUT / 'learning-assistant-data.js').write_text(data_js, encoding='utf-8') print('built', OUT) print(' index.html', (OUT / 'index.html').stat().st_size, 'bytes') print(' parent.html', (OUT / 'parent.html').stat().st_size, 'bytes') if __name__ == '__main__': main()