feat: theme-level blocks.css takes priority over platform asset

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
浅念
2026-10-22 17:49:12 +08:00
parent 712ccac058
commit 960f7b1002
2 changed files with 19 additions and 1 deletions
+6 -1
View File
@@ -36,6 +36,11 @@ def output_path(dist,route):
if not target.is_relative_to(dist.resolve()):raise ValueError('非法生成目标目录') if not target.is_relative_to(dist.resolve()):raise ValueError('非法生成目标目录')
return out 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): def link(path):
return (path or '/').lstrip('/') or './' return (path or '/').lstrip('/') or './'
@@ -188,7 +193,7 @@ def build(site_id,mirror=False):
theme_pin=theme_store.pinned(site_id) 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) 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(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'/'pro-base.css',dist/'assets'/'pro-base.css')
shutil.copy2(ROOT/'app'/'static'/'commercial.css',dist/'assets'/'commercial.css') shutil.copy2(ROOT/'app'/'static'/'commercial.css',dist/'assets'/'commercial.css')
visuals=theme_dir/'visual' visuals=theme_dir/'visual'
+13
View File
@@ -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 assert 'industrial' not in theme_pro._ENVS
finally: finally:
core.THEMES = core.discover_themes() 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 */'