45 changed files with 936 additions and 40 deletions
+52 -1
View File
@@ -28,6 +28,8 @@ php bin/admin.php reset admin@example.com
## 后台编辑
- **网站后台**可按名称、地址或发布状态查找页面,从列表打开画布、公开页或草稿预览。
- **整页模板**可以从后台首页、新建页面或画布打开独立抽屉。先选套系,再选页面,查看缩略图或完整预览后创建草稿。主题样式只由使用模板的公开页及预览加载,抽屉资源只由有入口的后台页面加载。六个套系共十二个页面,参考 [Hallmark](https://github.com/nutlope/hallmark) 的 Cobalt、Studio、Dusk、Vantage、Ribbon 和 Furrow。
- **页面显示**可以分别开关页头、首屏和页脚。选中画布里的首屏标题可移除首屏,并在页面设置中恢复。选中普通区块标题可删除整个区块,保存页面后生效。
- **页面设计**支持新建草稿、发布和撤回。首屏标题与简介可在桌面或手机画布中直接编辑。区块支持新增、排序、删除、可视化编辑、媒体插入和 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 +44,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 +66,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 +132,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 数据库和管理员账户。测试会在该库创建页面、分类和测试文章。
+7
View File
@@ -54,6 +54,13 @@ 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 ''");
}
if (!in_array('visibility', $pageColumns, true)) {
$pdo->exec("ALTER TABLE pages ADD COLUMN visibility 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,
};
}
}
+22 -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()]);
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
@@ -52,7 +62,7 @@ final class Repository
if (!$page) {
return null;
}
foreach (['actions', 'quicklinks', 'alignments'] as $key) {
foreach (['actions', 'quicklinks', 'alignments', 'visibility'] as $key) {
$page[$key] = json_decode($page[$key], true, flags: JSON_THROW_ON_ERROR);
}
$query = $this->pdo->prepare('SELECT * FROM sections WHERE page_slug = ? ORDER BY position, key');
@@ -78,11 +88,11 @@ final class Repository
{
Database::write(function (PDO $pdo) use ($slug, $data, $version, $sections): void {
$query = $pdo->prepare('UPDATE pages SET name = ?, title = ?, description = ?, heading = ?, accent = ?, lead = ?,
image = ?, alt = ?, image_scale = ?, alignments = ?, actions = ?, quicklinks = ?, status = ?, updated_at = ?, version = version + 1 WHERE slug = ? AND version = ?');
image = ?, alt = ?, image_scale = ?, alignments = ?, actions = ?, quicklinks = ?, visibility = ?, status = ?, updated_at = ?, version = version + 1 WHERE slug = ? AND version = ?');
$query->execute([
$data['name'], $data['title'], $data['description'], $data['heading'], $data['accent'], $data['lead'],
$data['image'], $data['alt'], $data['image_scale'], Database::json($data['alignments']), Database::json($data['actions']), Database::json($data['quicklinks']),
$data['status'], self::now(), $slug, $version,
Database::json($data['visibility']), $data['status'], self::now(), $slug, $version,
]);
self::checkVersion($query->rowCount());
foreach ($sections as $section) {
@@ -136,6 +146,10 @@ final class Repository
$query = $pdo->prepare('DELETE FROM sections WHERE page_slug = ? AND key = ? AND version = ?');
$query->execute([$page, $key, $version]);
self::checkVersion($query->rowCount());
$pdo->prepare("UPDATE pages SET
quicklinks = (SELECT json_group_array(json(value)) FROM json_each(quicklinks) WHERE json_extract(value, '$[0]') <> :anchor),
actions = (SELECT json_group_array(json(value)) FROM json_each(actions) WHERE json_extract(value, '$[0]') <> :anchor)
WHERE slug = :slug")->execute(['anchor' => '#' . $key, 'slug' => $page]);
}
public function arrangeSection(string $page, string $key, string $operation, int $version, int $pageVersion): void
+17 -3
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,
]);
}
@@ -271,6 +272,18 @@ class AdminController
}
$page = array_replace($page, $data, ['version' => $this->version($request)]);
try {
$data['visibility'] = $page['visibility'];
foreach (['hero', 'header', 'footer'] as $area) {
$value = $request->post('show_' . $area);
if ($value === null) {
continue;
}
if (!in_array($value, ['0', '1'], true)) {
throw new RuntimeException('页面显示选项不正确。');
}
$data['visibility'][$area] = $value === '1';
}
$page['visibility'] = $data['visibility'];
$data['alignments'] = $request->post('alignments') === null ? $page['alignments']
: $this->alignmentMap(json_decode($this->input($request, 'alignments'), true), ['heading', 'lead', 'actions', 'image']);
$page['alignments'] = $data['alignments'];
@@ -278,7 +291,7 @@ class AdminController
if ($data['name'] === '' || mb_strlen($data['name']) > 100 || !in_array($data['status'], ['draft', 'published'], true)
|| $data['title'] === '' || mb_strlen($data['title']) > 160 ||
($data['status'] === 'published' && $data['description'] === '') || mb_strlen($data['description']) > 300 ||
$data['heading'] === '' || mb_strlen($data['heading'] . $data['accent']) > 110 ||
(($data['visibility']['hero'] ?? true) && $data['heading'] === '') || mb_strlen($data['heading'] . $data['accent']) > 110 ||
mb_strlen($data['lead']) > 600 || mb_strlen($data['alt']) > 200 ||
($data['image_scale'] !== 0 && ($data['image_scale'] < 10 || $data['image_scale'] > 100)) ||
strlen($data['image']) > 1000 || ($data['image'] !== '' && !Html::url($data['image'], true)) || !$validButtons) {
@@ -295,6 +308,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);
}
@@ -363,8 +377,8 @@ class AdminController
throw new RuntimeException('区块已变更或画布内容无效,请重新打开编辑页。');
}
if ($delete) {
if ($isNew || empty($available[$key]['feed'])) {
throw new RuntimeException('此区块不能通过模块工具删除。');
if ($isNew) {
throw new RuntimeException('未保存的区块无需提交删除。');
}
$updates[$key] = compact('key', 'version', 'delete');
continue;
+3 -2
View File
@@ -41,6 +41,7 @@ final class SiteController
{
$slug = $page['slug'];
$isHome = $slug === 'home';
$showHero = $page['visibility']['hero'] ?? true;
$categories = $repo->categories();
foreach ($page['sections'] as &$section) {
if (!$section['feed']) {
@@ -75,8 +76,8 @@ final class SiteController
'path' => $isHome ? '/' : '/' . $slug,
'title' => $page['title'],
'description' => $page['description'],
'socialImage' => $page['image'],
'socialAlt' => $page['alt'],
'socialImage' => $showHero ? $page['image'] : '',
'socialAlt' => $showHero ? $page['alt'] : '',
'previewMode' => $preview, 'canvas' => $preview && $canvas, 'noindex' => $preview,
]);
}
+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>
+12
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>
@@ -121,6 +122,16 @@ $previewUrl = '/admin/pages/' . $slug . '/preview';
<label>页面名称<input name="name" value="<?= $e($page['name']) ?>" required maxlength="100"></label>
<label>SEO 标题<input name="title" value="<?= $e($page['title']) ?>" required maxlength="160"></label>
<label>SEO 描述<textarea name="description" rows="2" maxlength="300"><?= $e($page['description']) ?></textarea></label>
<fieldset class="admin-options form-grid">
<legend>页面显示</legend>
<?php foreach (['header' => '页头', 'hero' => '首屏', 'footer' => '页脚'] as $area => $label): ?>
<?php $visible = $page['visibility'][$area] ?? true; ?>
<label><?= $e($label) ?><select name="show_<?= $e($area) ?>">
<option value="1" <?= $visible ? 'selected' : '' ?>>显示</option>
<option value="0" <?= !$visible ? 'selected' : '' ?>>隐藏</option>
</select></label>
<?php endforeach ?>
</fieldset>
<?php
$contentFields = [
'heading' => $page['heading'], 'accent' => $page['accent'], 'lead' => $page['lead'],
@@ -146,3 +157,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')) ?>
+1 -1
View File
@@ -3,7 +3,7 @@ use App\Content\View;
$e = View::escape(...);
?>
<footer class="site-footer" id="contact">
<footer class="site-footer" id="contact"<?= empty($hideFooter) ? '' : ' hidden' ?>>
<div class="wrap">
<div class="footer-grid">
<div class="footer-company" itemscope itemtype="https://schema.org/Organization">
+11 -3
View File
@@ -16,6 +16,9 @@ $header = ($site['header'] ?? []) + SiteDesign::DEFAULT_HEADER;
$footer = SiteDesign::footer($site);
$nav = $header['links'];
$contact = $header['button'];
$theme = $page['theme'] ?? '';
$showHeader = $page['visibility']['header'] ?? true;
$showFooter = $page['visibility']['footer'] ?? true;
?>
<!doctype html>
<html lang="zh-CN" data-type="<?= $e($kind) ?>" data-buttons="solid" data-motion="on">
@@ -46,12 +49,14 @@ $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>
<body<?= $kind === 'service' ? ' class="copyright-service"' : '' ?>>
<a class="skip-link" href="#main-content">跳到内容</a>
<header class="masthead">
<?php if ($showHeader || !empty($canvas)): ?>
<header class="masthead"<?= $showHeader ? '' : ' hidden' ?>>
<div class="wrap masthead-inner">
<a class="wordmark" href="/" aria-label="来笙 Laysense 首页">
<?php if ($header['logo'] !== ''): ?>
@@ -75,7 +80,10 @@ $contact = $header['button'];
<?php endif ?>
</div>
</header>
<main id="main-content" tabindex="-1"><?= $content ?></main>
<?= View::fragment('footer', ['footer' => $footer]) ?>
<?php endif ?>
<main id="main-content"<?= $theme !== '' ? ' class="page-theme theme-' . $e($theme) . '"' : '' ?> tabindex="-1"><?= $content ?></main>
<?php if ($showFooter || !empty($canvas)): ?>
<?= View::fragment('footer', ['footer' => $footer, 'hideFooter' => !$showFooter]) ?>
<?php endif ?>
</body>
</html>
+15 -4
View File
@@ -1,16 +1,22 @@
<?php
use App\Content\PageTemplates;
use App\Content\View;
$e = View::escape(...);
$home = $page['slug'] === 'home';
$service = in_array($page['slug'], ['sc', 'shnu-sc'], true);
$showHero = $page['visibility']['hero'] ?? true;
$heroLinks = array_filter($page['sections'], static fn (array $section): bool => $section['style'] === 'hero-links');
$alignments = $page['alignments'];
$alignField = static fn (string $name): string => $canvas ? ' data-studio-align-field="' . $name . '"' : '';
$field = static fn (string $name): string => $canvas ? ' data-studio-field="' . $name . '"' : '';
?>
<?php if (!$showHero && !$canvas): ?><h1 class="sr-only"><?= $e($page['name']) ?></h1><?php endif ?>
<?php if ($showHero || $canvas || $heroLinks): ?>
<section class="hero hero-<?= $e($page['slug']) ?>" id="home" data-enter>
<div class="wrap hero-inner<?= $page['image'] === '' ? ' hero-text-only' : '' ?>">
<?php if ($showHero || $canvas): ?>
<div class="wrap hero-inner<?= $page['image'] === '' ? ' hero-text-only' : '' ?>"<?= $canvas ? ' data-studio-hero-content' : '' ?><?= $showHero ? '' : ' hidden' ?>>
<div class="hero-copy">
<?php if (!$home): ?>
<nav class="breadcrumbs" aria-label="面包屑" itemscope itemtype="https://schema.org/BreadcrumbList">
@@ -55,12 +61,12 @@ $field = static fn (string $name): string => $canvas ? ' data-studio-field="' .
</div>
<?php endif ?>
</div>
<?php foreach ($page['sections'] as $section): ?>
<?php if ($section['style'] === 'hero-links'): ?>
<?= View::fragment('section', ['section' => $section, 'moment' => false, 'canvas' => $canvas, 'pageSlug' => $page['slug']]) ?>
<?php endif ?>
<?php foreach ($heroLinks as $section): ?>
<?= View::fragment('section', ['section' => $section, 'moment' => false, 'canvas' => $canvas, 'pageSlug' => $page['slug']]) ?>
<?php endforeach ?>
</section>
<?php endif ?>
<?php if ($canvas || $page['quicklinks']): ?>
<nav class="section-nav" aria-label="本页目录"<?= $canvas ? ' data-studio-navigation' : '' ?><?= !$page['quicklinks'] ? ' hidden' : '' ?>>
<div class="wrap section-nav-inner">
@@ -75,6 +81,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 (($showHero || $canvas) && ($credit = PageTemplates::photoCredit($page['image']))): ?>
<p class="wrap page-photo-credit"<?= $showHero ? '' : ' hidden' ?>>摄影 <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')) ?>
+60
View File
@@ -0,0 +1,60 @@
<?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-detail">
<div>
<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>
</div>
<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>
</div>
</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']);
+64
View File
@@ -0,0 +1,64 @@
.page-template-drawer {
position: fixed;
inset: 0 0 0 auto;
margin: 0;
width: min(100%, clamp(45rem, 80vw, 78rem));
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-groups { grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr)); }
.page-template-pages { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.page-template-detail { display: grid; gap: clamp(1rem, 3vw, 2rem); align-items: start; }
.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-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 (min-width: 49rem) {
.page-template-detail { grid-template-columns: minmax(0, 1.8fr) minmax(17rem, 1fr); }
.page-template-detail .form-grid { grid-template-columns: 1fr; }
}
@media (max-width: 30rem) {
.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: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 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

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

+172
View File
@@ -0,0 +1,172 @@
.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; }
}
.theme-vantage {
--white: #121b20;
--paper: #1b272d;
--ink: #eef4f1;
--muted: #bdcdc8;
--line: #53676b;
--accent: #bfe971;
--accent-deep: #d7ffa0;
--accent-light: #2e4233;
}
.theme-vantage .hero {
background: radial-gradient(ellipse at 82% 35%, #243b39, transparent 65%),
radial-gradient(circle, #4b6959 1px, transparent 1.4px) 0 0 / 18px 18px, var(--white);
}
.theme-vantage .hero-copy { background: #121b20; padding-block: 1rem; }
.theme-vantage .app-frame { border: 1px solid #618076; border-radius: .2rem; background: #263738; box-shadow: 8px 8px 0 #172e26; }
.theme-vantage .app-frame img, .theme-vantage .button { border-radius: .2rem; }
.theme-vantage .button-primary, .theme-vantage .button-primary:hover { color: #172318; }
.theme-vantage .button-outline { border-color: #7d9b8e; color: var(--ink); }
.theme-vantage .button-outline:hover { background: var(--paper); }
.theme-ribbon {
--white: #fffdfb;
--paper: #f0eaf8;
--ink: #2d2546;
--muted: #5a516e;
--line: #d9cce8;
--accent: #633ab1;
--accent-deep: #4d268e;
--accent-light: #ebdfff;
}
.theme-ribbon .hero { background: radial-gradient(ellipse at 88% 24%, #d9c5f3, transparent 60%), #f5eff9; }
.theme-ribbon .app-frame { border-color: #b9a1db; border-radius: clamp(1.4rem, 4vw, 3rem); background: #fffafc; box-shadow: 0 22px 65px -31px #68489b83; }
.theme-ribbon .app-frame img { border-radius: 1rem; object-fit: cover; }
.theme-ribbon .button { border-radius: 2rem; }
.theme-ribbon .button-outline { border-color: #ac99c8; background: var(--white); }
.theme-ribbon .studio-split img { border-radius: 1.4rem; border: 1px solid var(--line); }
.theme-furrow {
--white: #fdf9ee;
--paper: #f1e9d5;
--ink: #262b1c;
--muted: #5a5847;
--line: #c9bd9f;
--accent: #325335;
--accent-deep: #233a27;
--accent-light: #e3ecd9;
}
.theme-furrow .hero { background: linear-gradient(115deg, #f7f0dd, #eee2c5); }
.theme-furrow .hero-copy { border-inline-start: .3rem solid #b67e28; padding-inline-start: clamp(1rem, 2.6vw, 2.2rem); }
.theme-furrow :is(h1, h2) { font-family: 'Noto Serif CJK SC', 'Songti SC', Georgia, serif; }
.theme-furrow .app-frame { border: 1px solid #9f946f; border-radius: .3rem; background: #fff8e7; box-shadow: 9px 9px 0 #c6ae7d56; }
.theme-furrow .app-frame img { border-radius: .15rem; }
.theme-furrow .button { border-radius: .2rem; }
.theme-furrow .button-outline { border-color: #908764; background: var(--white); }
+2 -1
View File
@@ -262,7 +262,7 @@ progress { width: 100%; height: .8rem; accent-color: var(--accent); }
.contact-panel { display: flex; flex-wrap: wrap; gap: 1.4rem 3rem; align-items: center; }
.contact-panel img { width: 10rem; border: 1px solid var(--line); }
.resource-box { max-width: 46rem; }
.faq { max-width: 62rem; border-top: 1px solid var(--line); }
.faq { border-top: 1px solid var(--line); }
.faq details { border-bottom: 1px solid var(--line); }
.faq summary { cursor: pointer; padding: 1.05rem 2.5rem 1.05rem 0; min-height: 48px; position: relative; list-style: none; font-weight: 630; }
.faq summary::-webkit-details-marker { display: none; }
@@ -479,6 +479,7 @@ progress { width: 100%; height: .8rem; accent-color: var(--accent); }
}
.hero h1 .hero-heading-primary { color: inherit; }
.studio-accent { display: block; }
[data-studio-editing] .hero:has(> [data-studio-hero-content][hidden]):not(:has(> .hero-directory-slot)) { display: none; }
[data-studio-editing] [contenteditable], [data-studio-editing] [data-studio-action],
[data-studio-editing] [data-studio-navigation] a, [data-studio-editing] [data-studio-hero-image] {
outline: 1px dashed #7896d5;
+44 -9
View File
@@ -306,8 +306,7 @@ jQuery(function ($) {
const $alignTools = $elementTools.find('[data-element-align]');
const alignments = ['left', 'center', 'right'];
const alignmentClasses = alignments.map((value) => 'studio-align-' + value);
const heroOrOptional = '[data-studio-field="accent"], [data-studio-field="lead"], [data-studio-part="lead"], [data-studio-action], [data-studio-nav-index]';
const canvasFields = heroOrOptional + ', [data-studio-field="heading"], [data-studio-part="title"]';
const canvasFields = '[data-studio-field="heading"], [data-studio-field="accent"], [data-studio-field="lead"], [data-studio-part="title"], [data-studio-part="lead"], [data-studio-action], [data-studio-nav-index]';
const bodyElements = 'a, article, blockquote, details, div, dl, dt, dd, figure, h1, h2, h3, h4, h5, h6, hr, li, ol, p, pre, progress, table, ul';
const mediaTargets = '[data-studio-hero-image], [data-studio-part="body"] img, [data-studio-part="body"] audio, [data-studio-part="body"] video';
const $handle = $studio.find('[data-media-handle]');
@@ -359,7 +358,7 @@ jQuery(function ($) {
const $moduleForm = $moduleDialog.find('form');
const moduleInput = (name) => $moduleForm.find('[name="' + name + '"]');
let editedModule;
let deletedModules = [];
let deletedSections = [];
const propertyInput = (name) => $propertyForm.find('[name="' + name + '"]');
const pageInput = (name) => $settings.find('[name="' + name + '"]');
const settingsSnapshot = () => $settings.serializeArray()
@@ -402,7 +401,7 @@ jQuery(function ($) {
if (feedChanged) edit.feed = feed;
return [edit];
});
return [...edits, ...deletedModules];
return [...edits, ...deletedSections];
}
$settings.on('studio:sync', () => pageInput('canvas_sections').val(JSON.stringify(sectionChanges())));
@@ -514,6 +513,15 @@ jQuery(function ($) {
}
function bindPage($doc) {
const visibilityTargets = {header: '.masthead', hero: '[data-studio-hero-content], .page-photo-credit', footer: '.site-footer'};
for (const [area, selector] of Object.entries(visibilityTargets)) {
const $input = pageInput('show_' + area);
const $target = $doc.find(selector);
$input.on('change.canvas', () => {
selectElement(null);
$target.prop('hidden', $input.val() === '0');
});
}
const labels = {name: '页面名称', heading: '首屏标题', accent: '标题第二行', lead: '首屏简介'};
$doc.find('[data-studio-field]').each(function () {
const field = this.dataset.studioField;
@@ -622,6 +630,20 @@ jQuery(function ($) {
return $navContent.find('[data-studio-nav-index="' + (index + 1) + '"]').get(0);
});
$navInput.on('input.canvas', syncNavigation);
heroControls.set('remove-section-links', (key) => {
const anchor = '#' + key;
$navInput.val(navLines().filter((line) => {
const separator = line.indexOf('|');
return separator < 0 || line.slice(separator + 1).trim() !== anchor;
}).join('\n'));
syncNavigation();
for (const index of [1, 2]) {
const $url = pageInput('url' + index);
if ($url.val().trim() !== anchor) continue;
pageInput('label' + index).val('');
$url.val('').trigger('input');
}
});
heroControls.set('navigation', () => {
openProperties('本页目录', {quicklinks: $navInput.val()}, ({quicklinks}) => {
$navInput.val(quicklinks);
@@ -832,7 +854,10 @@ jQuery(function ($) {
const aligned = dynamic ? null : alignmentTarget(node);
syncAlignmentButtons(aligned);
$elementTools.find('[data-element-copy]').prop('hidden', !canCopy);
$elementTools.find('[data-element-delete]').prop('hidden', !dynamic && !inBody && !selectedMedia && !node.matches(heroOrOptional));
const deleteLabel = node.dataset.studioField === 'heading' ? '删除首屏'
: node.dataset.studioPart === 'title' ? '删除区块' : '删除';
$elementTools.find('[data-element-delete]').attr({'aria-label': deleteLabel, title: deleteLabel})
.prop('hidden', !dynamic && !inBody && !selectedMedia && !node.matches(canvasFields));
$elementTools.find('[data-element-properties]').prop('hidden', !hasProperties);
if (target) showMediaWidth(currentMediaWidth(target));
selectionObserver?.observe(target || aligned || node);
@@ -848,6 +873,15 @@ jQuery(function ($) {
return;
}
const {studioField, studioAction, studioNavIndex} = node.dataset;
if (!copy && studioField === 'heading') {
pageInput('show_hero').val('0').trigger('change');
$studio.find('[data-canvas-status]').text('首屏已移除,可在页面设置中恢复。');
return;
}
if (!copy && node.dataset.studioPart === 'title') {
changeModule(sections.find((section) => section.node === node.closest('[data-studio-section]')), false);
return;
}
const inBody = node.closest('[data-studio-part="body"]') !== null;
selectElement(null);
if (inBody) {
@@ -958,9 +992,10 @@ jQuery(function ($) {
function removeSection(section) {
if (section.node.contains(activeBody)) selectBody(null);
if (section.node.contains(selectedElement)) selectElement(null);
if (section.version !== null) deletedModules.push({key: section.key, version: section.version, delete: true});
if (section.version !== null) deletedSections.push({key: section.key, version: section.version, delete: true});
section.node.remove();
sections = sections.filter((entry) => entry !== section);
heroControls.get('remove-section-links')(section.key);
section.$pending?.remove();
$pending.prop('hidden', !$pending.children().length);
}
@@ -989,9 +1024,9 @@ jQuery(function ($) {
function changeModule(section, copy) {
if (!section) return;
if (!copy) {
if (window.confirm('删除此模块?保存页面后生效。')) {
if (window.confirm('删除此区块?保存页面后生效。')) {
removeSection(section);
$studio.find('[data-canvas-status]').text('模块已移除,保存页面后生效。');
$studio.find('[data-canvas-status]').text('区块已移除,保存页面后生效。');
}
return;
}
@@ -1178,7 +1213,7 @@ jQuery(function ($) {
selectElement(null);
$pending.empty().prop('hidden', true);
sections = [];
deletedModules = [];
deletedSections = [];
$doc.find('[data-studio-section]').each((_, section) => registerSection(section));
$doc.on('focusin.canvas', '[contenteditable]', function () {
+104
View File
@@ -0,0 +1,104 @@
<?php
return [
'vantage' => [
'name' => 'Vantage · 观测台',
'description' => '蓝黑底色、仪表边框和青柠色操作入口,适合基础设施与运维说明。',
'pages' => [
'vantage-infrastructure' => [
'name' => '基础设施概览',
'heading' => '从一个界面看清解析服务。',
'description' => '为自托管服务整理部署入口、解析策略和故障排查资料。',
'image' => '/assets/original/highspeaker-ui-optimized.webp',
'alt' => 'HighSpeaker DNS 控制台',
'actions' => [['#deployment', '查看部署说明'], ['/highspeaker', '产品主页']],
'sections' => [
['deployment', '部署与管理', '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],
['visibility', '检查服务可用性', 'tinted', <<<'HTML'
<div class="studio-split"><div><h3>记录预期结果</h3><p>每次变更后,从服务节点和外部网络分别发起查询。</p></div><pre class="studio-code"><code>dig @127.0.0.1 example.com A</code></pre></div>
HTML, null],
['infra-resources', '产品与支持', 'plain', '<ul class="studio-resources"><li><a href="/highspeaker">查看 HighSpeaker DNS</a><span>产品文档</span></li><li><a href="/contact">联系来笙</a><span>技术咨询</span></li></ul>', null],
],
],
'vantage-runbook' => [
'name' => '运维操作手册',
'heading' => '按步骤排查服务故障。',
'description' => '把常用的检查、回退和交接步骤集中到一页,方便团队值班时使用。',
'image' => '',
'alt' => '',
'actions' => [['#first-checks', '开始排查']],
'sections' => [
['first-checks', '先核对这三项', 'plain', '<ol class="template-steps"><li><h3>确认影响范围</h3><p>检查是单一区域受影响,还是所有请求都失败。</p></li><li><h3>查看最近变更</h3><p>核对配置、证书与部署记录。</p></li><li><h3>比对响应</h3><p>比较本地与公开地址的访问结果。</p></li></ol>', null],
['recovery', '恢复与回退', 'tinted', '<ul class="studio-checklist"><li>保留当前配置与日志。</li><li>按团队约定恢复最近的可用配置。</li><li>从两个网络确认服务恢复。</li></ul>', null],
['handover', '交接记录', 'plain', '<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>', null],
],
],
],
],
'ribbon' => [
'name' => 'Ribbon · 柔彩',
'description' => '柔紫色封面、圆角图片与清晰的步骤组合,适合入门教程与帮助中心。',
'pages' => [
'ribbon-onboarding' => [
'name' => '新手入门页',
'heading' => '做出你的第一个网页。',
'description' => '从选模板、编辑组件到检查手机预览,走完一次完整的建站流程。',
'image' => '/assets/original/pagepan-example.webp',
'alt' => 'PAGEPAN 网页模板示例',
'actions' => [['#start-building', '开始学习'], ['/pagepan', '查看 PAGEPAN']],
'sections' => [
['start-building', '从三个动作开始', 'plain', '<ol class="template-steps"><li><h3>选一个版式</h3><p>用符合内容结构的模板开工。</p></li><li><h3>替换内容</h3><p>换上自己的文案、照片和链接。</p></li><li><h3>检查预览</h3><p>分别用桌面和手机尺寸浏览。</p></li></ol>', null],
['editor-tour', '认识编辑器', 'tinted', '<div class="studio-split"><img src="/assets/original/pagepan-editor-optimized.webp" alt="PAGEPAN 画布" loading="lazy"><div><h3>在画布上选中元素</h3><p>修改内容后,保留必要的导航和行动按钮。</p></div></div>', null],
['more-lessons', '继续学习', 'plain', '<ul class="studio-resources"><li><a href="/pagepan#download">获取 PAGEPAN</a><span>下载</span></li><li><a href="/articles">浏览产品动态</a><span>更新与文章</span></li></ul>', null],
],
],
'ribbon-help' => [
'name' => '产品帮助中心',
'heading' => '找到你眼下需要的帮助。',
'description' => '给访客一个独立入口,集中查看入门资料、常见问题和联系渠道。',
'image' => '/assets/original/home-hero.webp',
'alt' => '来笙云服务插画',
'actions' => [['#common-questions', '查看常见问题'], ['/contact', '联系支持']],
'sections' => [
['documentation', '快速入口', 'plain', '<ul class="studio-resources"><li><a href="/pagepan">可视化建站</a><span>PAGEPAN</span></li><li><a href="/highspeaker">智能 DNS</a><span>HighSpeaker DNS</span></li><li><a href="/articles">公告与动态</a><span>最新文章</span></li></ul>', null],
['common-questions', '常见问题', 'tinted', '<div class="faq"><details><summary>在哪里找下载入口?</summary><div><p>打开产品页,再查看页面中的下载区块。</p></div></details><details><summary>如何反馈问题?</summary><div><p>通过联系页发送所用产品和版本、操作步骤及遇到的问题。</p></div></details></div>', null],
['support-options', '联系团队', 'plain', '<p class="actions"><a class="button button-primary" href="/contact">查看联系方式</a></p>', null],
],
],
],
],
'furrow' => [
'name' => 'Furrow · 田垄',
'description' => '暖纸色、墨绿和琥珀色线条,适合服务介绍与办理清单。',
'pages' => [
'furrow-service' => [
'name' => '服务说明页',
'heading' => '从准备材料到提交申请。',
'description' => '清楚列出软件著作权服务的办理流程,以及申请人需要准备的材料。',
'image' => '/assets/original/copyright.webp',
'alt' => '软件著作权服务配图',
'actions' => [['#service-steps', '了解流程'], ['/sc', '查看服务详情']],
'sections' => [
['service-steps', '服务如何开展', 'plain', '<ol class="studio-timeline"><li><h3>了解项目</h3><p>先明确软件用途、申请主体和材料现状。</p></li><li><h3>核对材料</h3><p>按项目情况整理代码、使用说明与必要文件。</p></li><li><h3>提交并跟进</h3><p>核对信息后提交,并按办理进度补充材料。</p></li></ol>', null],
['prepare', '申请前准备', 'tinted', '<div class="studio-two-column"><article><h3>已经有项目</h3><p>整理项目代码、软件说明和主体信息。</p></article><article><h3>需要协助</h3><p>说明当前进度,方便团队判断需要哪些服务。</p></article></div>', null],
['service-contact', '咨询办理方案', 'plain', '<p class="actions"><a class="button button-primary" href="/contact">联系来笙</a></p>', null],
],
],
'furrow-checklist' => [
'name' => '办事准备清单',
'heading' => '把要准备的材料一次列清。',
'description' => '适合发布可逐项核对的材料清单、办理须知与后续链接。',
'image' => '',
'alt' => '',
'actions' => [['#materials-list', '查看材料清单']],
'sections' => [
['materials-list', '准备材料', 'plain', '<ul class="studio-checklist"><li>软件名称、版本与用途说明</li><li>可用于提交的代码材料</li><li>能够说明安装和操作的用户指南</li><li>适用时准备合作开发和主体证明材料</li></ul>', null],
['before-submitting', '提交前核对', 'tinted', '<div class="template-ledger"><article><h3>名称一致</h3><p>核对各材料中的软件名称和版本。</p></article><article><h3>说明完整</h3><p>确保文档能解释主要操作。</p></article><article><h3>文件齐全</h3><p>按申请类型核对所需证明。</p></article></div>', null],
['next-actions', '下一步', 'plain', '<ul class="studio-resources"><li><a href="/sc">查看软著服务</a><span>流程与方案</span></li><li><a href="/contact">咨询材料问题</a><span>联系方式</span></li></ul>', null],
],
],
],
],
];
+136
View File
@@ -0,0 +1,136 @@
<?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],
],
],
],
],
...require __DIR__ . '/page-templates-extra.php',
];
+2
View File
@@ -16,6 +16,8 @@ CREATE TABLE IF NOT EXISTS pages (
alignments TEXT NOT NULL DEFAULT '{}',
actions TEXT NOT NULL,
quicklinks TEXT NOT NULL,
theme TEXT NOT NULL DEFAULT '',
visibility TEXT NOT NULL DEFAULT '{}',
status TEXT NOT NULL DEFAULT 'published' CHECK (status IN ('draft', 'published')),
updated_at TEXT,
version INTEGER NOT NULL DEFAULT 0
+74 -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,78 @@ 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');
const themes = ['cobalt', 'studio', 'dusk', 'vantage', 'ribbon', 'furrow'];
assert.equal(await groups.count(), themes.length);
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 themes) {
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 +666,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();
}