refactor(routes): canonical URLs now match sablog format exactly
Build and Deploy / verify (push) Successful in 1m6s
Build and Deploy / deploy (push) Successful in 41s

- /show-{id}.shtml (comments page: /show-{id}-{page}.shtml)
- /category-{cid}.shtml / /category-{cid}-{page}.shtml
- /archives-{YYYYMM}.shtml / /archives-{YYYYMM}-{page}.shtml
- /tag/{name}, /tagslist.shtml, /index-{page}.shtml
- slug 时代的 /posts/{slug} 等旧格式全部 301 到 sablog 格式
This commit is contained in:
2026-09-09 21:21:07 +00:00
parent f6a9a8ea50
commit f5987e7cc2
22 changed files with 113 additions and 70 deletions
+10 -1
View File
@@ -20,8 +20,17 @@ class ArchiveController extends Controller
return theme_view('archives', compact('archives'));
}
public function month(string $year, string $month)
/**
* sablog 格式:/archives-{YYYYMM}.shtml
*/
public function month(string $date)
{
if (! preg_match('/^(\d{4})(\d{2})$/', $date, $m)) {
abort(404);
}
[$year, $month] = [$m[1], $m[2]];
$start = Carbon::create((int) $year, (int) $month, 1)->startOfMonth();
$end = (clone $start)->endOfMonth();
+7 -7
View File
@@ -78,7 +78,7 @@ class LegacyController extends Controller
$tag = Tag::findFromString($name, 'post');
return $tag
? redirect()->route('tags.show', $tag->slug ?: $tag->name, 301)
? redirect()->route('tags.show', $tag->name, 301)
: abort(404);
}
@@ -152,7 +152,7 @@ class LegacyController extends Controller
app(\App\Blog\Support\PluginManager::class)->doAction('comment.created', $comment);
return redirect()->route('posts.show', $post->slug ?: $post->id)
return redirect()->route('posts.show', $post->id)
->with($status === 'published' ? 'success' : 'error', $status === 'published' ? '评论已发布' : '评论已提交,等待审核')
->withFragment('comments');
}
@@ -162,7 +162,7 @@ class LegacyController extends Controller
$post = Post::find($id);
return $post
? redirect()->route('posts.show', $post->slug ?: $post->id, 301)
? redirect()->route('posts.show', $post->id, 301)
: abort(404);
}
@@ -171,7 +171,7 @@ class LegacyController extends Controller
$category = Category::find($cid);
return $category
? redirect()->route('category.show', $category->slug ?: $category->id, 301)
? redirect()->route('category.show', $category->id, 301)
: abort(404);
}
@@ -185,8 +185,8 @@ class LegacyController extends Controller
$month = $m[2] ?? null;
return $month
? redirect()->route('archives.month', [$year, $month], 301)
: redirect()->route('archives.month', [$year, '01'], 301);
? redirect()->route('archives.month', $year.$month, 301)
: redirect()->route('archives.month', $year.'01', 301);
}
private function tagList(Request $request)
@@ -198,7 +198,7 @@ class LegacyController extends Controller
$tag = $tagId ? Tag::find((int) $tagId) : Tag::find((int) $request->query('id'));
return $tag
? redirect()->route('tags.show', $tag->slug ?: $tag->name, 301)
? redirect()->route('tags.show', $tag->name, 301)
: abort(404);
}
+8 -3
View File
@@ -14,17 +14,22 @@ class PostController extends Controller
{
}
public function show(string $slug)
public function show(string $id, ?string $page = null)
{
$post = Post::query()
->where('slug', $slug)
->orWhere('id', (int) $slug)
->where('id', (int) $id)
->orWhere('slug', $id)
->first();
abort_unless($post && $post->status === 'published', 404);
$this->ensureReadable($post);
// sablog 式 /show-{id}-{page}.shtml 的评论分页
if ($page !== null) {
\Illuminate\Pagination\Paginator::currentPageResolver(fn () => max(1, (int) $page));
}
// 浏览量由 /track-view 端点统计(页面整页缓存下控制器不执行,避免双计)
$comments = $post->comments()
+5 -2
View File
@@ -28,9 +28,12 @@ class TagController extends Controller
return theme_view('tags', compact('tags'));
}
public function show(string $slug)
/**
* sablog 格式:/tag/{name},按名称(而非 slug)解析
*/
public function show(string $name)
{
$tag = Tag::findFromString($slug, 'post');
$tag = Tag::findFromString(urldecode($name), 'post');
abort_unless($tag, 404);
@@ -32,7 +32,7 @@ class CommentsTable
->label('文章')
->limit(30)
->description(fn ($record) => $record->post ? \Illuminate\Support\Str::limit($record->post->excerpt_or_fallback, 50) : null)
->url(fn ($record) => $record->post ? route('posts.show', $record->post->slug ?: $record->post->id) : null)
->url(fn ($record) => $record->post ? route('posts.show', $record->post->id) : null)
->openUrlInNewTab(),
TextColumn::make('status')
->label('状态')
+2 -2
View File
@@ -110,7 +110,7 @@ class ApiController extends Controller
'views' => $post->views,
'comment_count' => $post->comment_count,
'published_at' => $post->published_at?->toIso8601String(),
'url' => route('posts.show', $post->slug ?: $post->id),
'url' => route('posts.show', $post->id),
]);
}
@@ -237,7 +237,7 @@ class ApiController extends Controller
'views' => $post->views,
'comment_count' => $post->comment_count,
'published_at' => $post->published_at?->toIso8601String(),
'url' => route('posts.show', $post->slug ?: $post->id),
'url' => route('posts.show', $post->id),
];
}
}
+1 -1
View File
@@ -30,7 +30,7 @@ class Category extends Model implements HasMedia
public function getUrlAttribute(): string
{
return route('category.show', $this->slug ?? $this->id);
return route('category.show', $this->id);
}
public function registerMediaCollections(): void
+1 -1
View File
@@ -104,7 +104,7 @@ class Post extends Model implements HasMedia
public function getUrlAttribute(): string
{
return route('posts.show', $this->slug ?? $this->id);
return route('posts.show', $this->id);
}
/**
@@ -75,13 +75,13 @@ class SeoMiddleware
'@context' => 'https://schema.org',
'@type' => 'BlogPosting',
'headline' => $post->title,
'url' => route('posts.show', $post->slug ?: $post->id),
'url' => route('posts.show', $post->id),
'datePublished' => $post->published_at?->toIso8601String(),
'dateModified' => $post->updated_at?->toIso8601String(),
'author' => ['@type' => 'Person', 'name' => $post->author?->name ?? $siteName] + ($sameAs ? ['sameAs' => $sameAs] : []),
'publisher' => ['@type' => 'Organization', 'name' => $siteName, 'url' => url('/')] + ($sameAs ? ['sameAs' => $sameAs] : []),
'description' => Str::limit(strip_tags($post->excerpt_or_fallback), 200),
'mainEntityOfPage' => route('posts.show', $post->slug ?: $post->id),
'mainEntityOfPage' => route('posts.show', $post->id),
];
if ($cover = $post->getFirstMedia('cover')) {
@@ -105,7 +105,7 @@ class SeoMiddleware
'@type' => 'BreadcrumbList',
'itemListElement' => [
['@type' => 'ListItem', 'position' => 1, 'name' => $siteName, 'item' => url('/')],
['@type' => 'ListItem', 'position' => 2, 'name' => $category->name, 'item' => route('category.show', $category->slug ?: $category->id)],
['@type' => 'ListItem', 'position' => 2, 'name' => $category->name, 'item' => route('category.show', $category->id)],
],
];
}
@@ -30,7 +30,7 @@ class SeoController
$lines[] = '';
foreach ($posts as $post) {
$lines[] = '- ['.$post->title.']('.route('posts.show', $post->slug ?: $post->id).') — '.Str::limit(strip_tags($post->excerpt_or_fallback), 120);
$lines[] = '- ['.$post->title.']('.route('posts.show', $post->id).') — '.Str::limit(strip_tags($post->excerpt_or_fallback), 120);
}
return response(implode("\n", $lines)."\n")
@@ -81,7 +81,7 @@ class MembershipController
// 已能读付费内容(会员 / 作者 / 已解锁):直接查看文章,避免重复支付。
// 注意:付费块文章的整篇是公开的,不能用 canReadPost 判断(否则永远"已有权限")
if ($this->service->canReadPaidContent($user, $post)) {
return redirect()->route('posts.show', $post->slug ?? $post->id);
return redirect()->route('posts.show', $post->id);
}
// 单篇付费解锁:创建一笔定向支付
+2 -2
View File
@@ -11,11 +11,11 @@
<ul class="archive-list">
@foreach($months as $month => $monthPosts)
<li>
<a href="{{ route('archives.month', [$year, $month]) }}">{{ (int) $month }} </a>
<a href="{{ route('archives.month', $year.$month) }}">{{ (int) $month }} </a>
<span class="count">({{ $monthPosts->count() }} )</span>
<ul class="archive-posts">
@foreach($monthPosts as $post)
<li><a href="{{ route('posts.show', $post->slug ?: $post->id) }}">{{ $post->title }}</a> <time>{{ $post->published_at->format(blog_setting('listtime', 'm-d')) }}</time></li>
<li><a href="{{ route('posts.show', $post->id) }}">{{ $post->title }}</a> <time>{{ $post->published_at->format(blog_setting('listtime', 'm-d')) }}</time></li>
@endforeach
</ul>
</li>
+1 -1
View File
@@ -10,7 +10,7 @@
<div class="comment" id="comment-{{ $comment->id }}">
<div class="comment-head">
<strong>{{ $comment->author_name }}</strong>
<span>· 评论于 <a href="{{ route('posts.show', $comment->post->slug ?: $comment->post->id) }}#comment-{{ $comment->id }}">{{ $comment->post->title }}</a></span>
<span>· 评论于 <a href="{{ route('posts.show', $comment->post->id) }}#comment-{{ $comment->id }}">{{ $comment->post->title }}</a></span>
<span class="comment-time">· {{ $comment->created_at->format(blog_setting('comment_timeformat', 'Y-m-d H:i')) }}</span>
</div>
<div class="comment-body">{!! nl2br(e($comment->content)) !!}</div>
+2 -2
View File
@@ -10,8 +10,8 @@
@foreach($posts as $post)
<item>
<title>{{ $post->title }}</title>
<link>{{ route('posts.show', $post->slug ?: $post->id) }}</link>
<guid isPermaLink="true">{{ route('posts.show', $post->slug ?: $post->id) }}</guid>
<link>{{ route('posts.show', $post->id) }}</link>
<guid isPermaLink="true">{{ route('posts.show', $post->id) }}</guid>
<pubDate>{{ $post->published_at->toRssString() }}</pubDate>
<description>{{ Str::limit(strip_tags($post->excerpt_or_fallback), 300) }}</description>
@if($post->category)
+1 -1
View File
@@ -17,7 +17,7 @@
</url>
@foreach($posts as $post)
<url>
<loc>{{ route('posts.show', $post->slug ?: $post->id) }}</loc>
<loc>{{ route('posts.show', $post->id) }}</loc>
<lastmod>{{ $post->updated_at?->toAtomString() }}</lastmod>
<changefreq>monthly</changefreq>
<priority>0.8</priority>
+5 -5
View File
@@ -1,18 +1,18 @@
<article class="post-card {{ $post->is_sticky ? 'sticky' : '' }}">
@if($cover = $post->getFirstMedia('cover'))
<a href="{{ route('posts.show', $post->slug ?: $post->id) }}" class="post-cover">
<a href="{{ route('posts.show', $post->id) }}" class="post-cover">
<img src="{{ $cover->getUrl('card') ?: $cover->getUrl() }}" alt="{{ $post->title }}" loading="lazy">
</a>
@endif
<h2 class="post-title">
@if($post->is_sticky)<span class="badge">置顶</span>@endif
<a href="{{ route('posts.show', $post->slug ?: $post->id) }}">{{ $post->title }}</a>
<a href="{{ route('posts.show', $post->id) }}">{{ $post->title }}</a>
</h2>
<div class="post-meta">
<time datetime="{{ $post->published_at->toIso8601String() }}">{{ $post->published_at->format(blog_setting('normaltime', 'Y-m-d H:i')) }}</time>
@if($post->category)
<span>·</span>
<a href="{{ route('category.show', $post->category->slug ?: $post->category->id) }}">{{ $post->category->name }}</a>
<a href="{{ route('category.show', $post->category->id) }}">{{ $post->category->name }}</a>
@endif
<span>· 阅读 {{ $post->views }}</span>
<span>· 评论 {{ $post->comment_count }}</span>
@@ -21,9 +21,9 @@
{{ Str::limit(strip_tags($post->excerpt_or_fallback), 200) }}
</div>
<div class="post-footer">
<a href="{{ route('posts.show', $post->slug ?: $post->id) }}" class="read-more">阅读全文 &raquo;</a>
<a href="{{ route('posts.show', $post->id) }}" class="read-more">阅读全文 &raquo;</a>
@foreach($post->tags as $tag)
<a href="{{ route('tags.show', $tag->slug ?: $tag->name) }}" class="tag-link">#{{ $tag->name }}</a>
<a href="{{ route('tags.show', $tag->name) }}" class="tag-link">#{{ $tag->name }}</a>
@endforeach
</div>
</article>
+4 -4
View File
@@ -5,7 +5,7 @@
<ul class="widget-list">
@forelse($categories as $category)
<li>
<a href="{{ route('category.show', $category->slug ?: $category->id) }}">{{ $category->name }}</a>
<a href="{{ route('category.show', $category->id) }}">{{ $category->name }}</a>
<span class="count">({{ $category->post_count }})</span>
</li>
@empty
@@ -18,7 +18,7 @@
<h3 class="widget-title">最新文章</h3>
<ul class="widget-list">
@forelse($recentPosts as $post)
<li><a href="{{ route('posts.show', $post->slug ?: $post->id) }}">{{ $post->title }}</a></li>
<li><a href="{{ route('posts.show', $post->id) }}">{{ $post->title }}</a></li>
@empty
<li>暂无文章</li>
@endforelse
@@ -30,7 +30,7 @@
<ul class="widget-list">
@forelse($recentComments as $comment)
<li>
<a href="{{ route('posts.show', $comment->post->slug ?: $comment->post->id) }}#comment-{{ $comment->id }}">
<a href="{{ route('posts.show', $comment->post->id) }}#comment-{{ $comment->id }}">
{{ $comment->author_name }}{{ Str::limit(strip_tags($comment->content), 30) }}
</a>
</li>
@@ -44,7 +44,7 @@
<h3 class="widget-title">标签云</h3>
<div class="tag-cloud">
@forelse($hotTags as $tag)
<a href="{{ route('tags.show', $tag->slug ?: $tag->name) }}" class="tag-link">{{ $tag->name }}</a>
<a href="{{ route('tags.show', $tag->name) }}" class="tag-link">{{ $tag->name }}</a>
@empty
<span>暂无标签</span>
@endforelse
+2 -2
View File
@@ -40,7 +40,7 @@
<time datetime="{{ $post->published_at->toIso8601String() }}">{{ $post->published_at->format(blog_setting('normaltime', 'Y-m-d H:i')) }}</time>
@if($post->author)<span>· {{ $post->author->name }}</span>@endif
@if($post->category)
<span>· <a href="{{ route('category.show', $post->category->slug ?: $post->category->id) }}">{{ $post->category->name }}</a></span>
<span>· <a href="{{ route('category.show', $post->category->id) }}">{{ $post->category->name }}</a></span>
@endif
<span>· 阅读 {{ $post->views }}</span>
</div>
@@ -53,7 +53,7 @@
@if($post->tags->isNotEmpty())
<div class="post-tags">
@foreach($post->tags as $tag)
<a href="{{ route('tags.show', $tag->slug ?: $tag->name) }}" class="tag-link">#{{ $tag->name }}</a>
<a href="{{ route('tags.show', $tag->name) }}" class="tag-link">#{{ $tag->name }}</a>
@endforeach
</div>
@endif
+1 -1
View File
@@ -7,7 +7,7 @@
<h1 class="list-title">全部标签</h1>
<div class="tag-cloud big">
@forelse($tags as $tag)
<a href="{{ route('tags.show', $tag->slug ?: $tag->name) }}" class="tag-link" style="font-size: {{ max(0.9, min(1.8, 0.9 + $tag->posts_count * 0.1)) }}em">
<a href="{{ route('tags.show', $tag->name) }}" class="tag-link" style="font-size: {{ max(0.9, min(1.8, 0.9 + $tag->posts_count * 0.1)) }}em">
{{ $tag->name }} ({{ $tag->posts_count }})
</a>
@empty
+49 -23
View File
@@ -31,38 +31,77 @@ Route::get('/', function () {
return app(HomeController::class)->index();
})->name('home');
Route::get('/posts/{slug}.shtml', [PostController::class, 'show'])->where('slug', '[^/]+')->name('posts.show');
Route::get('/posts/{slug}', fn (string $slug) => redirect()->route('posts.show', $slug, 301))->where('slug', '[^/]+');
// sablog 首页分页格式:/index-{page}.shtml
Route::get('/index-{page}.shtml', function (string $page) {
\Illuminate\Pagination\Paginator::currentPageResolver(fn () => max(1, (int) $page));
return app(HomeController::class)->index();
})->whereNumber('page');
Route::get('/posts/{slug}.shtml', function (string $slug) {
$post = \App\Models\Post::query()->where('slug', $slug)->orWhere('id', (int) $slug)->first();
return $post ? redirect()->route('posts.show', $post->id, 301) : abort(404);
})->where('slug', '[^/]+');
Route::get('/posts/{slug}', function (string $slug) {
$post = \App\Models\Post::query()->where('slug', $slug)->orWhere('id', (int) $slug)->first();
return $post ? redirect()->route('posts.show', $post->id, 301) : abort(404);
})->where('slug', '[^/]+');
// 文章正典:与 sablog 完全一致 /show-{id}.shtml(评论分页 /show-{id}-{page}.shtml
Route::get('/show-{id}.shtml', [PostController::class, 'show'])->whereNumber('id')->name('posts.show');
Route::get('/show-{id}-{page}.shtml', [PostController::class, 'show'])->whereNumber('id')->whereNumber('page');
Route::post('/posts/{post}/comments', [CommentController::class, 'store'])->name('comments.store');
// 浏览量统计(独立端点,避开整页缓存,保证实时)
Route::get('/track-view/{post}', fn (\App\Models\Post $post) => response($post->increment('views') ? '' : '', 204))->name('track-view');
Route::get('/category/{slug}.shtml', [CategoryController::class, 'show'])->where('slug', '[^/]+')->name('category.show');
Route::get('/category/{slug}', fn (string $slug) => redirect()->route('category.show', $slug, 301))->where('slug', '[^/]+');
Route::get('/category/{slug}.shtml', function (string $slug) {
$category = \App\Models\Category::query()->where('slug', $slug)->orWhere('id', (int) $slug)->first();
return $category ? redirect()->route('category.show', $category->id, 301) : abort(404);
})->where('slug', '[^/]+');
Route::get('/category/{slug}', function (string $slug) {
$category = \App\Models\Category::query()->where('slug', $slug)->orWhere('id', (int) $slug)->first();
return $category ? redirect()->route('category.show', $category->id, 301) : abort(404);
})->where('slug', '[^/]+');
// 分类正典:/category-{cid}.shtml(分页 /category-{cid}-{page}.shtml
Route::get('/category-{cid}.shtml', [CategoryController::class, 'show'])->whereNumber('cid')->name('category.show');
Route::get('/category-{cid}-{page}.shtml', [CategoryController::class, 'show'])->whereNumber('cid')->whereNumber('page');
Route::get('/archives.shtml', [ArchiveController::class, 'index'])->name('archives');
Route::get('/archives', fn () => redirect()->route('archives', [], 301));
Route::get('/archives/{year}/{month}.shtml', [ArchiveController::class, 'month'])
->where(['year' => '\d{4}', 'month' => '\d{2}'])
->name('archives.month');
Route::get('/archives/{year}/{month}', fn (string $year, string $month) => redirect()->route('archives.month', [$year, $month], 301))
Route::get('/archives/{year}/{month}.shtml', fn (string $year, string $month) => redirect()->route('archives.month', $year.$month, 301))
->where(['year' => '\d{4}', 'month' => '\d{2}']);
Route::get('/archives/{year}/{month}', fn (string $year, string $month) => redirect()->route('archives.month', $year.$month, 301))
->where(['year' => '\d{4}', 'month' => '\d{2}']);
// 按月归档正典:/archives-{YYYYMM}.shtml(分页 /archives-{YYYYMM}-{page}.shtml
Route::get('/archives-{date}.shtml', [ArchiveController::class, 'month'])->where('date', '\d{6}')->name('archives.month');
Route::get('/archives-{date}-{page}.shtml', [ArchiveController::class, 'month'])->where(['date' => '\d{6}', 'page' => '\d+']);
Route::get('/tags.shtml', [TagController::class, 'index'])->name('tags');
// 标签正典:/tag/{name}sablog 原版);列表 /tagslist.shtml
Route::get('/tagslist.shtml', [TagController::class, 'index'])->name('tags');
Route::get('/tagslist-{page}.shtml', [TagController::class, 'index'])->whereNumber('page');
Route::get('/tag/{name}', [TagController::class, 'show'])->name('tags.show');
Route::get('/tags.shtml', fn () => redirect()->route('tags', [], 301));
Route::get('/tags', fn () => redirect()->route('tags', [], 301));
Route::get('/tags/{slug}.shtml', [TagController::class, 'show'])->where('slug', '[^/]+')->name('tags.show');
Route::get('/tags/{slug}.shtml', fn (string $slug) => redirect()->route('tags.show', $slug, 301))->where('slug', '[^/]+');
Route::get('/tags/{slug}', fn (string $slug) => redirect()->route('tags.show', $slug, 301))->where('slug', '[^/]+');
Route::get('/search.shtml', [SearchController::class, 'index'])->name('search');
Route::get('/search', fn () => redirect()->route('search', [], 301));
Route::get('/search-{page}.shtml', [SearchController::class, 'index'])->whereNumber('page');
Route::get('/links.shtml', [LinkController::class, 'index'])->name('links');
Route::get('/links', fn () => redirect()->route('links', [], 301));
Route::get('/comments.shtml', [CommentController::class, 'index'])->name('comments');
Route::get('/comments', fn () => redirect()->route('comments', [], 301));
Route::get('/comments-{page}.shtml', [CommentController::class, 'index'])->whereNumber('page');
Route::get('/login.shtml', [AuthController::class, 'showLogin'])->name('login');
Route::get('/login', fn () => redirect()->route('login', [], 301));
@@ -109,29 +148,16 @@ Route::get('/themes/{theme}/assets/{path}', [ThemeAssetController::class, 'show'
Route::get('/show-{id}-{page}.html', [LegacyController::class, 'showRewritten'])
->where(['id' => '\d+', 'page' => '\d+']);
Route::get('/show-{id}.html', [LegacyController::class, 'showRewritten'])->where('id', '\d+');
Route::get('/show-{id}-{page}.shtml', [LegacyController::class, 'showRewritten'])
->where(['id' => '\d+', 'page' => '\d+']);
Route::get('/show-{id}.shtml', [LegacyController::class, 'showRewritten'])->where('id', '\d+');
Route::get('/category-{cid}-{page}.html', [LegacyController::class, 'categoryRewritten'])
->where(['cid' => '\d+', 'page' => '\d+']);
Route::get('/category-{cid}.html', [LegacyController::class, 'categoryRewritten'])->where('cid', '\d+');
Route::get('/category-{cid}-{page}.shtml', [LegacyController::class, 'categoryRewritten'])
->where(['cid' => '\d+', 'page' => '\d+']);
Route::get('/category-{cid}.shtml', [LegacyController::class, 'categoryRewritten'])->where('cid', '\d+');
Route::get('/archives-{date}-{page}.html', [LegacyController::class, 'archivesRewritten'])
->where(['date' => '\d+', 'page' => '\d+']);
Route::get('/archives-{date}.html', [LegacyController::class, 'archivesRewritten'])->where('date', '\d+');
Route::get('/archives-{date}-{page}.shtml', [LegacyController::class, 'archivesRewritten'])
->where(['date' => '\d+', 'page' => '\d+']);
Route::get('/archives-{date}.shtml', [LegacyController::class, 'archivesRewritten'])->where('date', '\d+');
Route::get('/tagslist-{page}.html', fn () => redirect()->route('tags', [], 301))->where('page', '\d+');
Route::get('/tagslist.html', fn () => redirect()->route('tags', [], 301));
Route::get('/tagslist-{page}.shtml', fn () => redirect()->route('tags', [], 301))->where('page', '\d+');
Route::get('/tagslist.shtml', fn () => redirect()->route('tags', [], 301));
Route::get('/comments-{page}.html', fn () => redirect()->route('comments', [], 301))->where('page', '\d+');
Route::get('/comments-{page}.shtml', fn () => redirect()->route('comments', [], 301))->where('page', '\d+');
Route::get('/search-{page}.html', fn () => redirect()->route('search', [], 301))->where('page', '\d+');
Route::get('/search-{page}.shtml', fn () => redirect()->route('search', [], 301))->where('page', '\d+');
Route::get('/reg.shtml', fn () => redirect()->route('register', [], 301));
Route::get('/tag/{name}', [LegacyController::class, 'tagByName']);
@@ -11,7 +11,7 @@
<h3>分类</h3>
<ul>
@forelse($categories as $category)
<li><a href="{{ route('category.show', $category->slug ?: $category->id) }}">{{ $category->name }}</a> ({{ $category->post_count }})</li>
<li><a href="{{ route('category.show', $category->id) }}">{{ $category->name }}</a> ({{ $category->post_count }})</li>
@empty
<li>暂无分类</li>
@endforelse
@@ -22,7 +22,7 @@
<h3>最新文章</h3>
<ul>
@forelse($recentPosts as $post)
<li><a href="{{ route('posts.show', $post->slug ?: $post->id) }}">{{ $post->title }}</a></li>
<li><a href="{{ route('posts.show', $post->id) }}">{{ $post->title }}</a></li>
@empty
<li>暂无文章</li>
@endforelse
@@ -33,7 +33,7 @@
<h3>最新评论</h3>
<ul>
@forelse($recentComments as $comment)
<li><a href="{{ route('posts.show', $comment->post->slug ?: $comment->post->id) }}#comment-{{ $comment->id }}">{{ $comment->author_name }}{{ Str::limit(strip_tags($comment->content), 20) }}</a></li>
<li><a href="{{ route('posts.show', $comment->post->id) }}#comment-{{ $comment->id }}">{{ $comment->author_name }}{{ Str::limit(strip_tags($comment->content), 20) }}</a></li>
@empty
<li>暂无评论</li>
@endforelse
@@ -44,7 +44,7 @@
<h3>标签</h3>
<p class="tagcloud">
@forelse($hotTags as $tag)
<a href="{{ route('tags.show', $tag->slug ?: $tag->name) }}">{{ $tag->name }}</a>
<a href="{{ route('tags.show', $tag->name) }}">{{ $tag->name }}</a>
@empty
暂无标签
@endforelse
+2 -2
View File
@@ -38,7 +38,7 @@
<time datetime="{{ $post->published_at->toIso8601String() }}">{{ $post->published_at->format(blog_setting('normaltime', 'Y-m-d H:i')) }}</time>
@if($post->author)<span>· {{ $post->author->name }}</span>@endif
@if($post->category)
<span>· <a href="{{ route('category.show', $post->category->slug ?: $post->category->id) }}">{{ $post->category->name }}</a></span>
<span>· <a href="{{ route('category.show', $post->category->id) }}">{{ $post->category->name }}</a></span>
@endif
<span>· 阅读 {{ $post->views }}</span>
</div>
@@ -52,7 +52,7 @@
@if($post->tags->isNotEmpty())
<div class="post-tags">
@foreach($post->tags as $tag)
<a href="{{ route('tags.show', $tag->slug ?: $tag->name) }}" class="tag-link">#{{ $tag->name }}</a>
<a href="{{ route('tags.show', $tag->name) }}" class="tag-link">#{{ $tag->name }}</a>
@endforeach
</div>
@endif