




























今天早上醒的特别早,也睡不着了,躺着也没啥意思,起来捣鼓博客吧,自从主题及系统升级完后一直还没测试过站内搜索的功能,尝试一下,结果发现问题,这篇文章做个记录。
这个问题不一定其它朋友遇到,但是我是真遇到了,这个博客永久链接地址设置了自定义地址 /archives/{slug}.html 。
搜索完成后,地址链接错误,给出的链接地址还是 https://9sb.net/archives/{slug}.html 不是真实的文章链接地址,随后找 AI 解决一下。
找到插件目录Action.php文件,找到原代码:
private function formatResult($post, $matchType, $snippet = null)
{
// 根据类型生成正确的URL
$type = $post['type'];
$cid = $post['cid'];
$slug = isset($post['slug']) ? $post['slug'] : '';
if ($type === 'page') {
// 独立页面使用slug生成URL
$url = Typecho_Router::url('page', array('cid' => $cid, 'slug' => $slug));
} else {
// 文章使用默认路由
$url = Typecho_Router::url('post', array('cid' => $cid));
}
$result = array(
'title' => $post['title'],
'url' => $url,
'date' => date('Y-m-d', $post['created']),
'matchType' => $matchType,
'contentSnippet' => $snippet
);
return $result;
}直接更换为:
private function formatResult($post, $matchType, $snippet = null)
{
$type = $post['type'];
$slug = isset($post['slug']) ? $post['slug'] : '';
$siteUrl = rtrim(Helper::options()->siteUrl, '/');
if ($type === 'page') {
// 独立页面沿用系统原生路由
$url = Typecho_Router::url('page', array('cid' => $post['cid'], 'slug' => $slug));
} else {
// 文章强制适配自定义永久链接 /archives/{slug}.html
$url = $siteUrl . '/archives/' . htmlspecialchars($slug) . '.html';
}
$result = array(
'title' => $post['title'],
'url' => $url,
'date' => date('Y-m-d', $post['created']),
'matchType' => $matchType,
'contentSnippet' => $snippet
);
return $result;
}
然后再去测试,问题已经解决,OK 收工。
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。