Merge pull request '新增整页模板抽屉和 Caddy 部署示例' (#13) from ChatGPT/laysense.cn:page-template-drawer into main

Reviewed-on: #13
This commit was merged in pull request #13.
This commit is contained in:
2026-11-22 12:41:29 +08:00
31 changed files with 661 additions and 14 deletions
+51 -1
View File
@@ -28,6 +28,7 @@ php bin/admin.php reset admin@example.com
## 后台编辑
- **网站后台**可按名称、地址或发布状态查找页面,从列表打开画布、公开页或草稿预览。
- **整页模板**可以从后台首页、新建页面或画布打开独立抽屉。先选套系,再选页面,查看缩略图或完整预览后创建草稿。首屏和各个区块可继续使用现有编辑器修改。主题样式只由使用模板的公开页及预览加载,抽屉样式和交互只由有入口的后台页面加载。首批三个套系参考 [Hallmark](https://github.com/nutlope/hallmark) 的 Cobalt、Studio 和 Dusk。
- **页面设计**支持新建草稿、发布和撤回。首屏标题与简介可在桌面或手机画布中直接编辑。区块支持新增、排序、删除、可视化编辑、媒体插入和 HTML 源码。单击画布元素可用浮动工具条复制或删除。选中媒体后,可拖动边缘手柄调整宽度。浮动工具条可将正文元素、区块标题和首屏元素对齐到左侧、中央或右侧。编辑器左侧分为「组件」「元素」「图层」。先进入分类,再查找并插入模板或基础元素。可在功能分类中复用产品图文、特性组、服务报价等内置模板,徽标、按钮组、面包屑、进度、通知和折叠等元素参考 [Preline UI 免费组件文档](https://preline.co/docs/index.html),用本站样式实现。悬停或键盘聚焦缩略图可放大,点击可打开预览。
- **媒体库**集中列出项目静态文件及上传文件,支持查找、选取、复制路径、改名和归档。归档资源的已有 URL 保持可访问。上传文件放在 `LAYSENSE_MEDIA_DIR`,由 `/assets/uploads/` 提供。
- **文章**使用自托管的 TOAST UI Editor 3.2.2(MIT)。Markdown 左侧源码、右侧实时预览,富文本使用所见即所得模式。文章可以加入多个分类,可在「管理分类」创建新分类。
@@ -42,7 +43,9 @@ php bin/admin.php reset admin@example.com
1. 以运行服务的用户执行 `composer install --no-dev --optimize-autoloader`、`php bin/install.php` 和管理员创建命令。
2. 通过 systemd 或其他进程管理器以前台命令 `php start.php start` 运行。为生产服务设置 `LAYSENSE_SECURE_COOKIES=1`,使 Webman 签发 Secure 会话 Cookie。默认监听 `127.0.0.1:8787`。
3. 由 Nginx 等反向代理处理 `laysense.cn` 的 HTTPS,并将请求转发给 Webman。项目根目录保持在公共站点根目录之外。
3. 由 Nginx 或 Caddy 处理 `laysense.cn` 的 HTTPS,并将请求转发给 Webman。项目根目录保持在公共站点根目录之外。
### Nginx
下面的 Nginx 片段可放入现有 HTTPS 虚拟主机。Nginx 会覆盖请求携带的 `X-Real-IP`,应用默认信任本机回环地址传来的该请求头。密码验证失败的请求按来源计数,超过阈值后返回 429。正确密码仍可登录。
@@ -62,6 +65,48 @@ location = /admin/media {
}
```
### Caddy v2
下面的 Caddyfile 适用于 Caddy v2.10.0 及以上版本,假定 Caddy 直接面对访客,与 Webman 运行在同一台机器上。把域名解析到 Caddy,并开放 80 和 443 端口,Caddy 会自动申请证书。`header_up` 用连接对端的 IP 覆盖 `X-Real-IP`,供 Webman 按访客来源计数。
```caddyfile
laysense.cn {
@media path /admin/media
@pages not path /admin/media
request_body @media {
max_size 66MiB
}
request_body @pages {
max_size 2MiB
}
reverse_proxy 127.0.0.1:8787 {
header_up X-Real-IP {remote_host}
}
}
```
用 `caddy validate --config /etc/caddy/Caddyfile --adapter caddyfile` 验证,再用 `caddy reload --config /etc/caddy/Caddyfile --adapter caddyfile` 重载。较早的 Caddy v2 可以省略两个匹配器及 `request_body` 块,保留反代。Webman 仍限制请求包大小,并将单个媒体文件限制在 64 MiB。
### Caddy v1
下例适用于仍在运行的 Caddy 1.x。`transparent` 保留请求的 Host,并用连接对端的 IP 设置 `X-Real-IP`。Caddy v1 的 `limits` 按路径前缀匹配,`MB` 以 1024 为进制。
```caddyfile
laysense.cn {
limits {
body /admin/media 66MB
body / 2MB
}
proxy / 127.0.0.1:8787 {
transparent
}
}
```
用 `caddy -validate -conf /etc/caddy/Caddyfile` 验证,再通过进程管理器重载。Caddy v1 已停止维护,新的部署使用 v2。
两个示例都把 HTTPS 终止在 Caddy,生产环境的 Webman 继续使用 `LAYSENSE_SECURE_COOKIES=1`。如果 Caddy 与 Webman 分开运行,将 `LAYSENSE_TRUSTED_PROXIES` 设为 Webman 实际看到的 Caddy 来源 IP,并把 Webman 的监听地址限制在只有 Caddy 能访问的网络。
| 环境变量 | 默认值与用途 |
| --- | --- |
| `LAYSENSE_SITE_URL` | `https://laysense.cn` · canonical、分享链接和站点地图的正式站点地址 |
@@ -86,6 +131,11 @@ SQLite 已启用 WAL。使用上一版多分类文章结构的站点,可用当
- SHNU 旧页首屏写 ¥69,详细报价表与正文写 ¥66。新版保留报价表中的 ¥66,并保留旧页学生资格及学分说明。两处普通软著页面的咨询按钮现在直达该页既有的企业微信入口。
- 中文公开页复用页头、页尾、首屏、内容区块、动态列表及同一套 CSS。历史迁移内容见 `resources/seed.json`,结构见 `resources/schema.sql`。
## 整页模板素材
- 工作室照片是 Adam Lusch 的《Wood Type close-up》,按 CC BY-SA 2.0 许可提供,已缩放并转为 WebP。 [照片](https://commons.wikimedia.org/wiki/File:Wood_Type_close-up.jpg) · [许可证](https://creativecommons.org/licenses/by-sa/2.0/)
- 暮色照片是 Bob Wick / BLM Utah 的《Utah Dunes Landscape》,公有领域,已缩放并转为 WebP。 [照片](https://commons.wikimedia.org/wiki/File:Utah_Dunes_Landscape_-_West_Desert_District.jpg)
## 画布浏览器回归
`tests/studio-browser.cjs` 用 Playwright 在真实 Chromium 内检查媒体拖拽、链接、模板预览、编辑器、文章分类和公开页面。使用已启动的测试实例、独立的 SQLite 数据库和管理员账户。测试会在该库创建页面、分类和测试文章。
+4
View File
@@ -54,6 +54,10 @@ final class Database
$pdo->exec("ALTER TABLE $table ADD COLUMN alignments TEXT NOT NULL DEFAULT '{}'");
}
}
$pageColumns = array_column($pdo->query('PRAGMA table_info(pages)')->fetchAll(), 'name');
if (!in_array('theme', $pageColumns, true)) {
$pdo->exec("ALTER TABLE pages ADD COLUMN theme TEXT NOT NULL DEFAULT ''");
}
$site = $pdo->prepare('INSERT OR IGNORE INTO site_settings (id, payload) VALUES (1, ?)');
$site->execute([self::json($seed['site'])]);
+49
View File
@@ -0,0 +1,49 @@
<?php
declare(strict_types=1);
namespace App\Content;
final class PageTemplates
{
public static function groups(): array
{
static $groups;
return $groups ??= require dirname(__DIR__, 2) . '/resources/page-templates.php';
}
public static function find(string $key): ?array
{
foreach (self::groups() as $theme => $group) {
if (!isset($group['pages'][$key])) {
continue;
}
$template = $group['pages'][$key];
$sections = [];
$quicklinks = [];
foreach ($template['sections'] as [$anchor, $title, $style, $body, $feed]) {
$sections[] = ['key' => $anchor, 'title' => $title, 'style' => $style, 'body' => Html::sanitize($body, $anchor),
'lead' => '', 'feed' => $feed, 'alignments' => '{}', 'version' => 0];
$quicklinks[] = ['#' . $anchor, $title];
}
return array_replace($template, [
'slug' => $key, 'theme' => $theme, 'title' => $template['name'] . ' · 来笙', 'accent' => '',
'lead' => $template['description'], 'quicklinks' => $quicklinks, 'status' => 'draft',
'alignments' => [], 'image_scale' => 0, 'sections' => $sections,
]);
}
return null;
}
public static function photoCredit(string $image): ?array
{
return match ($image) {
'/assets/page-templates/studio-letterpress.webp' => ['Adam Lusch', 'CC BY-SA 2.0', 'https://commons.wikimedia.org/wiki/File:Wood_Type_close-up.jpg', 'https://creativecommons.org/licenses/by-sa/2.0/'],
'/assets/page-templates/dusk-dunes.webp' => ['Bob Wick / BLM Utah', '公有领域', 'https://commons.wikimedia.org/wiki/File:Utah_Dunes_Landscape_-_West_Desert_District.jpg', null],
default => null,
};
}
}
+18 -8
View File
@@ -35,15 +35,25 @@ final class Repository
return $this->pdo->query('SELECT slug, name, title, updated_at, status FROM pages' . $where . ' ORDER BY rowid')->fetchAll();
}
public function createPage(string $slug, string $name): void
public function createPage(string $slug, string $name, array $template = []): void
{
$query = $this->pdo->prepare("INSERT OR IGNORE INTO pages (slug, name, title, description, heading, accent,
lead, image, alt, actions, quicklinks, status, updated_at)
VALUES (?, ?, ?, '', ?, '', '', '', '', '[]', '[]', 'draft', ?)");
$query->execute([$slug, $name, $name . ' · 来笙', $name, self::now()]);
if ($query->rowCount() !== 1) {
throw new RuntimeException('此页面地址已存在。');
}
Database::write(function (PDO $pdo) use ($slug, $name, $template): void {
$query = $pdo->prepare("INSERT OR IGNORE INTO pages (slug, name, title, description, heading, accent,
lead, image, alt, actions, quicklinks, theme, status, updated_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'draft', ?)");
$query->execute([
$slug, $name, $name . ' · 来笙', $template['description'] ?? '', $template['heading'] ?? $name,
$template['accent'] ?? '', $template['lead'] ?? '', $template['image'] ?? '', $template['alt'] ?? '',
Database::json($template['actions'] ?? []), Database::json($template['quicklinks'] ?? []),
$template['theme'] ?? '', self::now(),
]);
if ($query->rowCount() !== 1) {
throw new RuntimeException('此页面地址已存在。');
}
foreach ($template['sections'] ?? [] as $section) {
self::insertSection($pdo, $slug, $section['key'], $section);
}
});
}
public function page(string $slug): ?array
+2
View File
@@ -117,6 +117,7 @@ class AdminController
return $this->render($request, 'admin-dashboard', [
'title' => '内容管理', 'pages' => $repo->pages(), 'articles' => $repo->articles(public: false, limit: 5),
'pageTemplateDrawer' => true,
]);
}
@@ -295,6 +296,7 @@ class AdminController
return $this->render($request, 'admin-page', [
'title' => '编辑 ' . $page['name'], 'page' => $page, 'categories' => $repo->categories(), 'wideAdmin' => true, 'error' => $error, 'saved' => $request->get('saved') === '1',
'pageTemplateDrawer' => true,
], $error !== '' ? 422 : 200);
}
+22 -2
View File
@@ -8,6 +8,7 @@ use App\Content\Assets;
use App\Content\BlockTemplates;
use App\Content\Html;
use App\Content\Media;
use App\Content\PageTemplates;
use App\Content\Repository;
use App\Content\SiteDesign;
use App\Http\Request;
@@ -22,7 +23,10 @@ final class StudioController extends AdminController
if ($failure = $this->guard($request)) {
return $failure;
}
$data = ['title' => '新建页面', 'name' => '', 'slug' => '', 'error' => ''];
$data = [
'title' => '新建页面', 'name' => '', 'slug' => '', 'error' => '', 'pageTemplateDrawer' => true,
'openTemplates' => $request->get('templates') === '1',
];
if ($request->method() === 'POST') {
$data['name'] = $this->input($request, 'name');
$data['slug'] = $this->input($request, 'slug');
@@ -31,7 +35,12 @@ final class StudioController extends AdminController
|| $data['name'] === '' || mb_strlen($data['name']) > 100) {
throw new RuntimeException('请填写页面名称及可用的网址标识。');
}
(new Repository())->createPage($data['slug'], $data['name']);
$key = $this->input($request, 'template');
$template = $key === '' ? [] : PageTemplates::find($key);
if ($template === null) {
throw new RuntimeException('找不到所选整页模板。');
}
(new Repository())->createPage($data['slug'], $data['name'], $template);
return $this->success($request, '/admin/pages/' . $data['slug']);
} catch (RuntimeException $error) {
@@ -42,6 +51,17 @@ final class StudioController extends AdminController
return $this->render($request, 'studio-new-page', $data, $data['error'] === '' ? 200 : 422);
}
public function previewTemplate(Request $request, string $key): Response
{
if ($failure = $this->guard($request)) {
return $failure;
}
$template = PageTemplates::find($key);
return $template ? (new SiteController())->renderPage(new Repository(), $template, true)
: $this->error($request, '找不到所选整页模板。', 404);
}
public function previewPage(Request $request, string $slug): Response
{
if ($failure = $this->guard($request)) {
+2
View File
@@ -8,6 +8,7 @@ $live = count(array_filter($pages, static fn (array $page): bool => $page['statu
<h1>网站后台</h1>
<div class="actions">
<a class="button button-primary" href="/admin/new-page">新建页面</a>
<button type="button" class="button button-outline" data-open-page-templates hidden>整页模板</button>
<a class="button button-outline" href="/admin/articles/new">写文章</a>
</div>
</header>
@@ -57,3 +58,4 @@ $live = count(array_filter($pages, static fn (array $page): bool => $page['statu
</section>
</div>
</div>
<?= View::fragment('studio-page-templates', compact('token')) ?>
+4
View File
@@ -23,6 +23,10 @@ $active = match (true) {
<script src="/assets/jquery-4.0.0.min.js" defer></script>
<script src="/assets/admin.js" defer></script>
<script src="/assets/studio.js" defer></script>
<?php if (!empty($pageTemplateDrawer)): ?>
<link rel="stylesheet" href="/assets/page-template-drawer.css">
<script src="/assets/page-template-drawer.js" defer></script>
<?php endif ?>
<?php if (!empty($articleEditor)): ?>
<link rel="stylesheet" href="/assets/vendor/toastui/toastui-editor.min.css">
<script src="/assets/vendor/toastui/toastui-editor.min.js" defer></script>
+2
View File
@@ -14,6 +14,7 @@ $previewUrl = '/admin/pages/' . $slug . '/preview';
<span class="dashboard-page-state" data-published="<?= $page['status'] === 'published' ? 'true' : 'false' ?>"><?= $page['status'] === 'draft' ? '草稿' : '已发布' ?></span></p></div>
<div class="actions">
<a class="button button-outline" href="#studio-page-settings">页面设置</a>
<button type="button" class="button button-outline" data-open-page-templates hidden>整页模板</button>
<?php if ($page['status'] === 'published'): ?><a class="button button-outline" href="<?= $e($path) ?>">公开页面</a><?php endif ?>
<a class="button button-outline" href="<?= $e($previewUrl) ?>" target="_blank" rel="noopener">打开预览</a>
</div>
@@ -146,3 +147,4 @@ $previewUrl = '/admin/pages/' . $slug . '/preview';
<div class="form-submit"><button class="button button-primary" type="submit">保存页面</button></div>
</form>
</div>
<?= View::fragment('studio-page-templates', compact('token')) ?>
+3 -1
View File
@@ -16,6 +16,7 @@ $header = ($site['header'] ?? []) + SiteDesign::DEFAULT_HEADER;
$footer = SiteDesign::footer($site);
$nav = $header['links'];
$contact = $header['button'];
$theme = $page['theme'] ?? '';
?>
<!doctype html>
<html lang="zh-CN" data-type="<?= $e($kind) ?>" data-buttons="solid" data-motion="on">
@@ -46,6 +47,7 @@ $contact = $header['button'];
<meta name="twitter:card" content="summary_large_image">
<link rel="icon" href="/assets/favicon.png" type="image/png">
<link rel="stylesheet" href="/assets/site.css">
<?php if ($theme !== ''): ?><link rel="stylesheet" href="/assets/page-themes.css"><?php endif ?>
<script src="/assets/jquery-4.0.0.min.js" defer></script>
<script src="/assets/site.js" defer></script>
</head>
@@ -75,7 +77,7 @@ $contact = $header['button'];
<?php endif ?>
</div>
</header>
<main id="main-content" tabindex="-1"><?= $content ?></main>
<main id="main-content"<?= $theme !== '' ? ' class="page-theme theme-' . $e($theme) . '"' : '' ?> tabindex="-1"><?= $content ?></main>
<?= View::fragment('footer', ['footer' => $footer]) ?>
</body>
</html>
+6
View File
@@ -1,5 +1,6 @@
<?php
use App\Content\PageTemplates;
use App\Content\View;
$e = View::escape(...);
@@ -75,6 +76,11 @@ $field = static fn (string $name): string => $canvas ? ' data-studio-field="' .
<?= View::fragment('section', ['section' => $section, 'moment' => $home && $section['key'] === 'about', 'canvas' => $canvas, 'pageSlug' => $page['slug']]) ?>
<?php endif ?>
<?php endforeach ?>
<?php if ($credit = PageTemplates::photoCredit($page['image'])): ?>
<p class="wrap page-photo-credit">摄影 <a href="<?= $e($credit[2]) ?>"><?= $e($credit[0]) ?></a> ·
<?php if ($credit[3]): ?><a href="<?= $e($credit[3]) ?>"><?= $e($credit[1]) ?></a><?php else: ?><?= $e($credit[1]) ?><?php endif ?>
</p>
<?php endif ?>
<?php if ($canvas): ?>
<template data-studio-section-end><?= View::fragment('section', [
'section' => ['style' => 'plain', 'key' => 'new', 'version' => null, 'title' => '', 'lead' => '', 'body' => ''],
+5 -1
View File
@@ -4,7 +4,10 @@ use App\Content\View;
$e = View::escape(...);
?>
<a class="back-link" href="/admin">返回页面</a>
<header class="admin-heading"><h1>新建页面</h1></header>
<header class="admin-heading">
<h1>新建页面</h1>
<button type="button" class="button button-outline" data-open-page-templates hidden>整页模板</button>
</header>
<?= View::fragment('admin-feedback', ['error' => $error, 'saved' => false]) ?>
<form class="admin-form admin-panel" method="post" action="/admin/new-page">
<input type="hidden" name="csrf" value="<?= $e($token) ?>">
@@ -14,3 +17,4 @@ $e = View::escape(...);
</label>
<div class="form-submit"><button type="submit" class="button button-primary">创建草稿</button></div>
</form>
<?= View::fragment('studio-page-templates', compact('token', 'openTemplates')) ?>
+56
View File
@@ -0,0 +1,56 @@
<?php
use App\Content\PageTemplates;
use App\Content\View;
$e = View::escape(...);
$groups = PageTemplates::groups();
$previewRoot = '/assets/page-templates/';
?>
<dialog class="page-template-drawer" data-page-template-drawer<?= !empty($openTemplates) ? ' data-open-on-load' : '' ?> aria-labelledby="page-template-title">
<header class="page-template-header">
<h2 id="page-template-title">整页模板</h2>
<button type="button" class="button button-outline" data-close-page-templates>关闭</button>
</header>
<div class="page-template-content">
<section data-template-panel="groups" aria-labelledby="page-template-groups">
<h3 id="page-template-groups" tabindex="-1">选择套系</h3>
<div class="page-template-groups">
<?php foreach ($groups as $key => $group): ?>
<button type="button" class="page-template-card" data-template-group="<?= $e($key) ?>">
<span class="page-template-image"><img src="<?= $e($previewRoot . $key . '.webp') ?>" width="768" height="480" alt="" loading="lazy"></span>
<span class="page-template-card-copy"><strong><?= $e($group['name']) ?></strong><small><?= $e($group['description']) ?></small></span>
</button>
<?php endforeach ?>
</div>
</section>
<?php foreach ($groups as $key => $group): ?>
<section data-template-panel="<?= $e($key) ?>" aria-labelledby="page-template-<?= $e($key) ?>" hidden>
<button type="button" class="button button-outline page-template-back" data-template-back="groups">返回套系</button>
<h3 id="page-template-<?= $e($key) ?>" tabindex="-1"><?= $e($group['name']) ?></h3>
<div class="page-template-pages">
<?php foreach ($group['pages'] as $pageKey => $pageTemplate): ?>
<button type="button" class="page-template-card" data-page-template="<?= $e($pageKey) ?>">
<span class="page-template-image"><img src="<?= $e($previewRoot . $pageKey . '.webp') ?>" width="768" height="480" alt="" loading="lazy"></span>
<span class="page-template-card-copy"><strong><?= $e($pageTemplate['name']) ?></strong></span>
</button>
<?php endforeach ?>
</div>
</section>
<?php endforeach ?>
<section data-template-panel="detail" aria-labelledby="page-template-detail-heading" hidden>
<button type="button" class="button button-outline page-template-back" data-template-back="pages">返回套内页面</button>
<h3 id="page-template-detail-heading" data-template-name tabindex="-1"></h3>
<div class="page-template-image"><img data-template-preview width="768" height="480" alt=""></div>
<a class="button button-outline page-template-preview-link" data-template-live target="_blank" rel="noopener">打开完整页面预览</a>
<form class="admin-form" method="post" action="/admin/new-page">
<input type="hidden" name="csrf" value="<?= $e($token) ?>">
<input type="hidden" name="template">
<div class="form-grid">
<label>页面名称<input name="name" maxlength="100" required></label>
<label>网址标识<input name="slug" maxlength="70" pattern="[a-z0-9]+(-[a-z0-9]+)*" required></label>
</div>
<div class="form-submit"><button type="submit" class="button button-primary">用此模板创建草稿</button></div>
</form>
</section>
</div>
</dialog>
+1
View File
@@ -33,6 +33,7 @@ Route::add(['GET', 'POST'], '/admin/articles/new', [AdminController::class, 'art
Route::add(['GET', 'POST'], '/admin/articles/{id:[0-9]+}', [AdminController::class, 'article']);
Route::post('/admin/articles/{id:[0-9]+}/delete', [AdminController::class, 'deleteArticle']);
Route::add(['GET', 'POST'], '/admin/new-page', [StudioController::class, 'newPage']);
Route::get('/admin/page-templates/{key:[a-z0-9-]+}/preview', [StudioController::class, 'previewTemplate']);
Route::get('/admin/pages/{slug:[a-z0-9-]+}/preview', [StudioController::class, 'previewPage']);
Route::post('/admin/page-blocks/{slug:[a-z0-9-]+}', [StudioController::class, 'blocks']);
Route::add(['GET', 'POST'], '/admin/settings/{part:header|footer|cdn}', [StudioController::class, 'settings']);
+60
View File
@@ -0,0 +1,60 @@
.page-template-drawer {
position: fixed;
inset: 0 0 0 auto;
margin: 0;
width: min(100%, 39rem);
max-width: none;
height: 100dvh;
max-height: none;
overflow: auto;
overscroll-behavior: contain;
border: 0;
padding: 0;
background: var(--white);
color: var(--ink);
box-shadow: -16px 0 48px #111a2e29;
}
.page-template-drawer::backdrop { background: #111a2e60; }
.page-template-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 1rem;
position: sticky;
top: 0;
z-index: 1;
padding: .9rem clamp(1rem, 4vw, 1.6rem);
background: var(--white);
border-bottom: 1px solid var(--line);
}
.page-template-header h2 { margin: 0; }
.page-template-content { padding: 1.3rem clamp(1rem, 4vw, 1.6rem) 2rem; }
.page-template-content h3 { margin-bottom: 1rem; }
.page-template-content h3:focus { outline: none; }
.page-template-back { margin-bottom: 1.15rem; }
.page-template-groups, .page-template-pages { display: grid; gap: .75rem; }
.page-template-pages { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.page-template-card {
display: grid;
grid-template-columns: 1fr;
width: 100%;
padding: 0;
overflow: hidden;
color: var(--ink);
background: var(--white);
border: 1px solid var(--line);
border-radius: .7rem;
text-align: start;
}
.page-template-groups .page-template-card { grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); align-items: stretch; }
.page-template-card:hover, .page-template-card:focus-visible { border-color: var(--accent); }
.page-template-card-copy { display: grid; align-content: center; gap: .24rem; padding: clamp(.65rem, 2vw, 1rem); }
.page-template-card-copy small { line-height: 1.5; color: var(--muted); }
.page-template-image { display: block; overflow: hidden; background: var(--paper); }
.page-template-image img { width: 100%; height: auto; transition: transform 180ms ease; }
.page-template-card:hover img, .page-template-card:focus-visible img { transform: scale(1.035); }
.page-template-preview-link { margin-block: .8rem 1.2rem; }
@media (max-width: 30rem) {
.page-template-groups .page-template-card { grid-template-columns: 1fr; }
.page-template-pages { grid-template-columns: 1fr; }
}
+51
View File
@@ -0,0 +1,51 @@
'use strict';
jQuery(function ($) {
$('[data-page-template-drawer]').each(function () {
const drawer = this;
const $drawer = $(drawer);
const $opener = $('[data-open-page-templates]').prop('hidden', false);
const $panels = $drawer.find('[data-template-panel]');
const $detail = $panels.filter('[data-template-panel=detail]');
const $form = $detail.find('form');
let $groupButton;
let $pageButton;
function showPanel(key, $focus) {
const $panel = $panels.filter((_, panel) => panel.dataset.templatePanel === key);
$panels.prop('hidden', true);
$panel.prop('hidden', false);
$drawer.scrollTop(0);
($focus ?? $panel.find('h3')).trigger('focus');
}
function open() {
drawer.showModal();
showPanel('groups');
}
$opener.on('click', open);
$drawer.on('close', () => $opener.trigger('focus'))
.on('click', '[data-close-page-templates]', () => drawer.close())
.on('click', '[data-template-group]', function () {
$groupButton = $(this);
showPanel(this.dataset.templateGroup);
})
.on('click', '[data-page-template]', function () {
$pageButton = $(this);
const key = this.dataset.pageTemplate;
const name = $pageButton.find('strong').text();
$detail.find('[data-template-name]').text(name);
$detail.find('[data-template-preview]').attr('src', $pageButton.find('img').attr('src'));
$detail.find('[data-template-live]').attr('href', '/admin/page-templates/' + key + '/preview');
$form.find('[name=template], [name=slug]').val(key);
$form.find('[name=name]').val(name);
$form.children('.ajax-feedback').prop('hidden', true);
showPanel('detail');
})
.on('click', '[data-template-back=groups]', () => showPanel('groups', $groupButton))
.on('click', '[data-template-back=pages]', () => showPanel($groupButton.attr('data-template-group'), $pageButton));
if ($drawer.is('[data-open-on-load]')) open();
});
});
Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 220 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

+116
View File
@@ -0,0 +1,116 @@
.page-theme {
color: var(--ink);
background: var(--white);
--space-section: clamp(3.5rem, 7vw, 7rem);
}
.page-theme .hero-inner { min-height: clamp(29rem, 46vw, 44rem); }
.page-theme .hero h1 { font-size: clamp(2.65rem, 5vw, 5.2rem); text-wrap: balance; }
.page-theme .hero-text-only .hero-copy { max-width: 49rem; }
.page-theme .app-frame img { aspect-ratio: 4 / 3; object-fit: contain; }
.page-theme .section-heading h2 { font-size: clamp(1.9rem, 4vw, 3.6rem); }
.page-theme .page-photo-credit { padding-bottom: 1.4rem; margin-bottom: 0; color: var(--muted); font-size: .875rem; }
.page-theme .studio-code { color: #e7eeff; background: #202938; border-color: #39465d; }
.page-theme .studio-code code { white-space: pre-wrap; overflow-wrap: anywhere; }
.theme-cobalt {
--white: #fdfdff;
--paper: #f0f4fb;
--ink: #162237;
--muted: #46586f;
--line: #cbd7e5;
--accent: #184ed3;
--accent-deep: #153a9b;
}
.theme-cobalt .hero {
background: radial-gradient(ellipse at 77% 28%, #c9dafa 0, transparent 45%),
radial-gradient(circle, #96adc8 1px, transparent 1px) 0 0 / 16px 16px, var(--paper);
}
.theme-cobalt .app-frame {
border-radius: 1.1rem .2rem;
border-color: #4c6284;
background: #252f40;
box-shadow: 0 24px 45px -30px #2136569c;
}
.theme-cobalt .button { border-radius: .25rem; border-bottom-width: 3px; }
.theme-cobalt .button-outline { background: var(--white); }
.theme-cobalt .button-primary { border-bottom-color: #123884; }
.template-ledger { border-block-start: 2px solid var(--ink); }
.template-ledger article { display: grid; grid-template-columns: minmax(0, .8fr) minmax(0, 1.2fr); gap: 1rem; padding: 1.35rem 0; border-bottom: 1px solid var(--line); }
.template-ledger article h3 { margin: 0; }
.theme-studio {
--white: #fbfaf7;
--paper: #eeeae2;
--ink: #211e19;
--muted: #5f5547;
--line: #cfc5b6;
--accent: #9c3818;
--accent-deep: #78290f;
--accent-light: #ffe7d5;
}
.theme-studio .hero {
background: radial-gradient(circle, #9d8269 1px, transparent 1px) 0 0 / 24px 24px, var(--paper);
}
.theme-studio .hero-copy { background: var(--paper); padding-block: .85rem 1.25rem; }
.theme-studio :is(h1, h2, h3) {
font-family: 'Noto Serif CJK SC', 'Songti SC', 'STSong', Georgia, serif;
font-weight: 560;
letter-spacing: -.055em;
}
.theme-studio .app-frame {
padding: .45rem;
border-radius: 0;
border-color: #6f5342;
outline: 1px solid #a24528;
outline-offset: .45rem;
background: var(--white);
box-shadow: 12px 19px 0 -9px #684e3429;
}
.theme-studio .app-frame img { border-radius: 0; object-fit: cover; }
.theme-studio .button { border-radius: .15rem; }
.theme-studio .button-primary { color: #231911; background: #f3a578; border-color: #713a24; }
.theme-studio .button-primary:hover { background: #f8ba96; }
.theme-studio .button-outline { background: var(--white); border-color: #827261; }
.template-portfolio { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: clamp(1.4rem, 5vw, 4rem); }
.template-portfolio img { width: 100%; aspect-ratio: 3 / 2; object-fit: contain; border: 1px solid var(--line); border-radius: 0; background: var(--paper); }
.template-portfolio h3 { margin-top: 1rem; }
.theme-dusk {
--white: #191d2b;
--paper: #222739;
--ink: #f7f4f2;
--muted: #bfc5d8;
--line: #505971;
--accent: #bdc7ff;
--accent-deep: #dbe1ff;
--accent-light: #343d5e;
}
.theme-dusk .hero { background: radial-gradient(ellipse at 77% 48%, #454255 0, #222639 46%, #191d2b 78%); }
.theme-dusk .app-frame {
border: 1px solid #8b869c;
background: #514d6370;
padding: .6rem;
box-shadow: 0 21px 65px -20px #090a18ab;
}
.theme-dusk .app-frame img { object-fit: cover; }
.theme-dusk .button-primary, .theme-dusk .button-primary:hover { color: #151a30; }
.theme-dusk .button-outline { color: var(--ink); border-color: #8c96b0; }
.theme-dusk .button-outline:hover { color: var(--accent-deep); background: var(--paper); }
.theme-dusk .crumb-divider { color: var(--muted); }
.theme-dusk .article-tabs button { background: var(--white); }
.template-steps {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: clamp(1.25rem, 4vw, 3rem);
border-block-start: 1px solid var(--line);
}
.rich .template-steps { padding-inline-start: 1.6rem; }
.template-steps li { padding: 1.35rem .25rem 0; }
.template-steps li::marker { color: var(--accent); font-weight: 650; }
@media (max-width: 44rem) {
.page-theme .hero-inner { min-height: auto; }
.template-ledger article, .template-portfolio, .template-steps { grid-template-columns: 1fr; }
.template-ledger article { gap: .4rem; }
.template-steps { gap: .8rem; }
}
+135
View File
@@ -0,0 +1,135 @@
<?php
use App\Content\BlockTemplates;
return [
'cobalt' => [
'name' => 'Cobalt · 钴蓝',
'description' => '冷白纸面、细分隔线与钴蓝按钮,适合开发工具和技术文档。',
'pages' => [
'cobalt-product' => [
'name' => '开发者工具首页',
'heading' => '让 DNS 放回你手里。',
'description' => '在自己的服务器上管理域名、解析策略与 API。用一个控制台看清每一条记录。',
'image' => '/assets/original/highspeaker-ui-optimized.webp',
'alt' => 'HighSpeaker DNS 管理面板',
'actions' => [['#capabilities', '查看能力'], ['/highspeaker', 'HighSpeaker DNS']],
'sections' => [
['capabilities', '一处管理解析策略', 'plain', <<<'HTML'
<div class="template-ledger">
<article><h3>按来源应答</h3><p>为不同地区或网络来源返回对应记录。</p></article>
<article><h3>程序化管理</h3><p>从脚本或控制面板更新记录,保留人工检查入口。</p></article>
<article><h3>自主部署</h3><p>选择服务器与部署方式,把解析服务放在自己管理的环境中。</p></article>
</div>
HTML, null],
['workflow', '从测试到切换', 'tinted', <<<'HTML'
<div class="studio-split"><pre class="studio-code"><code>dig @127.0.0.1 example.com A</code></pre><ol class="studio-timeline"><li><h3>录入记录</h3><p>先填写域名和解析目标。</p></li><li><h3>验证应答</h3><p>确认返回结果,再切换正式流量。</p></li></ol></div>
HTML, null],
['resources', '开始部署', 'plain', <<<'HTML'
<ul class="studio-resources"><li><a href="/highspeaker">阅读产品说明</a><span>HighSpeaker DNS</span></li><li><a href="/contact">联系技术团队</a><span>部署咨询</span></li></ul>
HTML, null],
],
],
'cobalt-guide' => [
'name' => '技术快速入门',
'heading' => '从首次查询开始。',
'description' => '用三个步骤搭建一个可验证的测试环境,在接入正式流量前确认解析结果。',
'image' => '',
'alt' => '',
'actions' => [['#first-query', '执行首次查询']],
'sections' => [
['first-query', '验证第一条记录', 'plain', <<<'HTML'
<div class="studio-split"><div><h3>从本机发起查询</h3><p>将地址改为你的测试服务器,并将示例域名替换成已配置的域名。</p></div><pre class="studio-code"><code>dig @127.0.0.1 example.com A +short</code></pre></div>
HTML, null],
['checks', '上线前检查', 'tinted', <<<'HTML'
<div class="table-scroll"><table><thead><tr><th scope="col">检查项</th><th scope="col">预期结果</th></tr></thead><tbody><tr><td>域名</td><td>与控制台中的区域一致。</td></tr><tr><td>记录类型</td><td>查询类型与配置匹配。</td></tr><tr><td>解析结果</td><td>目标地址与部署计划一致。</td></tr></tbody></table></div>
HTML, null],
['troubleshooting', '常见问题', 'plain', <<<'HTML'
<div class="faq"><details><summary>查询一直超时怎么办?</summary><div><p>先确认服务在监听,再核对防火墙和查询地址。</p></div></details><details><summary>为什么旧结果还在?</summary><div><p>递归解析器可能仍在缓存上一条记录,检查该记录的 TTL。</p></div></details></div>
HTML, null],
],
],
],
],
'studio' => [
'name' => 'Studio · 工作室',
'description' => '衬线标题、校样网格与橙色标记,适合案例和项目介绍。',
'pages' => [
'studio-portfolio' => [
'name' => '作品与服务',
'heading' => '从一张校样,到一个网站。',
'description' => '汇集网站和视觉系统的项目作品,向访客展示你能合作的方式。',
'image' => '/assets/page-templates/studio-letterpress.webp',
'alt' => '排印工作台上的木质活字',
'actions' => [['#selected-work', '看作品'], ['/contact', '聊聊项目']],
'sections' => [
['selected-work', '项目档案', 'plain', <<<'HTML'
<div class="template-portfolio">
<article><img src="/assets/original/pagepan-example.webp" alt="PAGEPAN 网页版式" loading="lazy"><h3><a href="/pagepan">PAGEPAN 可视化建站</a></h3><p>从可视化画布组装响应式网页。</p></article>
<article><img src="/assets/original/highspeaker-ui-optimized.webp" alt="HighSpeaker DNS 控制台" loading="lazy"><h3><a href="/highspeaker">HighSpeaker DNS</a></h3><p>把解析记录放进可自主部署的控制面板。</p></article>
</div>
HTML, null],
['practice', '一起把方案落地', 'tinted', <<<'HTML'
<div class="studio-two-column"><article><h3>梳理内容</h3><p>先确认访客需要看到什么、完成什么,再安排页面顺序。</p></article><article><h3>交付与维护</h3><p>交付可编辑的网站,帮助团队把内容更新纳入日常工作。</p></article></div>
HTML, null],
['enquiries', '有项目想讨论?', 'plain', '<p class="actions"><a class="button button-primary" href="/contact">联系来笙</a></p>', null],
],
],
'studio-case' => [
'name' => '单个项目案例',
'heading' => '把建站流程放到画布上。',
'description' => '从内容结构、组件组合到发布,记录一个可视化建站项目的设计思路。',
'image' => '/assets/original/pagepan-editor-optimized.webp',
'alt' => 'PAGEPAN 可视化编辑界面',
'actions' => [['#project-brief', '阅读案例'], ['/pagepan', '查看 PAGEPAN']],
'sections' => [
['project-brief', '项目概要', 'plain', <<<'HTML'
<dl class="studio-metrics"><div><dt>目标</dt><dd>可视化编辑</dd></div><div><dt>范围</dt><dd>组件与发布</dd></div><div><dt>交付</dt><dd>自托管网站</dd></div></dl>
HTML, null],
['design-notes', '设计过程', 'tinted', <<<'HTML'
<div class="studio-split"><img src="/assets/original/pagepan-example.webp" alt="PAGEPAN 页面示例" loading="lazy"><div><h3>先定内容,再定版式</h3><p>把首屏、介绍和行动按钮拆成区块,让团队直接在页面里替换文字、图片和链接。</p></div></div>
HTML, null],
['next-step', '查看可用工具', 'plain', '<p class="actions"><a class="button button-primary" href="/services">浏览产品与服务</a></p>', null],
],
],
],
],
'dusk' => [
'name' => 'Dusk · 暮色',
'description' => '暮色摄影、深石板背景和淡紫按钮,适合产品发布和更新说明。',
'pages' => [
'dusk-launch' => [
'name' => '产品发布页',
'heading' => '把上线的每一步安排好。',
'description' => '给团队一份从预览、核对到上线的清晰路径,让第一次发布更从容。',
'image' => '/assets/page-templates/dusk-dunes.webp',
'alt' => '暮色下的犹他沙丘',
'actions' => [['#release-plan', '查看发布流程'], ['/contact', '联系支持']],
'sections' => [
['release-plan', '发布流程', 'plain', <<<'HTML'
<ol class="template-steps"><li><h3>在草稿中预览</h3><p>检查标题、版式和页面主链接。</p></li><li><h3>确认资源可加载</h3><p>查看手机布局,确认图片和视频可用。</p></li><li><h3>发布并记录变更</h3><p>检查公开地址,留下更新说明。</p></li></ol>
HTML, null],
['release-checks', '准备上线', 'tinted', <<<'HTML'
<ul class="studio-checklist"><li>核对公开标题与分享图</li><li>在不同窗口尺寸下检查首屏</li><li>为站点维护人员交接编辑入口</li></ul>
HTML, null],
['support', '需要发布协助?', 'plain', '<p class="actions"><a class="button button-primary" href="/contact">联系来笙</a></p>', null],
],
],
'dusk-updates' => [
'name' => '版本与动态',
'heading' => '每一次更新,都找得到。',
'description' => '把版本说明和站点动态放在同一页,方便读者了解改动和后续安排。',
'image' => '/assets/original/home-hero.webp',
'alt' => '来笙云端服务插画',
'actions' => [['#latest-notes', '看最新动态']],
'sections' => [
['latest-notes', '最新动态', 'plain', '', BlockTemplates::ARTICLE_FEED],
['release-notes', '版本说明', 'tinted', <<<'HTML'
<div class="studio-releases"><article><h3>主要改动</h3><p>在这里总结本次发布解决的问题,以及用户可以如何使用新功能。</p></article><article><h3>升级与迁移</h3><p>列出更新前需要备份的内容、操作步骤和验证方法。</p></article></div>
HTML, null],
['feedback', '反馈与联系', 'plain', '<p class="actions"><a class="button button-primary" href="/contact">提交反馈</a></p>', null],
],
],
],
],
];
+1
View File
@@ -16,6 +16,7 @@ CREATE TABLE IF NOT EXISTS pages (
alignments TEXT NOT NULL DEFAULT '{}',
actions TEXT NOT NULL,
quicklinks TEXT NOT NULL,
theme TEXT NOT NULL DEFAULT '',
status TEXT NOT NULL DEFAULT 'published' CHECK (status IN ('draft', 'published')),
updated_at TEXT,
version INTEGER NOT NULL DEFAULT 0
+73 -1
View File
@@ -32,6 +32,7 @@ async function run(browser) {
return response.json();
}
await verifyPageTemplateDrawer(context, page, slug, csrf);
await post('/admin/new-page', {slug, name: '画布测试页'});
await page.goto('/admin');
const dashboard = page.locator('[data-page-list]');
@@ -294,6 +295,77 @@ async function run(browser) {
await context.close();
}
async function verifyPageTemplateDrawer(context, page, slug, csrf) {
await page.goto('/admin/articles');
assert.equal(await page.locator('[src="/assets/page-template-drawer.js"]').count(), 0);
await page.goto('/admin');
const opener = page.getByRole('button', {name: '整页模板'});
await opener.click();
const drawer = page.getByRole('dialog', {name: '整页模板'});
const groups = drawer.locator('[data-template-group]:visible');
assert.equal(await groups.count(), 3);
const assertThumbnails = async (cards) => {
assert(await cards.locator('img').evaluateAll(async (images) => {
await Promise.all(images.map((image) => image.decode()));
return images.length > 0 && images.every((image) => image.naturalWidth === 768);
}));
};
await assertThumbnails(groups);
for (const theme of ['cobalt', 'studio', 'dusk']) {
await drawer.locator(`[data-template-group="${theme}"]`).click();
const pages = drawer.locator('[data-page-template]:visible');
assert.equal(await pages.count(), 2);
await assertThumbnails(pages);
await drawer.getByRole('button', {name: '返回套系'}).click();
}
await page.keyboard.press('Escape');
await drawer.waitFor({state: 'hidden'});
assert(await opener.evaluate((link) => link === document.activeElement));
await page.setViewportSize({width: 390, height: 844});
await opener.click();
await drawer.getByRole('button', {name: /Dusk/}).click();
await drawer.getByRole('button', {name: '版本与动态'}).click();
assert.equal((await drawer.boundingBox()).width, 390);
const preview = drawer.getByRole('link', {name: '打开完整页面预览'});
const response = await context.request.get(await preview.getAttribute('href'));
assert.equal(response.status(), 200);
assert.match(response.headers()['x-robots-tag'], /noindex/);
assert.match(await response.text(), /theme-dusk/);
await drawer.getByRole('button', {name: '返回套内页面'}).click();
await drawer.getByRole('button', {name: '版本与动态'}).click();
const newSlug = slug.replace('studio-browser-', 'page-template-');
await drawer.getByLabel('页面名称').fill('模板草稿测试');
await drawer.getByLabel('网址标识').fill(newSlug);
await drawer.getByRole('button', {name: '用此模板创建草稿'}).click();
await page.waitForURL('**/admin/pages/' + newSlug);
await page.setViewportSize({width: 1480, height: 960});
assert.equal((await context.request.get('/' + newSlug)).status(), 404);
const frame = page.frameLocator('iframe[title="可编辑页面画布"]');
await frame.locator('main.theme-dusk').waitFor();
const title = frame.locator('#release-notes h2');
await title.fill('本周更新记录');
await frame.locator('#latest-notes[data-studio-dynamic]').waitFor();
await page.locator('#studio-page-settings [name=status]').selectOption('published');
await page.getByRole('button', {name: '保存页面', exact: true}).first().click();
await page.locator('[data-save-confirmation]').waitFor();
const published = await context.request.get('/' + newSlug);
assert.equal(published.status(), 200);
const html = await published.text();
assert.match(html, /page-themes\.css/);
assert.match(html, /本周更新记录/);
assert.doesNotMatch(html, /page-template-drawer\.(?:js|css)/);
assert.doesNotMatch(await (await context.request.get('/')).text(), /page-themes\.css/);
const duplicate = await context.request.post('/admin/new-page', {
form: {csrf, slug: newSlug, name: '重复地址', template: 'studio-case'},
headers: {'X-Requested-With': 'XMLHttpRequest'},
});
assert.equal(duplicate.status(), 422);
assert.match(await (await context.request.get('/' + newSlug)).text(), /theme-dusk/);
}
async function verifyArticleLibrary(browser, context, page, post, slug, feedId) {
const category = String(Date.now());
await post('/admin/article-categories', {slug: category, name: '自定义测试分类'});
@@ -593,7 +665,7 @@ async function verifyDirectoryWidth(directory) {
const browser = await chromium.launch({executablePath: process.env.CHROMIUM_EXECUTABLE || undefined});
try {
await run(browser);
console.log('Passed Chromium dashboard, template library, dynamic modules, homepage link reflow, scoped archives, and article deletion.');
console.log('Passed Chromium dashboard, page and component templates, dynamic modules, homepage links, scoped archives, and article deletion.');
} finally {
await browser.close();
}