redundant_prefix, '', $header['description']); // 描述优先保留当前页面自己的内容,只有为空时才回退到站点默认描述 $site_default_desc = strip_tags($default_header['description']); $current_desc_stripped = strip_tags($header['description']); $header['description'] = empty($current_desc_stripped) ? $site_default_desc : $current_desc_stripped; // 强制同步 og:description,解决内容不一致问题 $header['og_description'] = $header['description']; // 为帖子页切换更准确的 Open Graph 类型 if (preg_match('/\/thread-\d+(-\d+)?\.htm/', $current_path)) { $header['og_type'] = 'article'; } // 低价值页与参数页使用 noindex,follow,避免消耗收录预算 $should_noindex = false; if ( preg_match('/^\/search\.htm$/', $current_path) || preg_match('/^\/user\-(login|create|resetpw|resetpw_complete)\.htm$/', $current_path) || strpos($current_path, '/my-') === 0 || preg_match('/^\/thread-create(\-\d+)?\.htm$/', $current_path) || preg_match('/^\/post-update-\d+\.htm$/', $current_path) || preg_match('/^\/post-create-\d+-\d+(\-\d+)?\.htm$/', $current_path) ) { $should_noindex = true; } if (strpos($current_path, '/domain-market') === 0 && !empty($current_query)) { $should_noindex = true; } if ($should_noindex) { $header['robots'] = 'noindex,follow'; } // 输出 meta 标签 echo "\t" . '' . "\n"; echo "\t" . '' . "\n"; if (!empty($header['image'])) { echo "\t" . '' . "\n"; } if (!empty($header['robots'])) { echo "\t" . '' . "\n"; } // 输出 Canonical 标签 (规范化链接) $canonical_url = !empty($header['canonical_url']) ? $header['canonical_url'] : ''; if (empty($canonical_url)) { $canonical_url = $canonical_base . $current_path; } $header['og_url'] = $canonical_url; if ($canonical_url) { echo "\t" . '' . "\n"; } // 输出 JSON-LD 结构化数据 (面包屑导航) if (!empty($header['breadcrumb'])) { $json_ld = [ "@context" => "https://schema.org", "@type" => "BreadcrumbList", "itemListElement" => [] ]; $position = 1; foreach ($header['breadcrumb'] as $name => $url) { $breadcrumb_item_url = (strpos($url, 'http') === 0) ? $url : $canonical_base . '/' . ltrim($url, '/'); $json_ld['itemListElement'][] = [ "@type" => "ListItem", "position" => $position++, "name" => strip_tags($name), "item" => $breadcrumb_item_url ]; } echo "\t" . '' . "\n"; } ?>