mirror of
https://gitee.com/ulthon/ulthon_information.git
synced 2026-03-03 16:24:28 +08:00
新增sietmap
This commit is contained in:
55
app/common/tools/Sitemap.php
Normal file
55
app/common/tools/Sitemap.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\tools;
|
||||
|
||||
use app\model\Post;
|
||||
use DateTime;
|
||||
use Thepixeldeveloper\Sitemap\Drivers\XmlWriterDriver;
|
||||
use Thepixeldeveloper\Sitemap\Url;
|
||||
use Thepixeldeveloper\Sitemap\Urlset;
|
||||
use think\facade\Request;
|
||||
|
||||
class Sitemap
|
||||
{
|
||||
public static function init()
|
||||
{
|
||||
|
||||
// $urlset_page_list = new Urlset();
|
||||
|
||||
$urlset_page_post = new Urlset();
|
||||
|
||||
$index_url = new Url(Request::scheme() . '://' . get_system_config('main_domain', Request::host()));
|
||||
|
||||
$index_url->setChangeFreq('always');
|
||||
|
||||
$index_url->setPriority(0.9);
|
||||
|
||||
$urlset_page_post->add($index_url);
|
||||
|
||||
$list_post = Post::cache(60)->where('status',1)->select();
|
||||
|
||||
foreach ($list_post as $model_post){
|
||||
$url_post = new Url($model_post->read_url);
|
||||
$url_post->setChangeFreq('yearly');
|
||||
|
||||
$last_mod_date = new DateTime($model_post->publish_time_datetime);
|
||||
|
||||
$url_post->setLastMod($last_mod_date);
|
||||
|
||||
$url_post->setPriority(0.9);
|
||||
|
||||
$urlset_page_post->add($url_post);
|
||||
|
||||
}
|
||||
|
||||
|
||||
$dirver = new XmlWriterDriver();
|
||||
// $urlset_page_list->accept($dirver);
|
||||
|
||||
$urlset_page_post->accept($dirver);
|
||||
|
||||
return $dirver->output();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,8 @@
|
||||
"topthink/think-helper": "^3.1",
|
||||
"topthink/think-captcha": "^3.0",
|
||||
"topthink/think-multi-app": "^1.0",
|
||||
"ulthon/user_hub_client": "^1.0"
|
||||
"ulthon/user_hub_client": "^1.0",
|
||||
"thepixeldeveloper/sitemap": "^5.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/var-dumper": "^4.2"
|
||||
|
||||
@@ -8,4 +8,12 @@
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
use think\facade\Route;
|
||||
|
||||
use app\common\tools\Sitemap;
|
||||
use think\facade\Route;
|
||||
|
||||
Route::rule('/site.xml', function () {
|
||||
$content = Sitemap::init();
|
||||
|
||||
return xml($content);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user