fix: restyle pager chips and restore theme ad slots
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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user