diff --git a/app/builder.py b/app/builder.py index 8a7ccfe..c33af61 100644 --- a/app/builder.py +++ b/app/builder.py @@ -36,6 +36,11 @@ def output_path(dist,route): if not target.is_relative_to(dist.resolve()):raise ValueError('非法生成目标目录') return out +def copy_blocks_css(theme_dir,dist_assets): + """Theme-provided blocks.css wins; platform default is the fallback.""" + src=theme_dir/'blocks.css' if (theme_dir/'blocks.css').is_file() else ROOT/'app'/'static'/'blocks.css' + shutil.copy2(src,dist_assets/'blocks.css') + def link(path): return (path or '/').lstrip('/') or './' @@ -188,7 +193,7 @@ def build(site_id,mirror=False): theme_pin=theme_store.pinned(site_id) theme_dir=theme_store.resolve(site['theme'],theme_pin['version'] if theme_pin and theme_pin['theme_id']==site['theme'] else None) shutil.copy2(theme_dir/'theme.css',dist/'assets'/'theme.css') - shutil.copy2(ROOT/'app'/'static'/'blocks.css',dist/'assets'/'blocks.css') + copy_blocks_css(theme_dir,dist/'assets') shutil.copy2(ROOT/'app'/'static'/'pro-base.css',dist/'assets'/'pro-base.css') shutil.copy2(ROOT/'app'/'static'/'commercial.css',dist/'assets'/'commercial.css') visuals=theme_dir/'visual' diff --git a/tests/test_theme_registry.py b/tests/test_theme_registry.py index 7a73c17..6941b98 100644 --- a/tests/test_theme_registry.py +++ b/tests/test_theme_registry.py @@ -91,3 +91,16 @@ def test_env_for_degraded_branch_not_cached_and_single_path(tmp_path, monkeypatc assert 'industrial' not in theme_pro._ENVS finally: core.THEMES = core.discover_themes() + +def test_theme_blocks_css_overrides_platform(tmp_path): + from app import builder + dist = tmp_path / 'assets'; dist.mkdir() + theme_dir = tmp_path / 'theme'; theme_dir.mkdir() + (theme_dir / 'blocks.css').write_text('/* theme version */', encoding='utf-8') + builder.copy_blocks_css(theme_dir, dist) + assert (dist / 'blocks.css').read_text(encoding='utf-8') == '/* theme version */' + # 无主题版时回落平台版 + dist2 = tmp_path / 'assets2'; dist2.mkdir() + builder.copy_blocks_css(tmp_path / 'nonexistent', dist2) + assert (dist2 / 'blocks.css').is_file() + assert (dist2 / 'blocks.css').read_text(encoding='utf-8') != '/* theme version */'