Merge branch 'main' of gitea.neatcn.com:gouki/laralog
Build and Deploy / verify (push) Successful in 34s
Build and Deploy / deploy (push) Successful in 40s

Keep media-library covers while adopting sablog /show-{id}.shtml canonical URLs.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
gouki
2026-09-16 19:06:42 +00:00
co-authored by Cursor
23 changed files with 116 additions and 73 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
@@ -48,7 +48,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
@@ -126,7 +126,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);
}
/**