diff --git a/Sitemap/Action.php b/Sitemap/Action.php new file mode 100644 index 0000000..e125c3f --- /dev/null +++ b/Sitemap/Action.php @@ -0,0 +1,66 @@ +fetchAll($db->select()->from('table.contents') + ->where('table.contents.status = ?', 'publish') + ->where('table.contents.created < ?', $options->gmtTime) + ->where('table.contents.type = ?', 'page') + ->order('table.contents.created', Typecho_Db::SORT_DESC)); + + $articles = $db->fetchAll($db->select()->from('table.contents') + ->where('table.contents.status = ?', 'publish') + ->where('table.contents.created < ?', $options->gmtTime) + ->where('table.contents.type = ?', 'post') + ->order('table.contents.created', Typecho_Db::SORT_DESC)); + + header("Content-Type: application/xml"); + echo "\n"; + echo "pluginUrl . "/Sitemap/sitemap.xsl'?>\n"; + echo ""; + foreach($articles AS $article) { + $type = $article['type']; + $article['categories'] = $db->fetchAll($db->select()->from('table.metas') + ->join('table.relationships', 'table.relationships.mid = table.metas.mid') + ->where('table.relationships.cid = ?', $article['cid']) + ->where('table.metas.type = ?', 'category') + ->order('table.metas.order', Typecho_Db::SORT_ASC)); + $article['category'] = urlencode(current(Typecho_Common::arrayFlatten($article['categories'], 'slug'))); + $article['slug'] = urlencode($article['slug']); + $article['date'] = new Typecho_Date($article['created']); + $article['year'] = $article['date']->year; + $article['month'] = $article['date']->month; + $article['day'] = $article['date']->day; + $routeExists = (NULL != Typecho_Router::get($type)); + $article['pathinfo'] = $routeExists ? Typecho_Router::url($type, $article) : '#'; + $article['permalink'] = Typecho_Common::url($article['pathinfo'], $options->index); + + echo "\t\n"; + echo "\t\t".$article['permalink']."\n"; + echo "\t\t".date('Y-m-d\TH:i:s\Z',$article['modified'])."\n"; + echo "\t\talways\n"; + echo "\t\t0.8\n"; + echo "\t\n"; + } + + foreach($pages AS $page) { + $type = $page['type']; + $routeExists = (NULL != Typecho_Router::get($type)); + $page['pathinfo'] = $routeExists ? Typecho_Router::url($type, $page) : '#'; + $page['permalink'] = Typecho_Common::url($page['pathinfo'], $options->index); + + echo "\t\n"; + echo "\t\t".$page['permalink']."\n"; + echo "\t\t".date('Y-m-d\TH:i:s\Z',$page['modified'])."\n"; + echo "\t\talways\n"; + echo "\t\t0.6\n"; + echo "\t\n"; + } + + echo ""; + } +} diff --git a/Sitemap/Plugin.php b/Sitemap/Plugin.php new file mode 100644 index 0000000..18a7ae1 --- /dev/null +++ b/Sitemap/Plugin.php @@ -0,0 +1,55 @@ +Ty开发 + * + * @package XML Sitemap + * @author Ty + * @version 0.0.1 + * @link https://tyblog.com.cn + */ +class Sitemap_Plugin implements Typecho_Plugin_Interface +{ + /** + * 激活插件方法,如果激活失败,直接抛出异常 + * + * @access public + * @return void + * @throws Typecho_Plugin_Exception + */ + public static function activate() + { + Helper::addRoute('sitemap', '/sitemap-maker.xml', 'Sitemap_Action', 'action'); + } + + /** + * 禁用插件方法,如果禁用失败,直接抛出异常 + * + * @static + * @access public + * @return void + * @throws Typecho_Plugin_Exception + */ + public static function deactivate() + { + Helper::removeRoute('sitemap'); + } + + /** + * 获取插件配置面板 + * + * @access public + * @param Typecho_Widget_Helper_Form $form 配置面板 + * @return void + */ + public static function config(Typecho_Widget_Helper_Form $form){} + + /** + * 个人用户的配置面板 + * + * @access public + * @param Typecho_Widget_Helper_Form $form + * @return void + */ + public static function personalConfig(Typecho_Widget_Helper_Form $form){} + +} diff --git a/Sitemap/README.md b/Sitemap/README.md new file mode 100644 index 0000000..50c9dd1 --- /dev/null +++ b/Sitemap/README.md @@ -0,0 +1,35 @@ +## 系统要求 +- [CentOS7.0][1]及以后版本(其他Linux系统未验证可用性) +- [宝塔面板][2] +- [PHP7.4][3]及以后版本(PHP8.0未验证可用性) +- Typecho1.1及以后版本 +## 插件必要设置 +1.打开宝塔面板,点击‘网站’,点击对应网站的‘设置’ + +2.点击‘伪静态’,左上角选择‘typecho’,点击‘保存’ + +![伪静态配置][5] + +3.进入typecho后台,点击‘设置->永久链接’ + +4.启用‘地址重写功能’ +## 插件安装 +1.在GitHub[下载][6]插件 + +2.将‘sitemap’目录上传到网站服务器‘/usr/plugins’目录下 + +3.进入Typecho后台启用插件 +## 插件使用 +**访问http(s)://你的域名/sitemap-maker.xml即可生成XML sitemap** +> Demo:[https://tyblog.com.cn/sitemap-maker.xml][7] +## 支持 +在[GitHub][8]提issue + + + [1]: https://www.centos.org + [2]: https://bt.cn + [3]: https://www.php.net + [5]: http://image-cdn-tyblog.test.upcdn.net/sitemap-plugin/1.png + [6]: https://github.com/ty-yqs/Typecho-Sitemap-Plugin + [7]: https://tyblog.com.cn/sitemap-maker.xml + [8]: https://github.com/ty-yqs/Typecho-Sitemap-Plugin/issues/new diff --git a/Sitemap/sitemap.xsl b/Sitemap/sitemap.xsl new file mode 100644 index 0000000..5fb60e0 --- /dev/null +++ b/Sitemap/sitemap.xsl @@ -0,0 +1,112 @@ + + + + + + + XML Sitemap + + + + +

XML Sitemap

+
+

+ This XML sitemap plugin was made by Ty +

+
+
+ + + + + + + + + + + + + ood + + + even + + + + + + + +
URLPriorityChange FrequencyLastChange
+ + + + + + + + + + + + +
+
+ + +
+