fix: restyle pager chips and restore theme ad slots
Build and Deploy / verify (push) Successful in 37s
Build and Deploy / deploy (push) Successful in 38s

Replace the loose page-count label with a SaBlog-style 6 / 316 chip, wire inject/stylevar HTML into list and post views, and flush page cache when ads are saved.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
gouki
2026-09-18 21:48:24 +00:00
co-authored by Cursor
parent ae47447062
commit 36c4ffc5b4
41 changed files with 936 additions and 81 deletions
+63
View File
@@ -34,6 +34,24 @@ class ThemeInjector
'body_end' => '页面末尾(</body> 前)',
];
/**
* Old SaBlog stylevar names → inject points. Unmapped HTML vars go to footer.
*
* @var array<string, list<string>>
*/
public const STYLEVAR_POINTS = [
'head' => ['ad_head', 'headad'],
'header' => ['headerad', 'header_ad', 'ad_header', 'topad', 'ad_top', 'sitead', 'site_ad'],
'sidebar_top' => ['sidebarad', 'sidebar_ad', 'ad_sidebar', 'leftad', 'ad_left'],
'sidebar_bottom' => ['ad_sidebar_bottom'],
'content_top' => ['indexad', 'ad_index', 'contentad', 'ad_content'],
'content_bottom' => ['ad_content_bottom'],
'post_content_top' => ['ad_post_top', 'insad'],
'post_content_bottom' => ['ad_post_bottom'],
'footer' => ['footerad', 'footer_ad', 'ad_footer', 'huangjinlian', 'huangjinlian2', 'huangjinlian3'],
'body_end' => ['ad_body_end'],
];
/**
* 读取某一注入点的所有注入块(多条,已排序、已过滤停用),
* 并把插件追加的 HTML 合并进来。
@@ -51,6 +69,10 @@ class ThemeInjector
->values()
->all();
foreach (self::stylevarBlocks($point) as $html) {
$blocks[] = $html;
}
$extra = (string) app(PluginManager::class)->applyFilters("theme.inject.{$point}", '');
if ($extra !== '') {
@@ -75,4 +97,45 @@ class ThemeInjector
}
});
}
/**
* @return list<string>
*/
private static function stylevarBlocks(string $point): array
{
$vars = app(ThemeManager::class)->variables();
if ($vars === []) {
return [];
}
$html = [];
foreach (self::STYLEVAR_POINTS[$point] ?? [] as $key) {
$value = trim((string) ($vars[$key] ?? ''));
if ($value !== '') {
$html[] = $value;
}
}
if ($point !== 'footer') {
return $html;
}
$mapped = [];
foreach (self::STYLEVAR_POINTS as $keys) {
foreach ($keys as $key) {
$mapped[$key] = true;
}
}
foreach ($vars as $key => $value) {
$value = trim((string) $value);
if ($value === '' || isset($mapped[$key]) || ! str_contains($value, '<')) {
continue;
}
$html[] = $value;
}
return $html;
}
}