Skip to content

Commit 534c707

Browse files
authored
fix:修复 Sitemap 插件在分类/标签无内容时导致谷歌无法读取站点地图的问题 (#201)
原因: 当分类或标签下没有文章时,获取最新文章时间返回 null, 导致 sitemap 生成异常,Google 抓取时报“无法读取站点地图”。 解决: 当分类/标签下无内容时,跳过对应 URL 节点,避免输出非法时间字段。 Issue: #151
1 parent 72f7ce9 commit 534c707

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

Sitemap/Action.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ public function action()
8080
->where('table.relationships.mid = ?', $cates->mid)
8181
->order('table.relationships.cid', Typecho_Db::SORT_DESC)
8282
->limit(1));
83+
//文章的分类跳过
84+
if (empty($art_rs['modified'])) continue;
8385
echo "\t<url>\n";
8486
echo "\t\t<loc>".$cates->permalink."</loc>\n";
8587
echo "\t\t<lastmod>".date('Y-m-d',$art_rs['modified'])."</lastmod>\n";
@@ -95,6 +97,9 @@ public function action()
9597
->where('table.relationships.mid = ?', $tag['mid'])
9698
->order('table.relationships.cid', Typecho_Db::SORT_DESC)
9799
->limit(1));
100+
// 文章的标签跳过
101+
if (empty($art_rt['modified'])) continue;
102+
98103
$routeExists = (NULL != Typecho_Router::get($type));
99104
$tag['pathinfo'] = $routeExists ? Typecho_Router::url($type, $tag) : '#';
100105
$tag['permalink'] = Typecho_Common::url($tag['pathinfo'], $options->index);

0 commit comments

Comments
 (0)