M2: 主题系统(sablog经典+modern简约)+ 前台全部页面 + 老 URL 301 兼容 + markdown 双份导入
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Blog\Controllers;
|
||||
|
||||
use App\Models\Post;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class ArchiveController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$posts = Post::published()->orderByDesc('published_at')->get(['id', 'title', 'slug', 'published_at']);
|
||||
|
||||
$archives = $posts->groupBy(fn (Post $post) => $post->published_at->format('Y'))
|
||||
->map(fn ($yearPosts) => $yearPosts->groupBy(fn (Post $post) => $post->published_at->format('m')));
|
||||
|
||||
return theme_view('archives', compact('archives'));
|
||||
}
|
||||
|
||||
public function month(string $year, string $month)
|
||||
{
|
||||
$start = Carbon::create((int) $year, (int) $month, 1)->startOfMonth();
|
||||
$end = (clone $start)->endOfMonth();
|
||||
|
||||
$posts = Post::query()
|
||||
->whereBetween('published_at', [$start, $end])
|
||||
->published()
|
||||
->orderByDesc('published_at')
|
||||
->paginate((int) blog_setting('per_page', config('blog.per_page')));
|
||||
|
||||
return theme_view('list', compact('posts'))
|
||||
->with('archiveTitle', "{$year} 年 {$month} 月");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user