M2: 主题系统(sablog经典+modern简约)+ 前台全部页面 + 老 URL 301 兼容 + markdown 双份导入
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Blog\Controllers;
|
||||
|
||||
use App\Blog\Support\ThemeManager;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\File;
|
||||
|
||||
class ThemeAssetController extends Controller
|
||||
{
|
||||
public function show(ThemeManager $themes, string $theme, string $path)
|
||||
{
|
||||
if (! $themes->exists($theme)) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$fullPath = $themes->path($theme).'/assets/'.$path;
|
||||
if (! File::isFile($fullPath)) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
return response(File::get($fullPath), 200, [
|
||||
'Content-Type' => $this->mimeType($fullPath),
|
||||
'Cache-Control' => 'public, max-age=86400',
|
||||
]);
|
||||
}
|
||||
|
||||
private function mimeType(string $path): string
|
||||
{
|
||||
$ext = strtolower(pathinfo($path, PATHINFO_EXTENSION));
|
||||
|
||||
return match ($ext) {
|
||||
'css' => 'text/css',
|
||||
'js' => 'application/javascript',
|
||||
'png' => 'image/png',
|
||||
'jpg', 'jpeg' => 'image/jpeg',
|
||||
'gif' => 'image/gif',
|
||||
'svg' => 'image/svg+xml',
|
||||
'woff' => 'font/woff',
|
||||
'woff2' => 'font/woff2',
|
||||
'ico' => 'image/x-icon',
|
||||
default => 'application/octet-stream',
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user