fix(widgets): restore article table of contents behavior and styles

This commit is contained in:
kate522 committed 2026-10-30 13:18:40 +08:00
1 parent fc04bf65e6
commit ea80cd96cc
15 files changed
+965 -407

No files matched your search

-10
View File
@@ -546,16 +546,6 @@ trait ScriptsPart1b {
(string) filemtime($pn_css)
);
}
$section_navs = get_template_directory() . '/assets/js/section-navs.js';
if (file_exists($section_navs)) {
wp_enqueue_script(
'aksrt-section-navs',
$base_uri . '/assets/js/section-navs.js',
['jquery'],
(string) filemtime($section_navs),
true
);
}
$pn_js = get_template_directory() . '/assets/js/posts-navs-page.js';
if (file_exists($pn_js)) {
wp_enqueue_script(
+6 -2
View File
@@ -69,7 +69,6 @@ trait ScriptsPart1c {
'/(?:<!--\s*wp:(?:code|preformatted|aksrt\/enlighter)\b|<pre\b|data-enlighter-language)/i',
$display_content
);
$heading_count = preg_match_all('/<h[1-4]\b/i', $display_content);
$has_hidden_content = $is_paid_content_single || (bool) preg_match(
'/(?:<!--\s*wp:aksrt\/paid-fragment\b|\[(?:aksrt_hide|hide|reply|vip|payshow|hidecontent|content)\b|aksrt-(?:hidden-content|paywall))/i',
$content
@@ -106,10 +105,15 @@ trait ScriptsPart1c {
$layout = function_exists('aksrt_get_post_show_layout')
? (string) aksrt_get_post_show_layout($post_id)
: '';
$article_nav_enabled = !array_key_exists('article_nav', $settings) || !empty($settings['article_nav']);
if ($article_nav_enabled && function_exists('get_post_meta') && class_exists(DomainModel::class)) {
$extension_meta = get_post_meta($post_id, DomainModel::POST_META_KEY, true);
$article_nav_enabled = !is_array($extension_meta) || empty($extension_meta['no_article-navs']);
}
$requirements['is_article'] = $is_article;
$requirements['has_code'] = $has_code;
$requirements['has_toc'] = $is_article && $heading_count >= 2;
$requirements['has_toc'] = $is_article && $article_nav_enabled;
$requirements['has_video'] = $has_video;
$requirements['has_hidden_content'] = $has_hidden_content || $has_yiyan || $has_inserted_content;
$requirements['needs_pay_box'] = $is_paid_content_single || (bool) preg_match('/\[(?:payshow|hidecontent)\b|wp:aksrt\/paid-fragment/i', $content);
+7 -1
View File
@@ -23,6 +23,12 @@ final class FrontendRenderer {
}
AssetManager::enqueue_for($definition);
if ($definition->slug() === 'posts_toc') {
// The TOC renderer owns the reference widget-container wrapper and
// displays its title inside the generated directory, not above it.
echo $content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
return;
}
if (in_array($definition->slug(), ['user_card', 'author_card', 'tab_posts', 'posts'], true)) {
self::render_reference_widget($definition, $instance, $widget, $content);
return;
@@ -31,7 +37,7 @@ final class FrontendRenderer {
'post_pay', 'oneline_posts', 'hot_posts',
'slider', 'slider_media_combo', 'icon_cards', 'icon_cover_cards',
'buttons', 'notice', 'term_cards', 'term_aggregation', 'media_cards',
'combo_info', 'partners', 'recent_comments', 'posts_toc',
'combo_info', 'partners', 'recent_comments',
], true)) {
echo (string) ($args['before_widget'] ?? '');
if ($definition->slug() !== 'post_pay') echo self::reference_title($instance);
+3 -1
View File
@@ -72,7 +72,9 @@ final class WidgetCatalog {
'common' => [
'title' => !in_array($slug, ['post_pay', 'layout_gap', 'slider', 'slider_media_combo', 'buttons', 'posts_toc'], true),
'affix' => ($size === 'sidebar' && $slug !== 'posts_toc') || in_array($slug, ['buttons', 'notice', 'posts'], true),
'animation' => !in_array($slug, ['buttons', 'term_cards', 'term_aggregation', 'media_cards', 'combo_info', 'slider_media_combo'], true),
'visibility' => $slug !== 'posts_toc',
'layout' => $slug !== 'posts_toc',
'animation' => !in_array($slug, ['buttons', 'term_cards', 'term_aggregation', 'media_cards', 'combo_info', 'slider_media_combo', 'posts_toc'], true),
],
'fields' => WidgetSchemas::for($slug),
'assets' => self::assets($slug),