M2: 主题系统(sablog经典+modern简约)+ 前台全部页面 + 老 URL 301 兼容 + markdown 双份导入

This commit is contained in:
ak
2026-08-11 17:58:29 +08:00
parent f16bb75538
commit 6214976a88
66 changed files with 2763 additions and 10 deletions
@@ -0,0 +1,44 @@
<?php
namespace App\Blog\Providers;
use App\Blog\Support\ThemeManager;
use App\Blog\View\Composers\SidebarComposer;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
class ThemeServiceProvider extends ServiceProvider
{
public function register(): void
{
$this->app->singleton(ThemeManager::class);
}
public function boot(): void
{
// 激活主题的 views 目录前置到全局视图路径,实现主题覆盖 + 默认兜底
$this->prependActiveThemeViews();
// 侧边栏数据共享:所有前台视图自动获得 $categories/$recentPosts/$hotTags/$links 等
View::composer(
['index', 'show', 'list', 'archives', 'tags', 'tag', 'search', 'links', 'comments', 'login', 'register', 'profile'],
SidebarComposer::class
);
}
private function prependActiveThemeViews(): void
{
$manager = app(ThemeManager::class);
$views = $manager->path($manager->active()).'/views';
if (! is_dir($views)) {
return;
}
$paths = config('view.paths');
array_unshift($paths, $views);
config(['view.paths' => $paths]);
app('view')->getFinder()->setPaths($paths);
}
}