From 66b9872df3f49104b1484ec83843132f1b9354f2 Mon Sep 17 00:00:00 2001 From: Ty <61855011+ty-yqs@users.noreply.github.com> Date: Thu, 31 Dec 2020 22:15:51 +0800 Subject: [PATCH 1/5] Create Plugin.php --- Sitemap/Plugin.php | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Sitemap/Plugin.php 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){} + +} From 9790ee99effe840166eb995bf7d08d45b3e95c8b Mon Sep 17 00:00:00 2001 From: Ty <61855011+ty-yqs@users.noreply.github.com> Date: Thu, 31 Dec 2020 22:16:44 +0800 Subject: [PATCH 2/5] Create Action.php --- Sitemap/Action.php | 66 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 Sitemap/Action.php 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 ""; + } +} From b7988666cdd530744697bd871942d2dd1a7c4187 Mon Sep 17 00:00:00 2001 From: Ty <61855011+ty-yqs@users.noreply.github.com> Date: Thu, 31 Dec 2020 22:17:25 +0800 Subject: [PATCH 3/5] Create sitemap.xsl --- Sitemap/sitemap.xsl | 112 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 Sitemap/sitemap.xsl 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
+ + + + + + + + + + + + +
+
+ + +
+
From fded6466bbe08ae88ffbcdd52629512a44cd3964 Mon Sep 17 00:00:00 2001 From: Ty <61855011+ty-yqs@users.noreply.github.com> Date: Thu, 31 Dec 2020 23:03:06 +0800 Subject: [PATCH 4/5] Create README.md --- Sitemap/README.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Sitemap/README.md diff --git a/Sitemap/README.md b/Sitemap/README.md new file mode 100644 index 0000000..2d6c180 --- /dev/null +++ b/Sitemap/README.md @@ -0,0 +1,31 @@ +## 系统要求 +- [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 From bb9d1a30e248c8ac6a913db34b54a4e5c7d00be7 Mon Sep 17 00:00:00 2001 From: Ty <61855011+ty-yqs@users.noreply.github.com> Date: Thu, 31 Dec 2020 23:03:36 +0800 Subject: [PATCH 5/5] Update README.md --- Sitemap/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sitemap/README.md b/Sitemap/README.md index 2d6c180..50c9dd1 100644 --- a/Sitemap/README.md +++ b/Sitemap/README.md @@ -5,15 +5,19 @@ - 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**