mirror of
https://gitee.com/ulthon/ulthon_information.git
synced 2026-03-04 00:24:29 +08:00
新增sitemap
This commit is contained in:
@@ -9,6 +9,7 @@ use app\model\Post as ModelPost;
|
|||||||
use app\model\PostCategory;
|
use app\model\PostCategory;
|
||||||
use app\model\PostTag;
|
use app\model\PostTag;
|
||||||
use app\model\Tag;
|
use app\model\Tag;
|
||||||
|
use think\facade\Cache;
|
||||||
use think\facade\Route;
|
use think\facade\Route;
|
||||||
use think\facade\View;
|
use think\facade\View;
|
||||||
use think\Request;
|
use think\Request;
|
||||||
@@ -201,8 +202,7 @@ class Post extends Common
|
|||||||
|
|
||||||
$model_post->save($post_data);
|
$model_post->save($post_data);
|
||||||
|
|
||||||
|
Cache::delete('sitemap_last_etag');
|
||||||
|
|
||||||
|
|
||||||
return $this->success('保存成功', url('index', ['type' => $model_post->getData('type')]));
|
return $this->success('保存成功', url('index', ['type' => $model_post->getData('type')]));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,10 +10,34 @@
|
|||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
use app\common\tools\Sitemap;
|
use app\common\tools\Sitemap;
|
||||||
|
use app\Request;
|
||||||
|
use think\facade\Cache;
|
||||||
|
use think\facade\Log;
|
||||||
use think\facade\Route;
|
use think\facade\Route;
|
||||||
|
|
||||||
Route::rule('/site.xml', function () {
|
Route::rule('/site.xml', function (Request $request) {
|
||||||
|
|
||||||
|
$cache_key = 'sitemap_last_etag';
|
||||||
|
|
||||||
|
$last_etag = Cache::get($cache_key);
|
||||||
|
|
||||||
|
if (!empty($cache_key)) {
|
||||||
|
|
||||||
|
$if_not_match = $request->header('If-None-Match');
|
||||||
|
|
||||||
|
if (!empty($if_not_match)) {
|
||||||
|
if ($if_not_match == $last_etag) {
|
||||||
|
Log::debug('sitemap go for etag cache');
|
||||||
|
return xml('', 304)->eTag($last_etag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$content = Sitemap::init();
|
$content = Sitemap::init();
|
||||||
|
|
||||||
return xml($content);
|
$last_etag = md5($content);
|
||||||
|
|
||||||
|
Cache::set($cache_key, $last_etag);
|
||||||
|
|
||||||
|
return xml($content)->eTag($last_etag);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user