Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
62c10b09bc | ||
|
|
935bc7f071 | ||
|
|
1a025353b2 | ||
|
|
ef1ff93904 | ||
|
|
74e0de84a6 | ||
|
|
9bc0ee0e45 |
@@ -27,10 +27,10 @@ php bin/admin.php reset admin@example.com
|
||||
|
||||
## 后台编辑
|
||||
|
||||
- **页面设计**支持新建草稿、发布和撤回。首屏标题与简介可在桌面或手机画布中直接编辑。区块支持新增、排序、删除、可视化编辑、媒体插入和 HTML 源码。单击画布元素可用浮动工具条复制或删除。选中媒体后,可拖动边缘手柄调整宽度。编辑器左侧可按分类和名称查找模板。悬停或键盘聚焦缩略图可放大,点击可打开预览。
|
||||
- **页面设计**支持新建草稿、发布和撤回。首屏标题与简介可在桌面或手机画布中直接编辑。区块支持新增、排序、删除、可视化编辑、媒体插入和 HTML 源码。单击画布元素可用浮动工具条复制或删除。选中媒体后,可拖动边缘手柄调整宽度。浮动工具条可将正文元素、区块标题和首屏元素对齐到左侧、中央或右侧。编辑器左侧可插入基础元素,或按分类和名称查找区块模板。悬停或键盘聚焦缩略图可放大,点击可打开预览。
|
||||
- **媒体库**集中列出项目静态文件及上传文件,支持查找、选取、复制路径、改名和归档。归档资源的已有 URL 保持可访问。上传文件放在 `LAYSENSE_MEDIA_DIR`,由 `/assets/uploads/` 提供。
|
||||
- **文章**使用自托管的 TOAST UI Editor 3.2.2(MIT)。Markdown 左侧源码、右侧实时预览,富文本使用所见即所得模式。文章可以加入多个分类,可在「管理分类」创建新分类。
|
||||
- **分类文章**支持在任意页面添加,保存区块后在「图层」中编辑分类、展示数量和合并或标签页模式。
|
||||
- **分类文章**支持在任意页面添加,保存区块后在「图层」中编辑分类、展示数量和合并或标签页模式。「查看全部动态」和翻页只列出该区块所选的分类。
|
||||
- **产品与服务**(`/services`)和**支持项目与合作伙伴**(`/network`)由文章分类生成。通过文章的目录卡片设置图片、链接和排序,使用草稿状态可从目录撤下。
|
||||
- **网站设置**分别编辑页头标志、导航及按钮,和页脚的公司信息、链接与备注。CDN 设置接受 HTTPS 源站地址。浏览器看到的公开 `/assets/…` 路径使用该源站。
|
||||
- 文章支持摘要和标签。状态选「草稿」可撤回公开文章。已发布文章改网址标识后,旧标识会自动跳转。
|
||||
@@ -70,7 +70,7 @@ location = /admin/media {
|
||||
| `LAYSENSE_SECURE_COOKIES` | 默认关闭 · 本地 HTTP 使用默认值。生产 HTTPS 设置为 `1`。 |
|
||||
| `LAYSENSE_TRUSTED_PROXIES` | 默认 `127.0.0.1,::1` · 逗号分隔的受信反代 IP,设为空字符串可关闭信任 |
|
||||
|
||||
SQLite 已启用 WAL。本版需要新的 SQLite 文件。将 `LAYSENSE_DB` 指向新文件,执行 `php bin/install.php`,再按上面的步骤创建管理员并重启 Webman。安装会预载网站自带页面、文章、产品和伙伴目录。服务用户需要对 SQLite 目录、媒体目录和 `runtime/` 有写权限。备份可用 `sqlite3 storage/laysense.sqlite ".backup 'laysense-backup.sqlite'"`,媒体目录单独保存。
|
||||
SQLite 已启用 WAL。使用上一版多分类文章结构的站点,可用当前 `LAYSENSE_DB` 运行 `php bin/install.php` 增加对齐字段,之后重启 Webman。全新安装时,将 `LAYSENSE_DB` 指向新文件并按上面的步骤初始化和创建管理员。安装会预载网站自带页面、文章、产品和伙伴目录。服务用户需要对 SQLite 目录、媒体目录和 `runtime/` 有写权限。备份可用 `sqlite3 storage/laysense.sqlite ".backup 'laysense-backup.sqlite'"`,媒体目录单独保存。
|
||||
|
||||
### CDN
|
||||
|
||||
|
||||
@@ -8,12 +8,25 @@ final class BlockTemplates
|
||||
{
|
||||
public const ARTICLE_FEED = '{"categories":["announcement","news","product"],"mode":"merged","limit":6}';
|
||||
|
||||
public const ELEMENTS = [
|
||||
'paragraph' => ['段落', '<p>填写正文。</p>'],
|
||||
'subheading' => ['小标题', '<h3>填写小标题</h3>'],
|
||||
'bullet-list' => ['项目列表', '<ul><li>填写列表项</li><li>填写列表项</li></ul>'],
|
||||
'button' => ['按钮', '<p><a class="button button-primary" href="#contact">联系来笙</a></p>'],
|
||||
'separator' => ['分割线', '<hr class="studio-divider">'],
|
||||
'code' => ['代码块', '<pre class="studio-code"><code>填写代码</code></pre>'],
|
||||
'image' => ['图片', '', 'image/'],
|
||||
'video' => ['视频', '', 'video/'],
|
||||
'audio' => ['音频', '', 'audio/'],
|
||||
];
|
||||
|
||||
public const GROUPS = [
|
||||
'content' => ['标题与正文', [
|
||||
'headline' => ['标题与简介', '<div class="studio-intro"><h3>填写区块标题</h3><p>用一句话补充背景或说明。</p></div>'],
|
||||
'text' => ['正文', '<p>在这里输入区块内容。</p>'],
|
||||
'articles' => ['分类文章', ''],
|
||||
'list' => ['步骤列表', '<ol><li>填写第一步</li><li>填写第二步</li><li>填写第三步</li></ol>'],
|
||||
'notice' => ['重点提示', '<div class="studio-notice"><h3>填写重要提示</h3><p>说明访客需要知悉的事项、条件或时间。</p></div>'],
|
||||
]],
|
||||
'cover' => ['封面与横幅', [
|
||||
'cover' => ['图文封面', '<div class="studio-cover"><img src="/assets/original/pagepan-example.webp" alt="" loading="lazy"><div><h3>用一句话介绍你的产品</h3><p>在首段说明访客能获得什么。</p><a class="button button-primary" href="/services">查看服务</a></div></div>'],
|
||||
@@ -23,17 +36,26 @@ final class BlockTemplates
|
||||
'image' => ['图文', '<div class="studio-split"><img src="/assets/original/home-hero.webp" alt="" loading="lazy"><div><h3>介绍主题</h3><p>在这里说明图片或产品。</p></div></div>'],
|
||||
'grid' => ['双栏网格', '<div class="studio-two-column"><article class="content-card"><h3>第一栏</h3><p>填写主要内容。</p></article><article class="content-card"><h3>第二栏</h3><p>补充相关信息。</p></article></div>'],
|
||||
]],
|
||||
'media' => ['媒体', [
|
||||
'gallery' => ['三图画廊', '<div class="studio-gallery"><img src="/assets/original/pagepan-editor-optimized.webp" alt="PAGEPAN 编辑器" loading="lazy"><img src="/assets/original/highspeaker-ui-optimized.webp" alt="HighSpeaker DNS 管理界面" loading="lazy"><img src="/assets/original/home-hero.webp" alt="云端服务插画" loading="lazy"></div>'],
|
||||
'video-demo' => ['视频演示', '<div class="studio-split"><video controls preload="none" poster="/assets/original/pagepan-editor-optimized.webp" src="/assets/original/drag-in-components.mp4"></video><div><h3>演示视频</h3><p>说明视频涵盖的功能与操作。</p></div></div>'],
|
||||
]],
|
||||
'features' => ['特性与口碑', [
|
||||
'features' => ['特性卡片', '<div class="card-grid feature-grid"><article class="content-card feature-card"><h3>特点一</h3><p>介绍这个特点。</p></article><article class="content-card feature-card"><h3>特点二</h3><p>介绍这个特点。</p></article><article class="content-card feature-card"><h3>特点三</h3><p>介绍这个特点。</p></article></div>'],
|
||||
'quote' => ['引文', '<blockquote><p>在这里填写引用或用户反馈。</p></blockquote>'],
|
||||
'metrics' => ['关键数据', '<dl class="studio-metrics"><div><dt>累计项目</dt><dd>100</dd></div><div><dt>服务覆盖</dt><dd>12</dd></div><div><dt>合作伙伴</dt><dd>8</dd></div></dl>'],
|
||||
'testimonials' => ['用户评价', '<div class="studio-two-column studio-testimonials"><blockquote><p>填写用户的评价,并说明他们获得的结果。</p><p class="studio-attribution">用户姓名 · 公司或角色</p></blockquote><blockquote><p>填写另一条用户评价。</p><p class="studio-attribution">用户姓名 · 公司或角色</p></blockquote></div>'],
|
||||
]],
|
||||
'details' => ['表格与问答', [
|
||||
'table' => ['对比表格', '<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></tbody></table>'],
|
||||
'faq' => ['常见问题', '<div class="faq"><details><summary>请输入问题</summary><div><p>请输入答案。</p></div></details></div>'],
|
||||
'timeline' => ['时间线', '<ol class="studio-timeline"><li><h3>确定目标</h3><p>填写这一阶段需要完成的事项。</p></li><li><h3>实施与验收</h3><p>填写交付时间与验收标准。</p></li></ol>'],
|
||||
'checklist' => ['清单', '<ul class="studio-checklist"><li>填写必备材料</li><li>填写提交条件</li><li>填写确认事项</li></ul>'],
|
||||
]],
|
||||
'actions' => ['导航与引导', [
|
||||
'navigation' => ['快速导航', '<ul class="studio-quick-nav"><li><a href="/services">产品与服务</a></li><li><a href="/articles">动态与文章</a></li><li><a href="/#contact">联系来笙</a></li></ul>'],
|
||||
'cta' => ['行动按钮', '<p>说明下一步。</p><p><a class="button button-primary" href="#contact">联系来笙</a></p>'],
|
||||
'resources' => ['资料与链接', '<ul class="studio-resources"><li><a href="/pagepan#download">获取 PAGEPAN</a><span>应用下载</span></li><li><a href="/articles">浏览动态与文档</a><span>网站资源</span></li></ul>'],
|
||||
]],
|
||||
];
|
||||
|
||||
|
||||
@@ -44,6 +44,12 @@ final class Database
|
||||
throw new RuntimeException('请将 LAYSENSE_DB 指向一个新的 SQLite 文件,再运行安装命令。');
|
||||
}
|
||||
$pdo->exec(file_get_contents($root . '/resources/schema.sql'));
|
||||
foreach (['pages', 'sections'] as $table) {
|
||||
$columns = array_column($pdo->query('PRAGMA table_info(' . $table . ')')->fetchAll(), 'name');
|
||||
if (!in_array('alignments', $columns, true)) {
|
||||
$pdo->exec("ALTER TABLE $table ADD COLUMN alignments TEXT NOT NULL DEFAULT '{}'");
|
||||
}
|
||||
}
|
||||
$site = $pdo->prepare('INSERT OR IGNORE INTO site_settings (id, payload) VALUES (1, ?)');
|
||||
$site->execute([self::json($seed['site'])]);
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@ use RuntimeException;
|
||||
|
||||
final class Html
|
||||
{
|
||||
public const ALIGNMENTS = ['left', 'center', 'right'];
|
||||
|
||||
private const TAGS = [
|
||||
'a' => ['href'], 'article' => [], 'audio' => ['src', 'controls', 'preload'], 'b' => [], 'blockquote' => [], 'br' => [],
|
||||
'caption' => [], 'code' => [], 'dd' => [], 'details' => [], 'div' => ['role', 'aria-label', 'tabindex'],
|
||||
|
||||
@@ -52,7 +52,7 @@ final class Repository
|
||||
if (!$page) {
|
||||
return null;
|
||||
}
|
||||
foreach (['actions', 'quicklinks'] as $key) {
|
||||
foreach (['actions', 'quicklinks', 'alignments'] 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');
|
||||
@@ -67,14 +67,21 @@ final class Repository
|
||||
return $this->one('SELECT * FROM sections WHERE page_slug = ? AND key = ?', [$page, $key]);
|
||||
}
|
||||
|
||||
public function publishedFeed(string $page, string $key): ?array
|
||||
{
|
||||
return $this->one("SELECT sections.title, sections.feed FROM sections
|
||||
JOIN pages ON pages.slug = sections.page_slug
|
||||
WHERE pages.slug = ? AND pages.status = 'published' AND sections.key = ? AND sections.feed IS NOT NULL", [$page, $key]);
|
||||
}
|
||||
|
||||
public function savePage(string $slug, array $data, int $version, array $sections = []): void
|
||||
{
|
||||
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 = ?, actions = ?, quicklinks = ?, status = ?, updated_at = ?, version = version + 1 WHERE slug = ? AND version = ?');
|
||||
image = ?, alt = ?, image_scale = ?, alignments = ?, actions = ?, quicklinks = ?, 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['actions']), Database::json($data['quicklinks']),
|
||||
$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,
|
||||
]);
|
||||
self::checkVersion($query->rowCount());
|
||||
@@ -98,9 +105,9 @@ final class Repository
|
||||
|
||||
private static function updateSection(PDO $pdo, string $page, string $key, array $data, int $version): void
|
||||
{
|
||||
$query = $pdo->prepare('UPDATE sections SET title = ?, lead = ?, body = ?, style = ?, feed = ?, version = version + 1
|
||||
$query = $pdo->prepare('UPDATE sections SET title = ?, lead = ?, body = ?, style = ?, feed = ?, alignments = COALESCE(?, alignments), version = version + 1
|
||||
WHERE page_slug = ? AND key = ? AND version = ?');
|
||||
$query->execute([$data['title'], $data['lead'], $data['body'], $data['style'], $data['feed'] ?? null, $page, $key, $version]);
|
||||
$query->execute([$data['title'], $data['lead'], $data['body'], $data['style'], $data['feed'] ?? null, $data['alignments'] ?? null, $page, $key, $version]);
|
||||
self::checkVersion($query->rowCount());
|
||||
}
|
||||
|
||||
@@ -114,9 +121,9 @@ final class Repository
|
||||
|
||||
private static function insertSection(PDO $pdo, string $page, string $key, array $data): void
|
||||
{
|
||||
$query = $pdo->prepare('INSERT OR IGNORE INTO sections (page_slug, key, title, lead, style, body, feed, position)
|
||||
SELECT ?, ?, ?, ?, ?, ?, ?, COALESCE(MAX(position), -1) + 1 FROM sections WHERE page_slug = ?');
|
||||
$query->execute([$page, $key, $data['title'], $data['lead'], $data['style'], $data['body'], $data['feed'] ?? null, $page]);
|
||||
$query = $pdo->prepare('INSERT OR IGNORE INTO sections (page_slug, key, title, lead, style, body, feed, alignments, position)
|
||||
SELECT ?, ?, ?, ?, ?, ?, ?, ?, COALESCE(MAX(position), -1) + 1 FROM sections WHERE page_slug = ?');
|
||||
$query->execute([$page, $key, $data['title'], $data['lead'], $data['style'], $data['body'], $data['feed'] ?? null, $data['alignments'] ?? '{}', $page]);
|
||||
if ($query->rowCount() !== 1) {
|
||||
throw new RuntimeException('此区块锚点已被使用。');
|
||||
}
|
||||
|
||||
@@ -65,6 +65,20 @@ final class View
|
||||
return $value ? date($format, strtotime($value)) : '';
|
||||
}
|
||||
|
||||
public static function alignmentClass(?string $alignment): string
|
||||
{
|
||||
return in_array($alignment, Html::ALIGNMENTS, true) ? ' studio-align-' . $alignment : '';
|
||||
}
|
||||
|
||||
public static function archivePage(string $path, int $page): string
|
||||
{
|
||||
if ($page === 1) {
|
||||
return $path;
|
||||
}
|
||||
|
||||
return $path . (str_contains($path, '?') ? '&' : '?') . 'page=' . $page;
|
||||
}
|
||||
|
||||
public static function redirect(string $path, int $status = 303): Response
|
||||
{
|
||||
return new Response($status, ['Location' => $path, 'Cache-Control' => $status === 301 ? 'public, max-age=300' : 'no-store'], '');
|
||||
|
||||
@@ -255,6 +255,9 @@ class AdminController
|
||||
}
|
||||
$page = array_replace($page, $data, ['version' => $this->version($request)]);
|
||||
try {
|
||||
$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'];
|
||||
$data['quicklinks'] = $request->post('quicklinks') === null ? $page['quicklinks'] : SiteDesign::parseLinks($this->input($request, 'quicklinks'));
|
||||
if ($data['name'] === '' || mb_strlen($data['name']) > 100 || !in_array($data['status'], ['draft', 'published'], true)
|
||||
|| $data['title'] === '' || mb_strlen($data['title']) > 160 ||
|
||||
@@ -334,8 +337,9 @@ class AdminController
|
||||
$key = $change['key'] ?? null;
|
||||
$version = $change['version'] ?? null;
|
||||
$fields = $change['fields'] ?? null;
|
||||
$alignments = $change['alignments'] ?? null;
|
||||
$isNew = is_array($change) && array_key_exists('version', $change) && $version === null;
|
||||
if (!is_string($key) || isset($updates[$key]) || !is_array($fields) || $fields === []
|
||||
if (!is_string($key) || isset($updates[$key]) || !is_array($fields) || ($fields === [] && $alignments === null)
|
||||
|| ($isNew ? (isset($available[$key]) || !preg_match('/^block-[a-f0-9]{32}$/D', $key))
|
||||
: (!isset($available[$key]) || !is_int($version) || $version !== (int) $available[$key]['version']))) {
|
||||
throw new RuntimeException('区块已变更或画布内容无效,请重新打开编辑页。');
|
||||
@@ -353,6 +357,9 @@ class AdminController
|
||||
}
|
||||
$section[$field] = trim($value);
|
||||
}
|
||||
if ($alignments !== null) {
|
||||
$section['alignments'] = Database::json($this->alignmentMap($alignments, ['title', 'lead']));
|
||||
}
|
||||
$this->checkSection($section, $section['style']);
|
||||
if (isset($fields['body'])) {
|
||||
$section['body'] = Html::sanitize($section['body']);
|
||||
@@ -367,6 +374,20 @@ class AdminController
|
||||
return $updates;
|
||||
}
|
||||
|
||||
private function alignmentMap(mixed $alignments, array $fields): array
|
||||
{
|
||||
if (!is_array($alignments) || array_diff(array_keys($alignments), $fields)) {
|
||||
throw new RuntimeException('画布对齐设置无效。');
|
||||
}
|
||||
foreach ($alignments as $value) {
|
||||
if (!in_array($value, Html::ALIGNMENTS, true)) {
|
||||
throw new RuntimeException('画布对齐设置无效。');
|
||||
}
|
||||
}
|
||||
|
||||
return $alignments;
|
||||
}
|
||||
|
||||
private function checkSection(array $section, string $savedStyle): void
|
||||
{
|
||||
if ($section['title'] === '' || mb_strlen($section['title']) > 100 || mb_strlen($section['lead']) > 500
|
||||
|
||||
@@ -39,10 +39,12 @@ final class SiteController
|
||||
$feed = json_decode($section['feed'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$tabs = $feed['mode'] === 'tabs' && count($feed['categories']) > 1;
|
||||
$section['articleFeed'] = [];
|
||||
$section['archivePath'] = $page['status'] === 'published' ? '/articles/feed/' . $slug . '/' . $section['key'] : null;
|
||||
foreach ($tabs ? $feed['categories'] : [''] as $category) {
|
||||
$selected = $category === '' ? $feed['categories'] : [$category];
|
||||
$section['articleFeed'][] = [
|
||||
'label' => $categories[$category] ?? '',
|
||||
'articles' => $repo->articles($category === '' ? $feed['categories'] : $category, limit: $feed['limit']),
|
||||
'categories' => $selected, 'label' => $categories[$category] ?? '',
|
||||
'articles' => $repo->articles($selected, limit: $feed['limit']),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -102,6 +104,60 @@ final class SiteController
|
||||
}
|
||||
$title = $category ? $categories[$category] : ($tag ?: '来笙动态');
|
||||
$path = '/articles' . ($category ? '/category/' . $category : ($tag ? '/tag/' . rawurlencode($tag) : ''));
|
||||
|
||||
$categoryLinks = [];
|
||||
foreach (array_keys($categories) as $key) {
|
||||
$categoryLinks[$key] = '/articles/category/' . $key;
|
||||
}
|
||||
|
||||
return $this->renderArchive($request, $repo, $category, $tag, [
|
||||
'headline' => $title, 'description' => '查看来笙的公告、新闻和产品动态。',
|
||||
'archivePath' => $path, 'allPath' => '/articles',
|
||||
'categoryLinks' => $categoryLinks,
|
||||
'categories' => $categories, 'category' => $category, 'tag' => $tag,
|
||||
'backPath' => $category || $tag ? '/articles' : null, 'backLabel' => '全部动态',
|
||||
]);
|
||||
}
|
||||
|
||||
public function feedArchive(Request $request, string $slug, string $key): Response
|
||||
{
|
||||
$repo = new Repository();
|
||||
$section = $repo->publishedFeed($slug, $key);
|
||||
if (!$section) {
|
||||
return $this->missing($request);
|
||||
}
|
||||
$feed = json_decode($section['feed'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$labels = $repo->categories();
|
||||
$categories = [];
|
||||
foreach ($feed['categories'] as $value) {
|
||||
if (isset($labels[$value])) {
|
||||
$categories[$value] = $labels[$value];
|
||||
}
|
||||
}
|
||||
$category = $request->get('category');
|
||||
if (!$categories || ($category !== null && (!is_string($category) || !isset($categories[$category])))) {
|
||||
return $this->missing($request);
|
||||
}
|
||||
|
||||
$allPath = '/articles/feed/' . $slug . '/' . $key;
|
||||
$returnPath = ($slug === 'home' ? '/' : '/' . $slug) . '#' . $key;
|
||||
$categoryLinks = [];
|
||||
foreach (array_keys($categories) as $value) {
|
||||
$categoryLinks[$value] = $allPath . '?category=' . rawurlencode((string) $value);
|
||||
}
|
||||
|
||||
return $this->renderArchive($request, $repo, $category ?? array_keys($categories), null, [
|
||||
'headline' => $section['title'] . ($category !== null ? ' · ' . $categories[$category] : ''),
|
||||
'description' => '查看' . implode('、', $categories) . '分类下的文章。',
|
||||
'archivePath' => $category === null ? $allPath : $categoryLinks[$category], 'allPath' => $allPath,
|
||||
'categoryLinks' => $categoryLinks, 'categories' => $categories, 'category' => $category, 'tag' => null,
|
||||
'categoryScope' => $category === null ? array_keys($categories) : [$category],
|
||||
'backPath' => $returnPath, 'backLabel' => '返回原页面', 'noindex' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
private function renderArchive(Request $request, Repository $repo, string|array|null $category, ?string $tag, array $view): Response
|
||||
{
|
||||
$number = $request->get('page', '1');
|
||||
if (!is_scalar($number) || !preg_match('/^[1-9][0-9]{0,4}$/D', (string) $number)) {
|
||||
return $this->missing($request);
|
||||
@@ -111,13 +167,12 @@ final class SiteController
|
||||
if ($page > 1 && $articles === []) {
|
||||
return $this->missing($request);
|
||||
}
|
||||
$path = $view['archivePath'];
|
||||
|
||||
return View::render('archive', [
|
||||
'site' => $repo->site(), 'title' => $title . ' · 来笙', 'headline' => $title,
|
||||
'description' => '查看来笙的公告、新闻和产品动态。',
|
||||
'path' => $path . ($page > 1 ? '?page=' . $page : ''), 'archivePath' => $path,
|
||||
'categories' => $categories, 'category' => $category, 'tag' => $tag, 'pageNumber' => $page,
|
||||
'hasNext' => count($articles) > 20, 'articles' => array_slice($articles, 0, 20),
|
||||
return View::render('archive', $view + [
|
||||
'site' => $repo->site(), 'title' => $view['headline'] . ' · 来笙',
|
||||
'path' => $page > 1 ? View::archivePage($path, $page) : $path,
|
||||
'pageNumber' => $page, 'hasNext' => count($articles) > 20, 'articles' => array_slice($articles, 0, 20),
|
||||
'noindex' => $articles === [],
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ $filters = $category ? 'category=' . rawurlencode($category) . '&' : '';
|
||||
<nav class="filter-nav" aria-label="筛选文章">
|
||||
<a href="/admin/articles" <?= $category === null ? 'aria-current="page"' : '' ?>>全部</a>
|
||||
<?php foreach ($categories as $key => $name): ?>
|
||||
<a href="/admin/articles?category=<?= $e($key) ?>" <?= $category === $key ? 'aria-current="page"' : '' ?>><?= $e($name) ?></a>
|
||||
<a href="/admin/articles?category=<?= $e($key) ?>" <?= $category === (string) $key ? 'aria-current="page"' : '' ?>><?= $e($name) ?></a>
|
||||
<?php endforeach ?>
|
||||
</nav>
|
||||
<div class="admin-panel">
|
||||
|
||||
@@ -2,12 +2,13 @@
|
||||
use App\Content\View;
|
||||
|
||||
$e = View::escape(...);
|
||||
$checked = array_fill_keys($selected, true);
|
||||
?>
|
||||
<fieldset class="category-checks">
|
||||
<legend><?= $e($legend) ?></legend>
|
||||
<div>
|
||||
<?php foreach ($categories as $key => $label): ?>
|
||||
<label><input type="checkbox" name="<?= $e($name) ?>[]" value="<?= $e($key) ?>" <?= in_array($key, $selected, true) ? 'checked' : '' ?>> <?= $e($label) ?></label>
|
||||
<label><input type="checkbox" name="<?= $e($name) ?>[]" value="<?= $e($key) ?>" <?= isset($checked[$key]) ? 'checked' : '' ?>> <?= $e($label) ?></label>
|
||||
<?php endforeach ?>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
use App\Content\Database;
|
||||
use App\Content\SiteDesign;
|
||||
use App\Content\View;
|
||||
use App\Content\BlockTemplates;
|
||||
@@ -92,6 +93,11 @@ $previewUrl = '/admin/pages/' . $slug . '/preview';
|
||||
<div class="studio-frame-window">
|
||||
<iframe title="可编辑页面画布" src="<?= $e($previewUrl) ?>?canvas=1" sandbox="allow-same-origin"></iframe>
|
||||
<div class="studio-element-tools" data-element-tools role="group" aria-label="所选元素" hidden>
|
||||
<div class="studio-element-align" data-element-align role="group" aria-label="对齐">
|
||||
<button type="button" data-align="left" aria-pressed="false">居左</button>
|
||||
<button type="button" data-align="center" aria-pressed="false">居中</button>
|
||||
<button type="button" data-align="right" aria-pressed="false">居右</button>
|
||||
</div>
|
||||
<button type="button" data-element-properties>属性</button>
|
||||
<button type="button" data-element-copy>复制</button>
|
||||
<button type="button" data-element-delete>删除</button>
|
||||
@@ -103,7 +109,7 @@ $previewUrl = '/admin/pages/' . $slug . '/preview';
|
||||
<button class="button button-outline" type="button" data-replace-media>替换媒体</button>
|
||||
</div>
|
||||
</div>
|
||||
<p class="field-note">单击画布中的元素可打开浮动工具条。选中媒体后可拖动边缘手柄调整宽度。</p>
|
||||
<p class="field-note">单击画布元素可设置对齐、复制或删除。选中媒体后可拖动边缘手柄调整宽度。</p>
|
||||
<dialog class="media-picker canvas-properties" data-canvas-properties aria-labelledby="canvas-properties-heading">
|
||||
<div class="admin-heading compact"><h2 id="canvas-properties-heading" data-property-heading>编辑属性</h2></div>
|
||||
<form class="admin-form" method="dialog">
|
||||
@@ -130,6 +136,7 @@ $previewUrl = '/admin/pages/' . $slug . '/preview';
|
||||
<input type="hidden" name="csrf" value="<?= $e($token) ?>">
|
||||
<input type="hidden" name="version" value="<?= $e($page['version']) ?>">
|
||||
<input type="hidden" name="canvas_sections" value="">
|
||||
<input type="hidden" name="alignments" value="<?= $e(Database::json($page['alignments'])) ?>">
|
||||
<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>
|
||||
|
||||
@@ -6,22 +6,22 @@ $e = View::escape(...);
|
||||
<section class="section article-page" aria-labelledby="archive-title" data-enter>
|
||||
<div class="wrap">
|
||||
<div class="section-heading">
|
||||
<?php if ($tag || $category): ?><a class="back-link" href="/articles">全部动态</a><?php endif ?>
|
||||
<?php if ($backPath): ?><a class="back-link" href="<?= $e($backPath) ?>"><?= $e($backLabel) ?></a><?php endif ?>
|
||||
<h1 id="archive-title"><?= $e($headline) ?></h1>
|
||||
<p>来笙的公告、新闻和产品动态。</p>
|
||||
<p><?= $e($description) ?></p>
|
||||
</div>
|
||||
<nav class="filter-nav" aria-label="动态分类">
|
||||
<a href="/articles" <?= !$category && !$tag ? 'aria-current="page"' : '' ?>>全部</a>
|
||||
<a href="<?= $e($allPath) ?>" <?= !$category && !$tag ? 'aria-current="page"' : '' ?>>全部</a>
|
||||
<?php foreach ($categories as $key => $label): ?>
|
||||
<a href="/articles/category/<?= $e($key) ?>" <?= $category === $key ? 'aria-current="page"' : '' ?>><?= $e($label) ?></a>
|
||||
<a href="<?= $e($categoryLinks[$key]) ?>" <?= $category === (string) $key ? 'aria-current="page"' : '' ?>><?= $e($label) ?></a>
|
||||
<?php endforeach ?>
|
||||
</nav>
|
||||
<?= View::fragment('article-list', ['articles' => $articles]) ?>
|
||||
<?= View::fragment('article-list', ['articles' => $articles, 'categoryScope' => $categoryScope ?? null]) ?>
|
||||
<?php if ($pageNumber > 1 || $hasNext): ?>
|
||||
<nav class="pagination" aria-label="动态分页">
|
||||
<?php if ($pageNumber > 1): ?><a class="button button-outline" href="<?= $e($archivePath . ($pageNumber > 2 ? '?page=' . ($pageNumber - 1) : '')) ?>" rel="prev">上一页</a><?php endif ?>
|
||||
<?php if ($pageNumber > 1): ?><a class="button button-outline" href="<?= $e(View::archivePage($archivePath, $pageNumber - 1)) ?>" rel="prev">上一页</a><?php endif ?>
|
||||
<span>第 <?= $e($pageNumber) ?> 页</span>
|
||||
<?php if ($hasNext): ?><a class="button button-outline" href="<?= $e($archivePath . '?page=' . ($pageNumber + 1)) ?>" rel="next">下一页</a><?php endif ?>
|
||||
<?php if ($hasNext): ?><a class="button button-outline" href="<?= $e(View::archivePage($archivePath, $pageNumber + 1)) ?>" rel="next">下一页</a><?php endif ?>
|
||||
</nav>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
|
||||
@@ -14,7 +14,10 @@ $e = View::escape(...);
|
||||
<?php foreach ($groups as $index => $group): ?>
|
||||
<div id="<?= $e($sectionKey) ?>-articles-<?= $index ?>" data-tab-panel>
|
||||
<?php if ($group['label'] !== ''): ?><h3 data-tab-heading><?= $e($group['label']) ?></h3><?php endif ?>
|
||||
<?= View::fragment('article-list', ['articles' => $group['articles']]) ?>
|
||||
<?= View::fragment('article-list', ['articles' => $group['articles'], 'categoryScope' => $group['categories']]) ?>
|
||||
</div>
|
||||
<?php endforeach ?>
|
||||
<?php if ($archivePath !== null): ?>
|
||||
<p class="article-feed-archive"><a class="back-link" href="<?= $e($archivePath) ?>">查看全部动态</a></p>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
|
||||
@@ -2,13 +2,15 @@
|
||||
use App\Content\View;
|
||||
|
||||
$e = View::escape(...);
|
||||
$scope = isset($categoryScope) ? array_flip($categoryScope) : null;
|
||||
?>
|
||||
<?php if ($articles): ?>
|
||||
<ul class="article-list">
|
||||
<?php foreach ($articles as $item): ?>
|
||||
<?php $labels = $scope === null ? $item['categories'] : array_intersect_key($item['categories'], $scope); ?>
|
||||
<li>
|
||||
<a class="article-row" href="/articles/<?= $e($item['slug']) ?>">
|
||||
<span class="article-category"><?= $e(implode('、', $item['categories'])) ?></span>
|
||||
<span class="article-category"><?= $e(implode('、', $labels)) ?></span>
|
||||
<span class="article-row-title"><?= $e($item['title']) ?>
|
||||
<?php if ($item['summary']): ?><small><?= $e($item['summary']) ?></small><?php endif ?>
|
||||
</span>
|
||||
|
||||
@@ -17,15 +17,21 @@ $e = View::escape(...);
|
||||
<?php if (!$group['articles']): ?><p class="empty-state">暂无已发布条目。</p><?php endif ?>
|
||||
<ul class="network-list">
|
||||
<?php foreach ($group['articles'] as $item): ?>
|
||||
<?php $card = $item['card']; $articlePath = '/articles/' . $item['slug']; ?>
|
||||
<?php
|
||||
// 优先跳卡片配置的网址;没有网址时,只有文章本身有内容才回退到文章页,否则不渲染链接。
|
||||
$card = $item['card'];
|
||||
$articlePath = '/articles/' . $item['slug'];
|
||||
$hasDetail = $item['body'] !== '' || $item['summary'] !== '';
|
||||
$target = ($card['url'] ?? '') ?: ($hasDetail ? $articlePath : '');
|
||||
?>
|
||||
<li>
|
||||
<a href="<?= $e(($card['url'] ?? '') ?: $articlePath) ?>">
|
||||
<?php if ($target !== ''): ?><a href="<?= $e($target) ?>"><?php else: ?><span class="network-static"><?php endif ?>
|
||||
<?php if (!empty($card['image'])): ?>
|
||||
<img src="<?= $e($card['image']) ?>" alt="" loading="lazy" width="76" height="28">
|
||||
<?php endif ?>
|
||||
<span><?= $e($item['title']) ?></span>
|
||||
</a>
|
||||
<?php if ($standalone && !empty($card['url']) && ($item['body'] !== '' || $item['summary'] !== '')): ?>
|
||||
<?php if ($target !== ''): ?></a><?php else: ?></span><?php endif ?>
|
||||
<?php if ($standalone && !empty($card['url']) && $hasDetail): ?>
|
||||
<a class="network-detail" href="<?= $e($articlePath) ?>">查看详情</a>
|
||||
<?php endif ?>
|
||||
</li>
|
||||
|
||||
@@ -5,6 +5,8 @@ use App\Content\View;
|
||||
$e = View::escape(...);
|
||||
$home = $page['slug'] === 'home';
|
||||
$service = in_array($page['slug'], ['sc', 'shnu-sc'], true);
|
||||
$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 . '"' : '';
|
||||
?>
|
||||
<section class="hero hero-<?= $e($page['slug']) ?>" id="home" data-enter>
|
||||
@@ -25,16 +27,16 @@ $field = static fn (string $name): string => $canvas ? ' data-studio-field="' .
|
||||
<?php else: ?>
|
||||
<p class="overline hero-label"><?= $e($site['footer']['name'] ?? $site['name']) ?></p>
|
||||
<?php endif ?>
|
||||
<h1><span class="hero-heading-primary"<?= $field('heading') ?>><?= $e($page['heading']) ?></span><?php if ($canvas): ?><span class="studio-accent"<?= $field('accent') ?>><?= $e($page['accent']) ?></span><?php elseif ($page['accent'] !== ''): ?><br><span><?= $e($page['accent']) ?><?php if ($home): ?><span class="home-cursor" aria-hidden="true">_</span><?php endif ?></span><?php elseif ($home): ?><span class="home-cursor" aria-hidden="true">_</span><?php endif ?></h1>
|
||||
<p class="hero-lead"<?= $field('lead') ?>><?= $e($page['lead']) ?></p>
|
||||
<div class="actions hero-actions">
|
||||
<h1<?= isset($alignments['heading']) ? ' class="' . trim(View::alignmentClass($alignments['heading'])) . '"' : '' ?><?= $alignField('heading') ?>><span class="hero-heading-primary"<?= $field('heading') ?>><?= $e($page['heading']) ?></span><?php if ($canvas): ?><span class="studio-accent"<?= $field('accent') ?>><?= $e($page['accent']) ?></span><?php elseif ($page['accent'] !== ''): ?><br><span><?= $e($page['accent']) ?><?php if ($home): ?><span class="home-cursor" aria-hidden="true">_</span><?php endif ?></span><?php elseif ($home): ?><span class="home-cursor" aria-hidden="true">_</span><?php endif ?></h1>
|
||||
<p class="hero-lead<?= View::alignmentClass($alignments['lead'] ?? null) ?>"<?= $field('lead') ?><?= $alignField('lead') ?>><?= $e($page['lead']) ?></p>
|
||||
<div class="actions hero-actions<?= View::alignmentClass($alignments['actions'] ?? null) ?>"<?= $alignField('actions') ?>>
|
||||
<?php foreach ($canvas ? array_pad($page['actions'], 2, ['', '']) : $page['actions'] as $index => [$url, $label]): ?>
|
||||
<a class="button <?= $index ? 'button-outline' : 'button-primary' ?>" href="<?= $e($url) ?>"<?= $canvas ? ' data-studio-action="' . ($index + 1) . '"' : '' ?><?= $label === '' && $url === '' ? ' hidden' : '' ?>><?= $e($label) ?></a>
|
||||
<?php endforeach ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php if ($canvas || $page['image'] !== ''): ?>
|
||||
<div class="hero-visual <?= $home ? 'hero-illustration' : ($service ? 'hero-service-art' : 'app-frame') ?><?= $page['image_scale'] ? ' studio-media-' . $e($page['image_scale']) : '' ?>" data-visual<?= $page['image'] === '' ? ' hidden' : '' ?>>
|
||||
<div class="hero-visual <?= $home ? 'hero-illustration' : ($service ? 'hero-service-art' : 'app-frame') ?><?= $page['image_scale'] ? ' studio-media-' . $e($page['image_scale']) : '' ?><?= View::alignmentClass($alignments['image'] ?? null) ?>" data-visual<?= $alignField('image') ?><?= $page['image'] === '' ? ' hidden' : '' ?>>
|
||||
<img<?= $page['image'] === '' ? '' : ' src="' . $e($page['image']) . '"' ?> alt="<?= $e($page['alt']) ?>" width="1448" height="1086" fetchpriority="high"<?= $canvas ? ' data-studio-hero-image' : '' ?>>
|
||||
<?php if ($home && !$canvas && $page['image'] === '/assets/original/home-hero.webp'): ?>
|
||||
<svg class="home-pipe-flow" viewBox="0 0 640 480" aria-hidden="true" focusable="false">
|
||||
|
||||
@@ -3,16 +3,21 @@ use App\Content\View;
|
||||
|
||||
$e = View::escape(...);
|
||||
$canvas ??= false;
|
||||
$body = $section['body'];
|
||||
$alignments = json_decode($section['alignments'] ?? '{}', true, flags: JSON_THROW_ON_ERROR);
|
||||
if (isset($section['articleFeed']) && $body === '<p><a class="back-link" href="/articles">查看全部动态</a></p>') {
|
||||
$body = '';
|
||||
}
|
||||
?>
|
||||
<section class="section section-<?= $e($section['style']) ?>" id="<?= $e($section['key']) ?>" aria-labelledby="heading-<?= $e($section['key']) ?>" <?= $moment ? 'data-moment="iris-opens"' : '' ?><?= $canvas ? ' data-studio-section="' . $e($section['version']) . '" data-studio-source="' . $e(base64_encode($section['body'])) . '"' : '' ?>>
|
||||
<div class="wrap">
|
||||
<div class="section-heading">
|
||||
<h2 id="heading-<?= $e($section['key']) ?>"<?= $canvas ? ' data-studio-part="title"' : '' ?>><?= $e($section['title']) ?></h2>
|
||||
<?php if ($canvas || $section['lead']): ?><p<?= $canvas ? ' data-studio-part="lead"' : '' ?>><?= $e($section['lead']) ?></p><?php endif ?>
|
||||
<h2 id="heading-<?= $e($section['key']) ?>"<?= isset($alignments['title']) ? ' class="' . trim(View::alignmentClass($alignments['title'])) . '"' : '' ?><?= $canvas ? ' data-studio-part="title"' : '' ?>><?= $e($section['title']) ?></h2>
|
||||
<?php if ($canvas || $section['lead']): ?><p<?= isset($alignments['lead']) ? ' class="' . trim(View::alignmentClass($alignments['lead'])) . '"' : '' ?><?= $canvas ? ' data-studio-part="lead"' : '' ?>><?= $e($section['lead']) ?></p><?php endif ?>
|
||||
</div>
|
||||
<?php if (!empty($section['articleFeed'])): ?>
|
||||
<?= View::fragment('article-feed', ['groups' => $section['articleFeed'], 'sectionKey' => $section['key']]) ?>
|
||||
<?= View::fragment('article-feed', ['groups' => $section['articleFeed'], 'sectionKey' => $section['key'], 'archivePath' => $section['archivePath']]) ?>
|
||||
<?php endif ?>
|
||||
<?php if ($canvas || $section['body'] !== ''): ?><div class="rich<?= !empty($section['articleFeed']) ? ' article-feed-note' : '' ?>"<?= $canvas ? ' data-studio-part="body"' : '' ?>><?= $section['body'] ?></div><?php endif ?>
|
||||
<?php if ($canvas || $body !== ''): ?><div class="rich<?= !empty($section['articleFeed']) ? ' article-feed-note' : '' ?>"<?= $canvas ? ' data-studio-part="body"' : '' ?>><?= $body ?></div><?php endif ?>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -16,23 +16,30 @@ $e = View::escape(...);
|
||||
<?php if (!$products): ?><p class="empty-state">暂无可查看的产品和服务。</p><?php endif ?>
|
||||
<div class="catalog-grid">
|
||||
<?php foreach ($products as $product): ?>
|
||||
<?php $card = $product['card']; $articlePath = '/articles/' . $product['slug']; ?>
|
||||
<?php
|
||||
// 目录卡片指向卡片自己配置的网址;没有网址时,只有文章本身有内容才回退到文章页。
|
||||
$card = $product['card'];
|
||||
$hasDetail = $product['body'] !== '' || $product['summary'] !== '';
|
||||
$target = ($card['url'] ?? '') ?: ($hasDetail ? '/articles/' . $product['slug'] : '');
|
||||
?>
|
||||
<article class="catalog-card">
|
||||
<?php if (!empty($card['image'])): ?>
|
||||
<div class="catalog-image"><img src="<?= $e($card['image']) ?>" alt="<?= $e($card['alt'] ?? '') ?>" loading="lazy"></div>
|
||||
<?php endif ?>
|
||||
<div class="catalog-content">
|
||||
<?php if (!empty($card['category_label'])): ?><p class="overline"><?= $e($card['category_label']) ?></p><?php endif ?>
|
||||
<h2><a href="<?= $e($articlePath) ?>"><?= $e($product['title']) ?></a></h2>
|
||||
<h2><?php if ($target !== ''): ?><a href="<?= $e($target) ?>"><?= $e($product['title']) ?></a><?php else: ?><?= $e($product['title']) ?><?php endif ?></h2>
|
||||
<?php if ($product['summary']): ?>
|
||||
<p><?= $e($product['summary']) ?></p>
|
||||
<?php else: ?>
|
||||
<div class="rich"><?= Html::articleBody($product) ?></div>
|
||||
<?php endif ?>
|
||||
<?php if ($target !== '' || !empty($card['extra_url'])): ?>
|
||||
<div class="actions">
|
||||
<a class="button button-primary" href="<?= $e(($card['url'] ?? '') ?: $articlePath) ?>"><?= $e(($card['label'] ?? '') ?: '了解详情') ?></a>
|
||||
<?php if ($target !== ''): ?><a class="button button-primary" href="<?= $e($target) ?>"><?= $e(($card['label'] ?? '') ?: '了解详情') ?></a><?php endif ?>
|
||||
<?php if (!empty($card['extra_url'])): ?><a href="<?= $e($card['extra_url']) ?>"><?= $e(($card['extra_label'] ?? '') ?: '相关链接') ?></a><?php endif ?>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
</article>
|
||||
<?php endforeach ?>
|
||||
|
||||
@@ -6,6 +6,19 @@ use App\Content\View;
|
||||
$e = View::escape(...);
|
||||
?>
|
||||
<div class="studio-presets" data-canvas-presets>
|
||||
<details class="studio-element-library">
|
||||
<summary>基础元素</summary>
|
||||
<div role="group" aria-label="添加基础元素">
|
||||
<?php foreach (BlockTemplates::ELEMENTS as $key => $element): ?>
|
||||
<?php [$label, $markup, $mime] = array_pad($element, 3, ''); ?>
|
||||
<button type="button" disabled data-canvas-element="<?= $e($key) ?>"
|
||||
<?php if ($mime): ?>data-element-mime="<?= $e($mime) ?>"<?php endif ?>
|
||||
aria-label="插入<?= $e($label) ?>"><?= $e($label) ?></button>
|
||||
<template data-element="<?= $e($key) ?>"><?= $markup ?></template>
|
||||
<?php endforeach ?>
|
||||
</div>
|
||||
<p class="field-note" data-element-status role="status">选中画布正文后插入。</p>
|
||||
</details>
|
||||
<label class="studio-template-search">搜索模板<input type="search" data-template-search placeholder="按名称或分类搜索" autocomplete="off"></label>
|
||||
<div class="studio-template-filters" role="group" aria-label="模板分类">
|
||||
<button type="button" data-template-filter="" aria-pressed="true">全部</button>
|
||||
|
||||
@@ -16,6 +16,7 @@ Route::get('/assets/uploads/{name:[a-f0-9]{32}\.[a-z0-9]+}', [MediaController::c
|
||||
Route::get('/articles', [SiteController::class, 'archive']);
|
||||
Route::get('/articles/category/{category:[a-z0-9-]+}', [SiteController::class, 'archive']);
|
||||
Route::get('/articles/tag/{tag:[^/]+}', [SiteController::class, 'tagged']);
|
||||
Route::get('/articles/feed/{slug:[a-z0-9-]+}/{key:[a-z0-9-]+}', [SiteController::class, 'feedArchive']);
|
||||
Route::get('/articles/{slug:[a-z0-9-]+}', [SiteController::class, 'article']);
|
||||
Route::get('/main', static fn () => View::redirect('/articles', 301));
|
||||
Route::get('/main/category/{id:[0-9]+}.html', [SiteController::class, 'legacyCategory']);
|
||||
|
||||
@@ -234,3 +234,15 @@
|
||||
.article-editor-heading { display: flex; align-items: center; justify-content: space-between; gap: .6rem; margin-bottom: .45rem; }
|
||||
.article-editor-heading > .button { min-height: 2.1rem; padding: .25rem .6rem; }
|
||||
.article-editor-help:empty { display: none; }
|
||||
|
||||
.studio-element-library { padding: .55rem .65rem; border: 1px solid var(--line); border-radius: .5rem; }
|
||||
.studio-element-library summary { font-size: .9rem; font-weight: 650; cursor: pointer; }
|
||||
.studio-element-library [role="group"] { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .35rem; margin-top: .55rem; }
|
||||
.studio-element-library button {
|
||||
min-height: 2.35rem; padding: .2rem; border: 1px solid var(--line);
|
||||
border-radius: .4rem; color: var(--ink); background: var(--white); font-size: .8rem; cursor: pointer;
|
||||
}
|
||||
.studio-element-library .field-note { margin: .45rem 0 0; font-size: .78rem; }
|
||||
.studio-element-align { display: flex; gap: .05rem; padding-inline-end: .2rem; border-inline-end: 1px solid #ffffff55; }
|
||||
.studio-element-align button { padding-inline: .38rem; }
|
||||
.studio-element-align button[aria-pressed="true"] { background: white; color: #244bc8; }
|
||||
|
||||
@@ -647,3 +647,58 @@ progress { width: 100%; height: .8rem; accent-color: var(--accent); }
|
||||
.article-tabs button { padding: .38rem .8rem; background: white; border: 1px solid var(--line); border-radius: .45rem; color: inherit; cursor: pointer; }
|
||||
.article-tabs button[aria-selected="true"] { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }
|
||||
.network-list .network-detail { min-height: 0; padding-block: .2rem; font-size: .85rem; }
|
||||
|
||||
.article-feed-archive { margin: 1rem 0 0; }
|
||||
.studio-notice { padding: clamp(1rem, 3vw, 1.8rem); border-inline-start: 3px solid var(--accent); border-radius: .55rem; background: var(--accent-light); }
|
||||
.studio-notice p, .studio-testimonials p:last-child, .studio-timeline li p:last-child { margin-bottom: 0; }
|
||||
.studio-gallery, .studio-metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
|
||||
.studio-gallery img { width: 100%; aspect-ratio: 4 / 3; object-fit: contain; border: 1px solid var(--line); background: var(--paper); }
|
||||
.studio-split video { width: 100%; aspect-ratio: 16 / 9; border-radius: .6rem; background: var(--navy); object-fit: contain; }
|
||||
.studio-metrics { margin-block: 0 1rem; }
|
||||
.studio-metrics div { padding: 1rem; border-block-start: 1px solid var(--line); }
|
||||
.studio-metrics dd { margin: .4rem 0 0; color: var(--accent); font-size: clamp(1.65rem, 5vw, 3rem); font-weight: 700; }
|
||||
.studio-testimonials blockquote { margin: 0; padding: 1.1rem 1.3rem; border: 1px solid var(--line); border-radius: .6rem; }
|
||||
.studio-testimonials .studio-attribution { font-size: .88rem; color: var(--muted); }
|
||||
.rich .studio-timeline { padding-inline-start: 1.4rem; border-inline-start: 1px solid var(--line); }
|
||||
.studio-timeline li + li, .studio-checklist li + li { margin-top: .7rem; }
|
||||
.studio-timeline li::marker, .studio-checklist li::marker { color: var(--accent); font-weight: 700; }
|
||||
.studio-timeline h3 { font-size: 1.15rem; margin-bottom: .2rem; }
|
||||
.rich .studio-resources { list-style: none; padding: 0; border-block-start: 1px solid var(--line); }
|
||||
.studio-resources li { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .35rem 1rem; padding: .7rem 0; border-block-end: 1px solid var(--line); }
|
||||
.studio-resources span { font-size: .875rem; color: var(--muted); }
|
||||
.studio-divider { width: 100%; margin-block: 1.25rem; border: 0; border-block-start: 1px solid var(--line); }
|
||||
.studio-code { max-width: 100%; overflow: auto; padding: .8rem 1rem; border: 1px solid var(--line); border-radius: .5rem; background: var(--paper); }
|
||||
@media (max-width: 36rem) {
|
||||
.studio-gallery { grid-template-columns: 1fr; }
|
||||
.studio-metrics { gap: .45rem; }
|
||||
.studio-metrics div { padding: .55rem .3rem; }
|
||||
}
|
||||
|
||||
.studio-align-left {
|
||||
--studio-margin-left: 0; --studio-margin-right: auto; --studio-justify: start;
|
||||
text-align: left; justify-self: start;
|
||||
}
|
||||
.studio-align-center {
|
||||
--studio-margin-left: auto; --studio-margin-right: auto; --studio-justify: center;
|
||||
text-align: center; justify-self: center;
|
||||
}
|
||||
.studio-align-right {
|
||||
--studio-margin-left: auto; --studio-margin-right: 0; --studio-justify: end;
|
||||
text-align: right; justify-self: end;
|
||||
}
|
||||
:is(.hero-lead, .section-heading > p, .rich > p)[class*="studio-align-"] {
|
||||
margin-left: var(--studio-margin-left);
|
||||
margin-right: var(--studio-margin-right);
|
||||
}
|
||||
.rich > p:is(.studio-align-left, .studio-align-center, .studio-align-right) { max-width: 47rem; }
|
||||
:is(.rich, .editor-preview) :is(img, video, audio, a, ol, ul)[class*="studio-align-"] {
|
||||
margin-left: var(--studio-margin-left);
|
||||
margin-right: var(--studio-margin-right);
|
||||
}
|
||||
:is(.rich, .editor-preview) :is(img, video, audio)[class*="studio-align-"] { display: block; max-width: 100%; }
|
||||
:is(.rich, .editor-preview) a[class*="studio-align-"] { display: flex; width: fit-content; max-width: 100%; }
|
||||
:is(.rich, .editor-preview) :is(ol, ul)[class*="studio-align-"] { width: fit-content; max-width: 100%; }
|
||||
.rich > img[class*="studio-align-"]:not([class*="studio-media-"]) { max-width: min(100%, 46rem); }
|
||||
.rich table[class*="studio-align-"] :is(th, td) { text-align: inherit; }
|
||||
.hero-visual[class*="studio-align-"] { justify-self: var(--studio-justify); }
|
||||
.hero-actions[class*="studio-align-"] { justify-content: var(--studio-justify); }
|
||||
|
||||
@@ -265,7 +265,11 @@ jQuery(function ($) {
|
||||
const $settings = $layout.find('.studio-inspector');
|
||||
const $sizing = $studio.find('[data-media-sizing]');
|
||||
const $elementTools = $studio.find('[data-element-tools]');
|
||||
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 bodyElements = 'a, article, blockquote, details, div, dl, dt, dd, figure, h1, h2, h3, h4, h5, h6, hr, li, ol, p, pre, 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]');
|
||||
@@ -328,7 +332,14 @@ jQuery(function ($) {
|
||||
function sectionChanges(withEdits = true) {
|
||||
return sections.flatMap(({key, version, fields, source, template}) => {
|
||||
const changes = {};
|
||||
for (const [field, {node, initial}] of Object.entries(fields)) {
|
||||
const aligned = {};
|
||||
let alignmentChanged = false;
|
||||
for (const [field, {node, initial, initialAlignment}] of Object.entries(fields)) {
|
||||
if (field !== 'body') {
|
||||
const value = getAlignment(node);
|
||||
if (value) aligned[field] = value;
|
||||
if (value !== initialAlignment) alignmentChanged = true;
|
||||
}
|
||||
let value = field === 'body' ? node.innerHTML : node.textContent;
|
||||
if (field === 'body' && node.contains(selectedElement)) {
|
||||
const copy = node.cloneNode(true);
|
||||
@@ -339,7 +350,8 @@ jQuery(function ($) {
|
||||
changes[field] = withEdits && field === 'body' && version !== null ? bodyEdits(source, value) : value;
|
||||
}
|
||||
}
|
||||
return Object.keys(changes).length ? [{key, version, fields: changes, ...(template ? {template} : {})}] : [];
|
||||
if (!Object.keys(changes).length && !alignmentChanged) return [];
|
||||
return [{key, version, fields: changes, ...(alignmentChanged ? {alignments: aligned} : {}), ...(template ? {template} : {})}];
|
||||
});
|
||||
}
|
||||
|
||||
@@ -616,7 +628,7 @@ jQuery(function ($) {
|
||||
} else {
|
||||
configureText(node, label, part === 'lead');
|
||||
}
|
||||
fields[part] = {node, initial: body ? node.innerHTML : node.textContent};
|
||||
fields[part] = {node, initial: body ? node.innerHTML : node.textContent, initialAlignment: body ? '' : getAlignment(node)};
|
||||
}
|
||||
const source = new TextDecoder('utf-8', {ignoreBOM: true}).decode(Uint8Array.from(
|
||||
atob(section.dataset.studioSource || ''), (byte) => byte.charCodeAt(0)
|
||||
@@ -662,11 +674,12 @@ jQuery(function ($) {
|
||||
const node = sizingTarget();
|
||||
if (node) {
|
||||
const bounds = previewBounds(node);
|
||||
const x = getAlignment(node) === 'right' ? bounds.left : bounds.right;
|
||||
const y = (bounds.top + bounds.bottom) / 2;
|
||||
const visible = bounds.width > 0 && y >= 0 && y <= container.clientHeight
|
||||
&& bounds.right > 0 && bounds.right <= container.clientWidth + 1;
|
||||
&& x >= 0 && x <= container.clientWidth + 1;
|
||||
$handle.prop('hidden', !mediaDrag && !visible);
|
||||
$handle.css({left: Math.min(bounds.right, container.clientWidth - 11), top: y});
|
||||
$handle.css({left: Math.max(11, Math.min(x, container.clientWidth - 11)), top: y});
|
||||
} else {
|
||||
$handle.prop('hidden', true);
|
||||
}
|
||||
@@ -706,6 +719,24 @@ jQuery(function ($) {
|
||||
return element !== body && body.contains(element) ? element : null;
|
||||
}
|
||||
|
||||
function getAlignment(node) {
|
||||
return alignments.find((value) => node.classList.contains('studio-align-' + value)) || '';
|
||||
}
|
||||
|
||||
function alignmentTarget(node) {
|
||||
if (!node) return null;
|
||||
const hero = node.closest('[data-studio-align-field]');
|
||||
if (hero) return hero;
|
||||
return node.matches('[data-studio-part="title"], [data-studio-part="lead"]') || node.closest('[data-studio-part="body"]')
|
||||
? node : null;
|
||||
}
|
||||
|
||||
function syncAlignmentButtons(target) {
|
||||
$alignTools.prop('hidden', !target).find('[data-align]').each(function () {
|
||||
$(this).attr('aria-pressed', String(Boolean(target) && getAlignment(target) === this.dataset.align));
|
||||
});
|
||||
}
|
||||
|
||||
function selectElement(node) {
|
||||
selectionObserver?.disconnect();
|
||||
selectedElement?.removeAttribute('data-studio-selected');
|
||||
@@ -719,10 +750,13 @@ jQuery(function ($) {
|
||||
const inBody = node.closest('[data-studio-part="body"]') !== null;
|
||||
const canCopy = inBody || (nav && $(node).siblings().length < 19);
|
||||
const hasProperties = selectedMedia || node.matches('a');
|
||||
const aligned = alignmentTarget(node);
|
||||
syncAlignmentButtons(aligned);
|
||||
$elementTools.find('[data-element-copy]').prop('hidden', !canCopy);
|
||||
$elementTools.find('[data-element-delete]').prop('hidden', !inBody && !selectedMedia && !node.matches(heroOrOptional));
|
||||
$elementTools.find('[data-element-properties]').prop('hidden', !hasProperties);
|
||||
if (target) showMediaWidth(currentMediaWidth(target));
|
||||
selectionObserver?.observe(target || node);
|
||||
selectionObserver?.observe(target || aligned || node);
|
||||
}
|
||||
positionSelection();
|
||||
}
|
||||
@@ -760,7 +794,22 @@ jQuery(function ($) {
|
||||
}
|
||||
}
|
||||
|
||||
$elementTools.on('click', '[data-element-copy]', () => changeElement(true))
|
||||
$elementTools.on('click', '[data-align]', function () {
|
||||
const target = alignmentTarget(selectedElement);
|
||||
const alignment = this.dataset.align;
|
||||
if (!target || !alignments.includes(alignment)) return;
|
||||
target.classList.remove(...alignmentClasses);
|
||||
target.classList.add('studio-align-' + alignment);
|
||||
const field = target.dataset.studioAlignField;
|
||||
if (field) {
|
||||
const $value = pageInput('alignments');
|
||||
const values = {...JSON.parse($value.val())};
|
||||
values[field] = alignment;
|
||||
$value.val(JSON.stringify(values));
|
||||
}
|
||||
syncAlignmentButtons(target);
|
||||
positionSelection();
|
||||
}).on('click', '[data-element-copy]', () => changeElement(true))
|
||||
.on('click', '[data-element-delete]', () => changeElement(false))
|
||||
.on('click', '[data-element-properties]', () => {
|
||||
if (selectedMedia) replaceMedia();
|
||||
@@ -790,9 +839,10 @@ jQuery(function ($) {
|
||||
const narrow = node.getBoundingClientRect();
|
||||
if (classes === null) node.removeAttribute('class');
|
||||
else node.setAttribute('class', classes);
|
||||
const rightEdgeTravel = (full.right - narrow.right) / .9;
|
||||
const available = rightEdgeTravel > full.width * .15 ? rightEdgeTravel : full.width;
|
||||
return {available, initialWidth: width || Math.round(100 * natural / (full.width || natural || 1))};
|
||||
const fromLeft = getAlignment(node) === 'right';
|
||||
const edgeTravel = (fromLeft ? narrow.left - full.left : full.right - narrow.right) / .9;
|
||||
const available = edgeTravel > full.width * .15 ? edgeTravel : full.width;
|
||||
return {available, fromLeft, initialWidth: width || Math.round(100 * natural / (full.width || natural || 1))};
|
||||
}
|
||||
|
||||
function resizeMedia(width) {
|
||||
@@ -817,7 +867,8 @@ jQuery(function ($) {
|
||||
if (!mediaDrag || mediaDrag.id !== pointer.pointerId || !mediaDrag.available) return;
|
||||
if (pointer.clientX !== mediaDrag.x || mediaDrag.moved) {
|
||||
mediaDrag.moved = true;
|
||||
resizeMedia(mediaDrag.initialWidth + 100 * (pointer.clientX - mediaDrag.x) / (mediaDrag.available * mediaDrag.scale));
|
||||
const distance = (pointer.clientX - mediaDrag.x) * (mediaDrag.fromLeft ? -1 : 1);
|
||||
resizeMedia(mediaDrag.initialWidth + 100 * distance / (mediaDrag.available * mediaDrag.scale));
|
||||
}
|
||||
}).on('lostpointercapture', () => {
|
||||
mediaDrag = null;
|
||||
@@ -836,7 +887,44 @@ jQuery(function ($) {
|
||||
$layout.on('click', '[data-hero-control]', function () {
|
||||
heroControls.get(this.dataset.heroControl)?.();
|
||||
});
|
||||
$presets.on('mousedown', '[data-canvas-template]', (event) => event.preventDefault());
|
||||
function insertInBody(markup, body, range) {
|
||||
if (!body.isConnected) return;
|
||||
const insertion = doc.createRange();
|
||||
// Insert between blocks so the browser doesn't split a paragraph or duplicate its ID.
|
||||
let node = range?.endContainer;
|
||||
if (!node || !body.contains(node)) {
|
||||
insertion.selectNodeContents(body);
|
||||
insertion.collapse(false);
|
||||
} else if (node === body) {
|
||||
insertion.setStart(body, range.endOffset);
|
||||
} else {
|
||||
while (node.parentNode !== body) node = node.parentNode;
|
||||
insertion.setStartAfter(node);
|
||||
}
|
||||
editBody(body, insertion, 'insertHTML', markup);
|
||||
}
|
||||
|
||||
$presets.on('mousedown', '[data-canvas-template], [data-canvas-element]', (event) => event.preventDefault());
|
||||
$presets.on('click', '[data-canvas-element]', function () {
|
||||
const $status = $presets.find('[data-element-status]');
|
||||
const body = activeBody;
|
||||
const range = savedRange?.cloneRange();
|
||||
if (!body) {
|
||||
$status.text('请先在画布中选中要插入的正文。');
|
||||
return;
|
||||
}
|
||||
const add = (markup) => {
|
||||
if (!markup) return;
|
||||
insertInBody(markup, body, range);
|
||||
selectElement(null);
|
||||
$status.text('已插入' + $(this).text() + '。');
|
||||
};
|
||||
if (this.dataset.elementMime) {
|
||||
openPicker(this.dataset.elementMime, (file) => add(mediaMarkup(file)));
|
||||
} else {
|
||||
add($presets.find('template[data-element="' + this.dataset.canvasElement + '"]').get(0).innerHTML);
|
||||
}
|
||||
});
|
||||
$presets.on('click', '[data-canvas-template]', function () {
|
||||
const markup = $presets.find('template[data-preset="' + this.dataset.canvasTemplate + '"]').get(0).innerHTML;
|
||||
const template = this.dataset.canvasTemplate;
|
||||
@@ -849,10 +937,8 @@ jQuery(function ($) {
|
||||
$templateStatus.text('先在画布中选择要插入的区块正文。');
|
||||
return;
|
||||
}
|
||||
// Insert at the saved caret without replacing any selected text.
|
||||
const insertion = savedRange?.cloneRange();
|
||||
insertion?.collapse(false);
|
||||
editBody(activeBody, insertion, 'insertHTML', markup);
|
||||
insertInBody(markup, activeBody, savedRange);
|
||||
selectElement(null);
|
||||
$templateStatus.text('已插入当前正文。');
|
||||
return;
|
||||
}
|
||||
@@ -920,8 +1006,8 @@ jQuery(function ($) {
|
||||
});
|
||||
$doc.on('click.canvas', (event) => {
|
||||
const node = event.target;
|
||||
const optional = node.closest?.(heroOrOptional);
|
||||
selectElement(doc.getSelection()?.isCollapsed ? optional || editableBodyElement(node) : null);
|
||||
const field = node.closest?.(canvasFields);
|
||||
selectElement(doc.getSelection()?.isCollapsed ? field || editableBodyElement(node) : null);
|
||||
});
|
||||
$doc.on('dblclick.canvas', '[data-studio-part="body"] a', function (event) {
|
||||
event.preventDefault();
|
||||
@@ -950,7 +1036,7 @@ jQuery(function ($) {
|
||||
});
|
||||
$toolbar.prop('hidden', false);
|
||||
$layout.find('[data-canvas-jump]').prop('hidden', false);
|
||||
$layout.find('[data-canvas-template], [data-hero-control]').prop('disabled', false);
|
||||
$layout.find('[data-canvas-template], [data-canvas-element], [data-hero-control]').prop('disabled', false);
|
||||
$presets.triggerHandler('studio:canvas-ready');
|
||||
}
|
||||
|
||||
|
||||
|
After Width: | Height: | Size: 4.1 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 5.8 KiB |
|
After Width: | Height: | Size: 5.2 KiB |
|
After Width: | Height: | Size: 5.2 KiB |
|
After Width: | Height: | Size: 6.4 KiB |
|
After Width: | Height: | Size: 6.0 KiB |
|
After Width: | Height: | Size: 11 KiB |
@@ -13,6 +13,7 @@ CREATE TABLE IF NOT EXISTS pages (
|
||||
image TEXT NOT NULL,
|
||||
alt TEXT NOT NULL,
|
||||
image_scale INTEGER NOT NULL DEFAULT 0,
|
||||
alignments TEXT NOT NULL DEFAULT '{}',
|
||||
actions TEXT NOT NULL,
|
||||
quicklinks TEXT NOT NULL,
|
||||
status TEXT NOT NULL DEFAULT 'published' CHECK (status IN ('draft', 'published')),
|
||||
@@ -26,6 +27,7 @@ CREATE TABLE IF NOT EXISTS sections (
|
||||
lead TEXT NOT NULL,
|
||||
style TEXT NOT NULL DEFAULT 'plain',
|
||||
feed TEXT,
|
||||
alignments TEXT NOT NULL DEFAULT '{}',
|
||||
body TEXT NOT NULL,
|
||||
position INTEGER NOT NULL,
|
||||
version INTEGER NOT NULL DEFAULT 0,
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
"title": "来笙动态",
|
||||
"lead": "",
|
||||
"style": "plain",
|
||||
"body": "<p><a class=\"back-link\" href=\"/articles\">查看全部动态</a></p>",
|
||||
"body": "",
|
||||
"feed": {
|
||||
"categories": [
|
||||
"announcement",
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use App\Content\Database;
|
||||
|
||||
// 输出目录类文章:slug<TAB>卡片网址<TAB>是否已发布
|
||||
$pdo = Database::connect();
|
||||
$query = $pdo->query("SELECT a.slug, a.card, a.status FROM articles a
|
||||
WHERE EXISTS (SELECT 1 FROM article_category_links l WHERE l.article_id = a.id
|
||||
AND l.category_slug IN ('services', 'supported-projects', 'partners'))
|
||||
ORDER BY a.id");
|
||||
foreach ($query as $row) {
|
||||
$card = json_decode($row['card'], true) ?: [];
|
||||
echo $row['slug'], '|', $card['url'] ?? '', '|', $row['status'], "\n";
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
#!/usr/bin/env bash
|
||||
# 目录页(/services、/network)的卡片链接必须指向卡片配置的网址,而不是 /articles/<slug>
|
||||
set -u
|
||||
cd "$(dirname "$0")/.." || exit 1
|
||||
BASE=http://127.0.0.1:8787
|
||||
PASS=0; FAIL=0
|
||||
ok(){ PASS=$((PASS+1)); printf ' ok %s\n' "$1"; }
|
||||
no(){ FAIL=$((FAIL+1)); printf ' FAIL %s -> %s\n' "$1" "${2:-}"; }
|
||||
|
||||
SERVICES=$(curl -s "$BASE/services")
|
||||
NETWORK=$(curl -s "$BASE/network")
|
||||
ROWS=$(php tests/dircheck.php)
|
||||
|
||||
echo "== /services 卡片链接 =="
|
||||
while IFS='|' read -r slug url status; do
|
||||
[ -z "$slug" ] && continue
|
||||
[ -z "$url" ] && continue
|
||||
if echo "$SERVICES" | grep -q "href=\"$url\""; then ok "$slug 标题/按钮指向 $url"; else no "$slug 未指向 $url"; fi
|
||||
if echo "$SERVICES" | grep -q "href=\"/articles/$slug\""; then no "$slug 仍出现 /articles/$slug"; else ok "$slug 不再指向文章页"; fi
|
||||
done <<< "$(echo "$ROWS" | grep -E '^service-')"
|
||||
|
||||
echo "== /network 卡片链接 =="
|
||||
while IFS='|' read -r slug url status; do
|
||||
[ -z "$slug" ] && continue
|
||||
[ -z "$url" ] && continue
|
||||
if echo "$NETWORK" | grep -q "href=\"$url\""; then ok "$slug 指向 $url"; else no "$slug 未指向 $url"; fi
|
||||
if echo "$NETWORK" | grep -q "href=\"/articles/$slug\""; then no "$slug 仍出现 /articles/$slug"; else ok "$slug 不再指向文章页"; fi
|
||||
done <<< "$(echo "$ROWS" | grep -E '^network-')"
|
||||
|
||||
echo "== 标题链接与按钮链接一致性 =="
|
||||
python3 - "$BASE" <<'PY'
|
||||
import re, sys, html, urllib.request
|
||||
base = sys.argv[1]
|
||||
def get(path):
|
||||
return urllib.request.urlopen(base + path, timeout=10).read().decode()
|
||||
page = get('/services')
|
||||
cards = re.findall(r'<article class="catalog-card">.*?</article>', page, re.S)
|
||||
bad = 0
|
||||
for card in cards:
|
||||
links = re.findall(r'<a[^>]*href="([^"]+)"', card)
|
||||
title = re.search(r'<h2><a href="([^"]+)"', card)
|
||||
if not title:
|
||||
print(' FAIL 卡片缺标题链接'); bad += 1; continue
|
||||
primary = [l for l in links if not l.startswith('/articles/')]
|
||||
if primary and title.group(1) != primary[0]:
|
||||
print(' FAIL 标题 href=%s 与主按钮 href=%s 不一致' % (title.group(1), primary[0])); bad += 1
|
||||
print(' ok %d 张卡片标题与主按钮一致' % (len(cards) - bad) if bad == 0 else ' 共 %d 张卡片,%d 张不一致' % (len(cards), bad))
|
||||
sys.exit(0 if bad == 0 else 1)
|
||||
PY
|
||||
[ $? -eq 0 ] && ok "标题与按钮目标一致" || no "标题与主按钮目标不一致"
|
||||
|
||||
echo "== 参考信息:目录条目在文章流中的可见性(不判定) =="
|
||||
PUB=$(echo "$ROWS" | awk -F'|' '$3 == "published" {print $1}')
|
||||
N=0
|
||||
for slug in $PUB; do
|
||||
if curl -s "$BASE/articles" | grep -q "href=\"/articles/$slug\""; then N=$((N+1)); fi
|
||||
done
|
||||
echo " /articles 列表中出现的目录条目: $N / $(echo "$PUB" | wc -l)"
|
||||
M=0
|
||||
for slug in $PUB; do
|
||||
if curl -s "$BASE/sitemap.xml" | grep -q "/articles/$slug"; then M=$((M+1)); fi
|
||||
done
|
||||
echo " sitemap 中的目录条目: $M / $(echo "$PUB" | wc -l)"
|
||||
|
||||
echo ""
|
||||
echo "== 结果: $PASS 通过, $FAIL 失败 =="
|
||||
[ $FAIL -eq 0 ] || exit 1
|
||||
@@ -54,6 +54,8 @@ async function run(browser) {
|
||||
const frame = page.frameLocator('iframe[title="可编辑页面画布"]');
|
||||
const sizing = page.locator('[data-media-sizing]');
|
||||
const properties = page.locator('[data-canvas-properties]');
|
||||
const tools = page.getByRole('group', {name: '所选元素'});
|
||||
const align = (label) => tools.getByRole('button', {name: label, exact: true}).click();
|
||||
const closeProperties = () => properties.locator('[data-property-close]').click();
|
||||
|
||||
const image = frame.locator('#fixtures img');
|
||||
@@ -77,6 +79,18 @@ async function run(browser) {
|
||||
await properties.locator('[name=url]').fill('/assets/original/home-hero.webp');
|
||||
await properties.locator('button[type=submit]').click();
|
||||
assert.equal(await image.getAttribute('src'), '/assets/original/home-hero.webp');
|
||||
await image.click();
|
||||
await align('居右');
|
||||
const rightEdge = await image.boundingBox();
|
||||
const leftHandle = await handle.boundingBox();
|
||||
assert(Math.abs(rightEdge.x - (leftHandle.x + leftHandle.width / 2)) < 2);
|
||||
await align('居中');
|
||||
const centeredImage = await image.evaluate((node) => {
|
||||
const bounds = node.getBoundingClientRect();
|
||||
const parent = node.parentElement.getBoundingClientRect();
|
||||
return Math.abs((bounds.left + bounds.right) / 2 - (parent.left + parent.right) / 2) < 2;
|
||||
});
|
||||
assert(centeredImage);
|
||||
|
||||
const hero = frame.locator('[data-studio-hero-image]');
|
||||
await page.locator('iframe[title="可编辑页面画布"]').evaluate((iframe) => iframe.contentWindow.scrollTo(0, 0));
|
||||
@@ -88,8 +102,11 @@ async function run(browser) {
|
||||
await sizing.locator('[data-replace-media]').click();
|
||||
assert.equal(await properties.locator('h2').textContent(), '首屏图片');
|
||||
await closeProperties();
|
||||
const heroTitle = frame.locator('[data-studio-field=heading]');
|
||||
await heroTitle.click();
|
||||
await align('居右');
|
||||
assert.equal(await heroTitle.evaluate((node) => getComputedStyle(node.parentElement).textAlign), 'right');
|
||||
|
||||
const tools = page.getByRole('group', {name: '所选元素'});
|
||||
await frame.locator('#fixtures a').click();
|
||||
await tools.getByRole('button', {name: '属性'}).click();
|
||||
await properties.waitFor({state: 'visible'});
|
||||
@@ -108,6 +125,11 @@ async function run(browser) {
|
||||
|
||||
const copyText = frame.locator('#fixtures').getByText('待复制段落', {exact: true});
|
||||
await copyText.click();
|
||||
await align('居中');
|
||||
await align('居左');
|
||||
assert.equal(await copyText.evaluate((node) => getComputedStyle(node).textAlign), 'left');
|
||||
await align('居右');
|
||||
assert.equal(await copyText.evaluate((node) => getComputedStyle(node).textAlign), 'right');
|
||||
await tools.getByRole('button', {name: '复制'}).click();
|
||||
assert.equal(await copyText.count(), 2);
|
||||
assert.equal(await frame.locator('#copy-fixture').count(), 1);
|
||||
@@ -119,9 +141,19 @@ async function run(browser) {
|
||||
await tools.getByRole('button', {name: '删除'}).click();
|
||||
assert.equal(await page.locator('[name=lead]').inputValue(), '');
|
||||
|
||||
const sectionTitle = frame.locator('#fixtures [data-studio-part=title]');
|
||||
await sectionTitle.click();
|
||||
await align('居中');
|
||||
assert.equal(await sectionTitle.evaluate((node) => getComputedStyle(node).textAlign), 'center');
|
||||
|
||||
const gallery = page.locator('[data-canvas-presets]');
|
||||
assert.equal(await gallery.locator('[data-template-group]').count(), 6);
|
||||
assert.equal(await gallery.locator('[data-template-card]').count(), 14);
|
||||
await copyText.first().click();
|
||||
await gallery.getByText('基础元素', {exact: true}).click();
|
||||
await gallery.getByRole('button', {name: '插入分割线'}).click();
|
||||
await frame.locator('#fixtures .studio-divider').waitFor();
|
||||
await gallery.getByText('基础元素', {exact: true}).click();
|
||||
assert.equal(await gallery.locator('[data-template-group]').count(), 7);
|
||||
assert.equal(await gallery.locator('[data-template-card]').count(), 22);
|
||||
const brokenPreviews = await gallery.locator('[data-template-card] img').evaluateAll(async (images) => {
|
||||
for (const image of images) image.loading = 'eager';
|
||||
await Promise.all(images.map((image) => image.decode()));
|
||||
@@ -149,6 +181,9 @@ async function run(browser) {
|
||||
await gallery.locator('[data-template-empty]').waitFor({state: 'visible'});
|
||||
await search.fill('双栏');
|
||||
assert.equal(await gallery.locator('[data-template-card]:visible').count(), 1);
|
||||
await search.fill('重点提示');
|
||||
await gallery.locator('[data-canvas-template=notice]').click();
|
||||
await frame.locator('.studio-notice').waitFor();
|
||||
await search.fill('分类文章');
|
||||
await gallery.locator('[data-canvas-template=articles]').click();
|
||||
await frame.locator('section[id^=block-] h2').filter({hasText: '分类文章'}).waitFor();
|
||||
@@ -161,7 +196,12 @@ async function run(browser) {
|
||||
await frame.locator('section[id^=block-] .studio-cover').waitFor();
|
||||
assert.equal(await frame.locator('#fixtures a').getAttribute('href'), '/articles');
|
||||
assert.equal(await frame.locator('#fixtures img').getAttribute('src'), '/assets/original/home-hero.webp');
|
||||
assert.equal(await frame.locator('#fixtures img').getAttribute('class'), imageSize);
|
||||
assert.deepEqual((await image.getAttribute('class')).split(/\s+/).sort(), [imageSize, 'studio-align-center'].sort());
|
||||
assert.equal(await heroTitle.evaluate((node) => getComputedStyle(node.parentElement).textAlign), 'right');
|
||||
assert.equal(await sectionTitle.evaluate((node) => getComputedStyle(node).textAlign), 'center');
|
||||
assert.deepEqual(await copyText.evaluateAll((nodes) => nodes.map((node) => getComputedStyle(node).textAlign)), ['right', 'right']);
|
||||
await frame.locator('.studio-notice').waitFor();
|
||||
await frame.locator('#fixtures .studio-divider').waitFor();
|
||||
assert.match(await frame.locator('[data-visual]').getAttribute('class'), /studio-media-99/);
|
||||
assert.equal(await copyText.count(), 2);
|
||||
assert.equal(await frame.locator('#copy-fixture').count(), 1);
|
||||
@@ -190,7 +230,7 @@ async function run(browser) {
|
||||
}
|
||||
|
||||
async function verifyArticleLibrary(browser, context, page, post, slug, feedId) {
|
||||
const category = slug + '-category';
|
||||
const category = String(Date.now());
|
||||
await post('/admin/article-categories', {slug: category, name: '自定义测试分类'});
|
||||
const articleSlug = slug + '-article';
|
||||
await page.goto('/admin/articles/new');
|
||||
@@ -202,6 +242,7 @@ async function verifyArticleLibrary(browser, context, page, post, slug, feedId)
|
||||
await page.locator('[name=title]').fill('测试 Markdown 和富文本');
|
||||
await page.locator('[name=slug]').fill(articleSlug);
|
||||
await page.locator('[name="categories[]"][value="' + category + '"]').check();
|
||||
await page.locator('[name="categories[]"][value=product]').check();
|
||||
await page.locator('[name=status]').selectOption('published');
|
||||
await markdown.fill('**Markdown 分屏**');
|
||||
await preview.locator('strong').getByText('Markdown 分屏').waitFor();
|
||||
@@ -211,7 +252,7 @@ async function verifyArticleLibrary(browser, context, page, post, slug, feedId)
|
||||
const publishedPath = '/articles/' + articleSlug;
|
||||
const sourcePage = await context.newPage();
|
||||
await sourcePage.goto(publishedPath);
|
||||
assert.equal(await sourcePage.locator('[itemprop=articleSection]').count(), 2);
|
||||
assert.equal(await sourcePage.locator('[itemprop=articleSection]').count(), 3);
|
||||
await sourcePage.locator('[itemprop=articleBody] strong').getByText('Markdown 分屏').waitFor();
|
||||
await page.goto(articleAdmin);
|
||||
await editor.locator('.toastui-editor-mode-switch').getByText('所见即所得', {exact: true}).click();
|
||||
@@ -241,6 +282,7 @@ async function verifyArticleLibrary(browser, context, page, post, slug, feedId)
|
||||
await page.locator('[name="feed_categories[]"][value="' + category + '"]').check();
|
||||
await page.getByRole('button', {name: '保存区块'}).click();
|
||||
await page.locator('[data-save-confirmation]').waitFor({state: 'visible'});
|
||||
assert(await page.locator('[name="feed_categories[]"][value="' + category + '"]').isChecked());
|
||||
let contentVersion = await page.locator('[name=version]').inputValue();
|
||||
assert.equal(contentVersion, '1');
|
||||
const canvasPath = '/admin/pages/' + slug + '/preview';
|
||||
@@ -268,6 +310,7 @@ async function verifyArticleLibrary(browser, context, page, post, slug, feedId)
|
||||
assert.equal(await noJSPage.locator('#' + feedId + ' a[href="' + publishedPath + '"]:visible').count(), 2);
|
||||
await noJS.close();
|
||||
assert((await context.request.get('/articles/category/' + category)).ok());
|
||||
await verifyScopedArchive(context, page, sourcePage, post, slug, feedId, category, publishedPath);
|
||||
await sourcePage.goto('/services');
|
||||
await sourcePage.locator('.catalog-card').first().waitFor();
|
||||
await sourcePage.goto('/network');
|
||||
@@ -275,11 +318,61 @@ async function verifyArticleLibrary(browser, context, page, post, slug, feedId)
|
||||
await sourcePage.close();
|
||||
}
|
||||
|
||||
async function verifyScopedArchive(context, admin, page, post, slug, feedId, category, articlePath) {
|
||||
const scope = '/articles/feed/' + slug + '/' + feedId;
|
||||
const scopedResponse = (query = '') => context.request.get(scope + query);
|
||||
assert.equal((await scopedResponse()).status(), 404);
|
||||
await admin.goto('/admin/pages/' + slug);
|
||||
await admin.locator('[name=description]').fill('公开文章区块筛选测试。');
|
||||
await admin.locator('[name=status]').selectOption('published');
|
||||
await admin.getByRole('button', {name: '保存页面', exact: true}).first().click();
|
||||
await admin.locator('[data-save-confirmation]').waitFor({state: 'visible'});
|
||||
|
||||
const excluded = await post('/admin/articles/new', {
|
||||
title: '分类范围外测试文章', slug: slug + '-excluded', body_format: 'markdown',
|
||||
body: '只属于公告分类。', status: 'published', 'categories[]': 'announcement',
|
||||
});
|
||||
assert(excluded.redirect);
|
||||
await page.goto('/' + slug);
|
||||
const archiveLink = page.locator('#' + feedId).getByRole('link', {name: '查看全部动态'});
|
||||
assert.equal(await archiveLink.getAttribute('href'), scope);
|
||||
await archiveLink.click();
|
||||
await page.waitForURL('**' + scope);
|
||||
const list = page.locator('main .article-list');
|
||||
assert.equal(await list.locator('a[href="' + articlePath + '"]').count(), 1);
|
||||
assert.equal(await list.locator('a[href="/articles/' + slug + '-excluded"]').count(), 0);
|
||||
assert.doesNotMatch(await list.locator('a[href="' + articlePath + '"] .article-category').textContent(), /产品/);
|
||||
const filters = page.getByRole('navigation', {name: '动态分类'});
|
||||
assert.deepEqual(await filters.getByRole('link').allTextContents(), ['全部', '新闻', '自定义测试分类']);
|
||||
assert.equal((await scopedResponse('?category=announcement')).status(), 404);
|
||||
assert.equal((await scopedResponse('?category[]=news')).status(), 404);
|
||||
assert.equal((await scopedResponse('?categories=announcement')).status(), 200);
|
||||
assert.doesNotMatch(await (await scopedResponse('?categories=announcement')).text(), /分类范围外测试文章/);
|
||||
|
||||
for (let index = 0; index < 21; index++) {
|
||||
await post('/admin/articles/new', {
|
||||
title: '分类分页样例 ' + index, slug: slug + '-sample-' + index, body_format: 'markdown',
|
||||
body: '所选分类中的分页样例。', status: 'published', 'categories[]': category,
|
||||
});
|
||||
}
|
||||
const categoryPath = scope + '?category=' + category;
|
||||
await filters.getByRole('link', {name: '自定义测试分类'}).click();
|
||||
await page.waitForURL('**' + categoryPath);
|
||||
const next = page.getByRole('link', {name: '下一页'});
|
||||
assert.equal(await next.getAttribute('href'), categoryPath + '&page=2');
|
||||
await next.click();
|
||||
await page.waitForURL('**' + categoryPath + '&page=2');
|
||||
assert.equal(await list.locator('a').count(), 2);
|
||||
assert.equal(await page.getByRole('link', {name: '上一页'}).getAttribute('href'), categoryPath);
|
||||
assert.equal(await filters.getByRole('link', {name: '全部'}).getAttribute('href'), scope);
|
||||
assert.equal(await page.getByRole('link', {name: '返回原页面'}).getAttribute('href'), '/' + slug + '#' + feedId);
|
||||
}
|
||||
|
||||
(async () => {
|
||||
const browser = await chromium.launch({executablePath: process.env.CHROMIUM_EXECUTABLE || undefined});
|
||||
try {
|
||||
await run(browser);
|
||||
console.log('Passed Chromium canvas media/link interactions, template gallery, persistence, and the article library.');
|
||||
console.log('Passed Chromium canvas alignment, editor elements and modules, persistence, and scoped article archives.');
|
||||
} finally {
|
||||
await browser.close();
|
||||
}
|
||||
|
||||