Add visual CMS, media library and product directory

This commit is contained in:
2026-11-21 19:27:46 +08:00
parent 188a63fb2f
commit 474008b06e
42 changed files with 1710 additions and 134 deletions
+24 -3
View File
@@ -6,6 +6,7 @@ namespace App\Controller;
use App\Content\Html;
use App\Content\Repository;
use App\Content\SiteDesign;
use App\Content\View;
use support\Request;
use support\Response;
@@ -21,9 +22,15 @@ final class SiteController
{
$repo = new Repository();
$page = $repo->page($slug);
if (!$page) {
if (!$page || $page['status'] !== 'published' || $slug === 'home' && $request->path() !== '/') {
return $this->missing($request);
}
return $this->renderPage($repo, $page);
}
public function renderPage(Repository $repo, array $page, bool $preview = false): Response
{
$slug = $page['slug'];
$isHome = $slug === 'home';
return View::render('page', [
@@ -35,6 +42,17 @@ final class SiteController
'socialImage' => $page['image'],
'socialAlt' => $page['alt'],
'articles' => $isHome ? $repo->articles(limit: 3) : [],
'previewMode' => $preview, 'noindex' => $preview,
]);
}
public function services(Request $request): Response
{
return View::render('services', [
'site' => (new Repository())->site(), 'path' => '/services',
'title' => '产品与服务 · 来笙 Laysense',
'description' => '浏览来笙的建站工具、智能 DNS 和软件著作权服务。',
'products' => SiteDesign::catalog(),
]);
}
@@ -118,7 +136,8 @@ final class SiteController
{
$repo = new Repository();
$xml = ['<?xml version="1.0" encoding="UTF-8"?>', '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'];
$pages = $repo->pages();
$pages = $repo->pages(publishedOnly: true);
$pages[] = ['slug' => 'services', 'updated_at' => null];
if ($repo->articles(limit: 1)) {
$pages[] = ['slug' => 'articles', 'updated_at' => null];
}
@@ -144,7 +163,9 @@ final class SiteController
$path = $request->path();
if ($request->method() === 'GET' && strlen($path) > 1 && str_ends_with($path, '/')) {
$normal = rtrim($path, '/');
if (preg_match('~^/(?:pagepan|highspeaker|sc|shnu-sc|articles(?:/[a-z0-9-]+){0,2})$~D', $normal)) {
$single = preg_match('~^/[a-z0-9-]+$~D', $normal);
$known = $single && ((new Repository())->page(substr($normal, 1))['status'] ?? null) === 'published' && $normal !== '/home';
if ($known || $normal === '/services' || preg_match('~^/articles(?:/[a-z0-9-]+){0,2}$~D', $normal)) {
$query = $request->queryString();
return View::redirect($normal . ($query !== '' ? '?' . $query : ''), 301);