Author SHA1 Message Date
ChatGPT abccb8c004 Restore the original Laysense footer 2026-11-21 23:49:21 +08:00
DeepSeek 2ef38bd716 Merge pull request #8: 修复 /network 指向空白文章的死链,统一目录兜底规则
目录卡片:有网址用网址,无网址且有内容才回退文章页,否则不渲染链接。21 项断言 + 三套端到端回归通过。
2026-11-21 23:26:34 +08:00
DeepSeek 62c10b09bc Skip links to empty directory articles 2026-11-21 23:26:15 +08:00
DeepSeek 935bc7f071 Skip links to empty directory articles 2026-11-21 23:26:14 +08:00
DeepSeek 1a025353b2 Merge pull request #7: 修复产品目录卡片标题指向文章页
标题与主按钮统一使用卡片配置的网址,未配置时回退文章页。21 项链接断言通过。
2026-11-21 23:23:56 +08:00
DeepSeek ef1ff93904 Point product cards at their configured URL
The services directory built each card title from the backing article, so
/services linked to /articles/service-1..4 instead of the product pages the
card already carries (PAGEPAN, HighSpeaker, /sc, /shnu-sc). Only the primary
button used card.url, which made the title and the button disagree.

Use the card URL for both, keeping the article page as fallback for entries
without a configured URL, and add a dependency-free regression test.
2026-11-21 23:23:23 +08:00
DeepSeek 74e0de84a6 Merge pull request #6: 限制文章区块归档范围,扩展编辑组件与对齐工具
审计通过(405 项断言 + 浏览器实测对齐链路),合并。合并后需对现有 LAYSENSE_DB 运行 php bin/install.php 补 alignments 列并重启 Webman。
2026-11-21 23:16:53 +08:00
ChatGPT 9bc0ee0e45 Scope article feeds and expand canvas editing 2026-11-21 22:55:59 +08:00
DeepSeek a2fc628f08 Merge pull request #5: 画布元素工具条、媒体拖拽和多分类文章
审计通过(47 项专项断言 + 浏览器交互验证 + 旧库拒绝安装验证),合并。破坏式更新按新库部署。
2026-11-21 22:36:28 +08:00
42 changed files with 740 additions and 178 deletions
+4 -4
View File
@@ -27,12 +27,12 @@ php bin/admin.php reset admin@example.com
## 后台编辑 ## 后台编辑
- **页面设计**支持新建草稿、发布和撤回。首屏标题与简介可在桌面或手机画布中直接编辑。区块支持新增、排序、删除、可视化编辑、媒体插入和 HTML 源码。单击画布元素可用浮动工具条复制或删除。选中媒体后,可拖动边缘手柄调整宽度。编辑器左侧可按分类和名称查找模板。悬停或键盘聚焦缩略图可放大,点击可打开预览。 - **页面设计**支持新建草稿、发布和撤回。首屏标题与简介可在桌面或手机画布中直接编辑。区块支持新增、排序、删除、可视化编辑、媒体插入和 HTML 源码。单击画布元素可用浮动工具条复制或删除。选中媒体后,可拖动边缘手柄调整宽度。浮动工具条可将正文元素、区块标题和首屏元素对齐到左侧、中央或右侧。编辑器左侧可插入基础元素,或按分类和名称查找区块模板。悬停或键盘聚焦缩略图可放大,点击可打开预览。
- **媒体库**集中列出项目静态文件及上传文件,支持查找、选取、复制路径、改名和归档。归档资源的已有 URL 保持可访问。上传文件放在 `LAYSENSE_MEDIA_DIR`,由 `/assets/uploads/` 提供。 - **媒体库**集中列出项目静态文件及上传文件,支持查找、选取、复制路径、改名和归档。归档资源的已有 URL 保持可访问。上传文件放在 `LAYSENSE_MEDIA_DIR`,由 `/assets/uploads/` 提供。
- **文章**使用自托管的 TOAST UI Editor 3.2.2(MIT)。Markdown 左侧源码、右侧实时预览,富文本使用所见即所得模式。文章可以加入多个分类,可在「管理分类」创建新分类。 - **文章**使用自托管的 TOAST UI Editor 3.2.2(MIT)。Markdown 左侧源码、右侧实时预览,富文本使用所见即所得模式。文章可以加入多个分类,可在「管理分类」创建新分类。
- **分类文章**支持在任意页面添加,保存区块后在「图层」中编辑分类、展示数量和合并或标签页模式。 - **分类文章**支持在任意页面添加,保存区块后在「图层」中编辑分类、展示数量和合并或标签页模式。「查看全部动态」和翻页只列出该区块所选的分类。
- **产品与服务**(`/services`)和**支持项目与合作伙伴**(`/network`)由文章分类生成。通过文章的目录卡片设置图片、链接和排序,使用草稿状态可从目录撤下。 - **产品与服务**(`/services`)和**支持项目与合作伙伴**(`/network`)由文章分类生成。通过文章的目录卡片设置图片、链接和排序,使用草稿状态可从目录撤下。
- **网站设置**分别编辑页头标志、导航及按钮,和页脚的公司信息、链接与备注。CDN 设置接受 HTTPS 源站地址。浏览器看到的公开 `/assets/…` 路径使用该源站。 - **网站设置**分别编辑页头标志、导航及按钮,和页脚的公司信息、产品、公司及资源链接和备注。页脚设置可恢复原站内容。CDN 设置接受 HTTPS 源站地址。浏览器看到的公开 `/assets/…` 路径使用该源站。
- 文章支持摘要和标签。状态选「草稿」可撤回公开文章。已发布文章改网址标识后,旧标识会自动跳转。 - 文章支持摘要和标签。状态选「草稿」可撤回公开文章。已发布文章改网址标识后,旧标识会自动跳转。
- 首页动态、分类列表和站点地图随发布状态更新。源代码和 SQLite 数据分开管理。安装命令可重复执行,已编辑的内容会保留。 - 首页动态、分类列表和站点地图随发布状态更新。源代码和 SQLite 数据分开管理。安装命令可重复执行,已编辑的内容会保留。
@@ -70,7 +70,7 @@ location = /admin/media {
| `LAYSENSE_SECURE_COOKIES` | 默认关闭 · 本地 HTTP 使用默认值。生产 HTTPS 设置为 `1`。 | | `LAYSENSE_SECURE_COOKIES` | 默认关闭 · 本地 HTTP 使用默认值。生产 HTTPS 设置为 `1`。 |
| `LAYSENSE_TRUSTED_PROXIES` | 默认 `127.0.0.1,::1` · 逗号分隔的受信反代 IP,设为空字符串可关闭信任 | | `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 ### CDN
+22
View File
@@ -8,12 +8,25 @@ final class BlockTemplates
{ {
public const ARTICLE_FEED = '{"categories":["announcement","news","product"],"mode":"merged","limit":6}'; 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 = [ public const GROUPS = [
'content' => ['标题与正文', [ 'content' => ['标题与正文', [
'headline' => ['标题与简介', '<div class="studio-intro"><h3>填写区块标题</h3><p>用一句话补充背景或说明。</p></div>'], 'headline' => ['标题与简介', '<div class="studio-intro"><h3>填写区块标题</h3><p>用一句话补充背景或说明。</p></div>'],
'text' => ['正文', '<p>在这里输入区块内容。</p>'], 'text' => ['正文', '<p>在这里输入区块内容。</p>'],
'articles' => ['分类文章', ''], 'articles' => ['分类文章', ''],
'list' => ['步骤列表', '<ol><li>填写第一步</li><li>填写第二步</li><li>填写第三步</li></ol>'], 'list' => ['步骤列表', '<ol><li>填写第一步</li><li>填写第二步</li><li>填写第三步</li></ol>'],
'notice' => ['重点提示', '<div class="studio-notice"><h3>填写重要提示</h3><p>说明访客需要知悉的事项、条件或时间。</p></div>'],
]], ]],
'cover' => ['封面与横幅', [ '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>'], '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>'], '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>'], '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' => ['特性与口碑', [
'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>'], '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>'], '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' => ['表格与问答', [ '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>'], '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>'], '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' => ['导航与引导', [ '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>'], '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>'], '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>'],
]], ]],
]; ];
+6
View File
@@ -44,6 +44,12 @@ final class Database
throw new RuntimeException('请将 LAYSENSE_DB 指向一个新的 SQLite 文件,再运行安装命令。'); throw new RuntimeException('请将 LAYSENSE_DB 指向一个新的 SQLite 文件,再运行安装命令。');
} }
$pdo->exec(file_get_contents($root . '/resources/schema.sql')); $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 = $pdo->prepare('INSERT OR IGNORE INTO site_settings (id, payload) VALUES (1, ?)');
$site->execute([self::json($seed['site'])]); $site->execute([self::json($seed['site'])]);
+2
View File
@@ -12,6 +12,8 @@ use RuntimeException;
final class Html final class Html
{ {
public const ALIGNMENTS = ['left', 'center', 'right'];
private const TAGS = [ private const TAGS = [
'a' => ['href'], 'article' => [], 'audio' => ['src', 'controls', 'preload'], 'b' => [], 'blockquote' => [], 'br' => [], 'a' => ['href'], 'article' => [], 'audio' => ['src', 'controls', 'preload'], 'b' => [], 'blockquote' => [], 'br' => [],
'caption' => [], 'code' => [], 'dd' => [], 'details' => [], 'div' => ['role', 'aria-label', 'tabindex'], 'caption' => [], 'code' => [], 'dd' => [], 'details' => [], 'div' => ['role', 'aria-label', 'tabindex'],
+15 -8
View File
@@ -52,7 +52,7 @@ final class Repository
if (!$page) { if (!$page) {
return null; 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); $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'); $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]); 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 public function savePage(string $slug, array $data, int $version, array $sections = []): void
{ {
Database::write(function (PDO $pdo) use ($slug, $data, $version, $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 = ?, $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([ $query->execute([
$data['name'], $data['title'], $data['description'], $data['heading'], $data['accent'], $data['lead'], $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, $data['status'], self::now(), $slug, $version,
]); ]);
self::checkVersion($query->rowCount()); 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 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 = ?'); 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()); self::checkVersion($query->rowCount());
} }
@@ -114,9 +121,9 @@ final class Repository
private static function insertSection(PDO $pdo, string $page, string $key, array $data): void 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) $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 = ?'); 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->execute([$page, $key, $data['title'], $data['lead'], $data['style'], $data['body'], $data['feed'] ?? null, $data['alignments'] ?? '{}', $page]);
if ($query->rowCount() !== 1) { if ($query->rowCount() !== 1) {
throw new RuntimeException('此区块锚点已被使用。'); throw new RuntimeException('此区块锚点已被使用。');
} }
+29 -3
View File
@@ -16,14 +16,40 @@ final class SiteDesign
]; ];
public const DEFAULT_FOOTER = [ public const DEFAULT_FOOTER = [
'logo' => '/assets/wordmark.webp', 'alt' => '来笙 Laysense', 'logo' => '/assets/original/footer-wordmark.webp', 'alt' => '来笙 Laysense',
'name' => '上海来笙信息科技有限公司',
'address' => '中国(上海)自由贸易试验区世博村路231号2单元3层328室',
'email' => 'public@laysense.cn',
'products_title' => '产品与服务', 'products_title' => '产品与服务',
'products' => [['/pagepan', 'PAGEPAN 小飞页'], ['/highspeaker', 'HighSpeaker DNS'], ['/sc', '软著代理服务'], ['/shnu-sc', 'SHNU 学生软著服务']], 'products' => [['/highspeaker', 'HighSpeaker DNS'], ['/pagepan', 'PAGEPAN'], ['/sc', '软著代理服务']],
'company_title' => '公司', 'company_title' => '公司',
'company' => [['/#about', '关于来笙'], ['/articles', '来笙动态'], ['https://git.laysense.com', 'Laysense Git'], ['https://www.layso.de', 'LaySo']], 'company' => [['/#about', '关于来笙'], ['#contact', '联系来笙']],
'resources_title' => '资源',
'resources' => [['https://git.laysense.com', 'Laysense Git'], ['https://www.layso.de', 'LaySo']],
'phones' => [['tel:+16699004532', '+1 (669) 900 4532'], ['tel:+85257012856', '+852 5701 2856']], 'phones' => [['tel:+16699004532', '+1 (669) 900 4532'], ['tel:+85257012856', '+852 5701 2856']],
'copyright' => '© Shanghai Laysense Information Technology Co. Ltd. 2024',
'terms' => '本网站中产品价格仅作展示,不作为订立合同、邀约或要约邀请的有效因素。',
'registration' => '沪ICP备2024051698号-1',
]; ];
public static function footer(array $site): array
{
$saved = $site['footer'] ?? null;
if ($saved === null) {
return self::DEFAULT_FOOTER;
}
// Older configurations store the entire footer navigation in two columns.
if (!array_key_exists('resources', $saved)) {
$saved += ['resources' => [], 'resources_title' => ''];
if (!empty($saved['copyright'])) {
$saved['copyright'] .= ' 2024–' . date('Y');
}
}
return $saved + self::DEFAULT_FOOTER;
}
public static function parseLinks(string $value): array public static function parseLinks(string $value): array
{ {
$links = []; $links = [];
+14
View File
@@ -65,6 +65,20 @@ final class View
return $value ? date($format, strtotime($value)) : ''; 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 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'], ''); return new Response($status, ['Location' => $path, 'Cache-Control' => $status === 301 ? 'public, max-age=300' : 'no-store'], '');
+22 -1
View File
@@ -255,6 +255,9 @@ class AdminController
} }
$page = array_replace($page, $data, ['version' => $this->version($request)]); $page = array_replace($page, $data, ['version' => $this->version($request)]);
try { 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')); $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) if ($data['name'] === '' || mb_strlen($data['name']) > 100 || !in_array($data['status'], ['draft', 'published'], true)
|| $data['title'] === '' || mb_strlen($data['title']) > 160 || || $data['title'] === '' || mb_strlen($data['title']) > 160 ||
@@ -334,8 +337,9 @@ class AdminController
$key = $change['key'] ?? null; $key = $change['key'] ?? null;
$version = $change['version'] ?? null; $version = $change['version'] ?? null;
$fields = $change['fields'] ?? null; $fields = $change['fields'] ?? null;
$alignments = $change['alignments'] ?? null;
$isNew = is_array($change) && array_key_exists('version', $change) && $version === 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)) || ($isNew ? (isset($available[$key]) || !preg_match('/^block-[a-f0-9]{32}$/D', $key))
: (!isset($available[$key]) || !is_int($version) || $version !== (int) $available[$key]['version']))) { : (!isset($available[$key]) || !is_int($version) || $version !== (int) $available[$key]['version']))) {
throw new RuntimeException('区块已变更或画布内容无效,请重新打开编辑页。'); throw new RuntimeException('区块已变更或画布内容无效,请重新打开编辑页。');
@@ -353,6 +357,9 @@ class AdminController
} }
$section[$field] = trim($value); $section[$field] = trim($value);
} }
if ($alignments !== null) {
$section['alignments'] = Database::json($this->alignmentMap($alignments, ['title', 'lead']));
}
$this->checkSection($section, $section['style']); $this->checkSection($section, $section['style']);
if (isset($fields['body'])) { if (isset($fields['body'])) {
$section['body'] = Html::sanitize($section['body']); $section['body'] = Html::sanitize($section['body']);
@@ -367,6 +374,20 @@ class AdminController
return $updates; 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 private function checkSection(array $section, string $savedStyle): void
{ {
if ($section['title'] === '' || mb_strlen($section['title']) > 100 || mb_strlen($section['lead']) > 500 if ($section['title'] === '' || mb_strlen($section['title']) > 100 || mb_strlen($section['lead']) > 500
+63 -8
View File
@@ -39,10 +39,12 @@ final class SiteController
$feed = json_decode($section['feed'], true, flags: JSON_THROW_ON_ERROR); $feed = json_decode($section['feed'], true, flags: JSON_THROW_ON_ERROR);
$tabs = $feed['mode'] === 'tabs' && count($feed['categories']) > 1; $tabs = $feed['mode'] === 'tabs' && count($feed['categories']) > 1;
$section['articleFeed'] = []; $section['articleFeed'] = [];
$section['archivePath'] = $page['status'] === 'published' ? '/articles/feed/' . $slug . '/' . $section['key'] : null;
foreach ($tabs ? $feed['categories'] : [''] as $category) { foreach ($tabs ? $feed['categories'] : [''] as $category) {
$selected = $category === '' ? $feed['categories'] : [$category];
$section['articleFeed'][] = [ $section['articleFeed'][] = [
'label' => $categories[$category] ?? '', 'categories' => $selected, 'label' => $categories[$category] ?? '',
'articles' => $repo->articles($category === '' ? $feed['categories'] : $category, limit: $feed['limit']), 'articles' => $repo->articles($selected, limit: $feed['limit']),
]; ];
} }
} }
@@ -102,6 +104,60 @@ final class SiteController
} }
$title = $category ? $categories[$category] : ($tag ?: '来笙动态'); $title = $category ? $categories[$category] : ($tag ?: '来笙动态');
$path = '/articles' . ($category ? '/category/' . $category : ($tag ? '/tag/' . rawurlencode($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'); $number = $request->get('page', '1');
if (!is_scalar($number) || !preg_match('/^[1-9][0-9]{0,4}$/D', (string) $number)) { if (!is_scalar($number) || !preg_match('/^[1-9][0-9]{0,4}$/D', (string) $number)) {
return $this->missing($request); return $this->missing($request);
@@ -111,13 +167,12 @@ final class SiteController
if ($page > 1 && $articles === []) { if ($page > 1 && $articles === []) {
return $this->missing($request); return $this->missing($request);
} }
$path = $view['archivePath'];
return View::render('archive', [ return View::render('archive', $view + [
'site' => $repo->site(), 'title' => $title . ' · 来笙', 'headline' => $title, 'site' => $repo->site(), 'title' => $view['headline'] . ' · 来笙',
'description' => '查看来笙的公告、新闻和产品动态。', 'path' => $page > 1 ? View::archivePage($path, $page) : $path,
'path' => $path . ($page > 1 ? '?page=' . $page : ''), 'archivePath' => $path, 'pageNumber' => $page, 'hasNext' => count($articles) > 20, 'articles' => array_slice($articles, 0, 20),
'categories' => $categories, 'category' => $category, 'tag' => $tag, 'pageNumber' => $page,
'hasNext' => count($articles) > 20, 'articles' => array_slice($articles, 0, 20),
'noindex' => $articles === [], 'noindex' => $articles === [],
]); ]);
} }
+10 -4
View File
@@ -98,15 +98,16 @@ final class StudioController extends AdminController
$site = (new Repository())->site(); $site = (new Repository())->site();
$defaults = match ($part) { $defaults = match ($part) {
'header' => SiteDesign::DEFAULT_HEADER, 'header' => SiteDesign::DEFAULT_HEADER,
'footer' => SiteDesign::DEFAULT_FOOTER + array_intersect_key($site, array_flip(['name', 'address', 'email', 'copyright', 'registration', 'terms'])), 'footer' => SiteDesign::DEFAULT_FOOTER,
'cdn' => ['origin' => ''], 'cdn' => ['origin' => ''],
}; };
$config = ($site[$part] ?? []) + $defaults; $config = $part === 'footer' ? SiteDesign::footer($site) : ($site[$part] ?? []) + $defaults;
$version = $site['revisions'][$part] ?? 0; $version = $site['revisions'][$part] ?? 0;
$error = ''; $error = '';
if ($request->method() === 'POST') { if ($request->method() === 'POST') {
try { try {
$config = $this->settingsInput($request, $part, $defaults); $config = $part === 'footer' && $request->post('operation') === 'restore-footer'
? $defaults : $this->settingsInput($request, $part, $defaults, $config);
SiteDesign::saveSettings($part, $config, $this->version($request)); SiteDesign::saveSettings($part, $config, $this->version($request));
return $this->success($request, '/admin/settings/' . $part . '?saved=1'); return $this->success($request, '/admin/settings/' . $part . '?saved=1');
@@ -177,13 +178,18 @@ final class StudioController extends AdminController
return $this->success($request, '/admin/media'); return $this->success($request, '/admin/media');
} }
private function settingsInput(Request $request, string $part, array $defaults): array private function settingsInput(Request $request, string $part, array $defaults, array $current): array
{ {
if ($part === 'cdn') { if ($part === 'cdn') {
return ['origin' => Assets::cdn($this->input($request, 'origin'))]; return ['origin' => Assets::cdn($this->input($request, 'origin'))];
} }
$result = []; $result = [];
$hasResources = $request->post('resources') !== null;
foreach ($defaults as $key => $default) { foreach ($defaults as $key => $default) {
if ($part === 'footer' && !$hasResources && in_array($key, ['resources', 'resources_title'], true)) {
$result[$key] = $current[$key];
continue;
}
$input = $this->input($request, $key); $input = $this->input($request, $key);
if (is_array($default)) { if (is_array($default)) {
$result[$key] = SiteDesign::parseLinks($input); $result[$key] = SiteDesign::parseLinks($input);
+1 -1
View File
@@ -15,7 +15,7 @@ $filters = $category ? 'category=' . rawurlencode($category) . '&' : '';
<nav class="filter-nav" aria-label="筛选文章"> <nav class="filter-nav" aria-label="筛选文章">
<a href="/admin/articles" <?= $category === null ? 'aria-current="page"' : '' ?>>全部</a> <a href="/admin/articles" <?= $category === null ? 'aria-current="page"' : '' ?>>全部</a>
<?php foreach ($categories as $key => $name): ?> <?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 ?> <?php endforeach ?>
</nav> </nav>
<div class="admin-panel"> <div class="admin-panel">
+2 -1
View File
@@ -2,12 +2,13 @@
use App\Content\View; use App\Content\View;
$e = View::escape(...); $e = View::escape(...);
$checked = array_fill_keys($selected, true);
?> ?>
<fieldset class="category-checks"> <fieldset class="category-checks">
<legend><?= $e($legend) ?></legend> <legend><?= $e($legend) ?></legend>
<div> <div>
<?php foreach ($categories as $key => $label): ?> <?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 ?> <?php endforeach ?>
</div> </div>
</fieldset> </fieldset>
+8 -1
View File
@@ -1,4 +1,5 @@
<?php <?php
use App\Content\Database;
use App\Content\SiteDesign; use App\Content\SiteDesign;
use App\Content\View; use App\Content\View;
use App\Content\BlockTemplates; use App\Content\BlockTemplates;
@@ -92,6 +93,11 @@ $previewUrl = '/admin/pages/' . $slug . '/preview';
<div class="studio-frame-window"> <div class="studio-frame-window">
<iframe title="可编辑页面画布" src="<?= $e($previewUrl) ?>?canvas=1" sandbox="allow-same-origin"></iframe> <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-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-properties>属性</button>
<button type="button" data-element-copy>复制</button> <button type="button" data-element-copy>复制</button>
<button type="button" data-element-delete>删除</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> <button class="button button-outline" type="button" data-replace-media>替换媒体</button>
</div> </div>
</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"> <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> <div class="admin-heading compact"><h2 id="canvas-properties-heading" data-property-heading>编辑属性</h2></div>
<form class="admin-form" method="dialog"> <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="csrf" value="<?= $e($token) ?>">
<input type="hidden" name="version" value="<?= $e($page['version']) ?>"> <input type="hidden" name="version" value="<?= $e($page['version']) ?>">
<input type="hidden" name="canvas_sections" value=""> <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>页面名称<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 标题<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> <label>SEO 描述<textarea name="description" rows="2" maxlength="300"><?= $e($page['description']) ?></textarea></label>
+7 -7
View File
@@ -6,22 +6,22 @@ $e = View::escape(...);
<section class="section article-page" aria-labelledby="archive-title" data-enter> <section class="section article-page" aria-labelledby="archive-title" data-enter>
<div class="wrap"> <div class="wrap">
<div class="section-heading"> <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> <h1 id="archive-title"><?= $e($headline) ?></h1>
<p>来笙的公告、新闻和产品动态。</p> <p><?= $e($description) ?></p>
</div> </div>
<nav class="filter-nav" aria-label="动态分类"> <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): ?> <?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 ?> <?php endforeach ?>
</nav> </nav>
<?= View::fragment('article-list', ['articles' => $articles]) ?> <?= View::fragment('article-list', ['articles' => $articles, 'categoryScope' => $categoryScope ?? null]) ?>
<?php if ($pageNumber > 1 || $hasNext): ?> <?php if ($pageNumber > 1 || $hasNext): ?>
<nav class="pagination" aria-label="动态分页"> <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> <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> </nav>
<?php endif ?> <?php endif ?>
</div> </div>
+4 -1
View File
@@ -14,7 +14,10 @@ $e = View::escape(...);
<?php foreach ($groups as $index => $group): ?> <?php foreach ($groups as $index => $group): ?>
<div id="<?= $e($sectionKey) ?>-articles-<?= $index ?>" data-tab-panel> <div id="<?= $e($sectionKey) ?>-articles-<?= $index ?>" data-tab-panel>
<?php if ($group['label'] !== ''): ?><h3 data-tab-heading><?= $e($group['label']) ?></h3><?php endif ?> <?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> </div>
<?php endforeach ?> <?php endforeach ?>
<?php if ($archivePath !== null): ?>
<p class="article-feed-archive"><a class="back-link" href="<?= $e($archivePath) ?>">查看全部动态</a></p>
<?php endif ?>
</div> </div>
+3 -1
View File
@@ -2,13 +2,15 @@
use App\Content\View; use App\Content\View;
$e = View::escape(...); $e = View::escape(...);
$scope = isset($categoryScope) ? array_flip($categoryScope) : null;
?> ?>
<?php if ($articles): ?> <?php if ($articles): ?>
<ul class="article-list"> <ul class="article-list">
<?php foreach ($articles as $item): ?> <?php foreach ($articles as $item): ?>
<?php $labels = $scope === null ? $item['categories'] : array_intersect_key($item['categories'], $scope); ?>
<li> <li>
<a class="article-row" href="/articles/<?= $e($item['slug']) ?>"> <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']) ?> <span class="article-row-title"><?= $e($item['title']) ?>
<?php if ($item['summary']): ?><small><?= $e($item['summary']) ?></small><?php endif ?> <?php if ($item['summary']): ?><small><?= $e($item['summary']) ?></small><?php endif ?>
</span> </span>
+25 -15
View File
@@ -8,7 +8,7 @@ $e = View::escape(...);
<div class="footer-grid"> <div class="footer-grid">
<div class="footer-company" itemscope itemtype="https://schema.org/Organization"> <div class="footer-company" itemscope itemtype="https://schema.org/Organization">
<?php if ($footer['logo'] !== ''): ?> <?php if ($footer['logo'] !== ''): ?>
<a href="/" itemprop="url" aria-label="来笙 Laysense 首页"> <a class="footer-logo" href="/" itemprop="url" aria-label="来笙 Laysense 首页">
<img src="<?= $e($footer['logo']) ?>" alt="<?= $e($footer['alt']) ?>" width="130" height="33" itemprop="logo" loading="lazy"> <img src="<?= $e($footer['logo']) ?>" alt="<?= $e($footer['alt']) ?>" width="130" height="33" itemprop="logo" loading="lazy">
</a> </a>
<?php endif ?> <?php endif ?>
@@ -17,31 +17,41 @@ $e = View::escape(...);
<?php if ($footer['email']): ?> <?php if ($footer['email']): ?>
<a itemprop="email" href="mailto:<?= $e($footer['email']) ?>"><?= $e($footer['email']) ?></a> <a itemprop="email" href="mailto:<?= $e($footer['email']) ?>"><?= $e($footer['email']) ?></a>
<?php endif ?> <?php endif ?>
<p class="footer-payment-label">支持的付款方式</p>
<div class="payment-methods" aria-label="支持的付款方式"> <div class="payment-methods" aria-label="支持的付款方式">
<img src="/assets/original/payment-taobao.png" alt="淘宝" width="26" height="26" loading="lazy"> <img src="/assets/original/payment-taobao.png" alt="淘宝" width="26" height="26" loading="lazy">
<img src="/assets/original/payment-alipay.png" alt="支付宝" width="26" height="26" loading="lazy"> <img src="/assets/original/payment-alipay.png" alt="支付宝" width="26" height="26" loading="lazy">
<img src="/assets/original/payment-wechat.png" alt="微信支付" width="26" height="26" loading="lazy"> <img src="/assets/original/payment-wechat.png" alt="微信支付" width="26" height="26" loading="lazy">
</div> </div>
</div> </div>
<?php foreach (['products', 'company'] as $group): ?> <nav class="footer-links" aria-label="页脚导航">
<?php if (!$footer[$group] && $footer[$group . '_title'] === '') { continue; } ?> <?php foreach (['products', 'company', 'resources'] as $group): ?>
<div> <?php if (!$footer[$group] && $footer[$group . '_title'] === '') { continue; } ?>
<?php if ($footer[$group . '_title'] !== ''): ?><p class="footer-label"><?= $e($footer[$group . '_title']) ?></p><?php endif ?> <div>
<?php foreach ($footer[$group] as [$url, $label]): ?><a href="<?= $e($url) ?>"><?= $e($label) ?></a><?php endforeach ?> <?php if ($footer[$group . '_title'] !== ''): ?><h2 class="footer-label"><?= $e($footer[$group . '_title']) ?></h2><?php endif ?>
</div> <?php if ($footer[$group]): ?>
<?php endforeach ?> <ul>
<?php foreach ($footer[$group] as [$url, $label]): ?><li><a href="<?= $e($url) ?>"><?= $e($label) ?></a></li><?php endforeach ?>
</ul>
<?php endif ?>
</div>
<?php endforeach ?>
</nav>
</div> </div>
<div class="footer-meta"> <div class="footer-meta">
<?php if ($footer['copyright']): ?><p><?= $e($footer['copyright']) ?> 2024–<?= $e(date('Y')) ?></p><?php endif ?> <?php if ($footer['copyright']): ?><p><?= $e($footer['copyright']) ?></p><?php endif ?>
<?php if ($footer['phones']): ?> <?php if ($footer['email'] || $footer['phones']): ?>
<p>全球号码 <p>
<?php foreach ($footer['phones'] as $index => [$url, $label]): ?> <?php if ($footer['email']): ?><a href="mailto:<?= $e($footer['email']) ?>"><?= $e($footer['email']) ?></a><?php endif ?>
<?= $index ? ' / ' : '' ?><a href="<?= $e($url) ?>"><?= $e($label) ?></a> <?php if ($footer['phones']): ?>全球号码:
<?php endforeach ?> <?php foreach ($footer['phones'] as $index => [$url, $label]): ?>
<?= $index ? ' / ' : '' ?><a href="<?= $e($url) ?>"><?= $e($label) ?></a>
<?php endforeach ?>
<?php endif ?>
</p> </p>
<?php endif ?> <?php endif ?>
<?php if ($footer['registration']): ?><a href="https://beian.miit.gov.cn/"><?= $e($footer['registration']) ?></a><?php endif ?>
<?php if ($footer['terms']): ?><p class="footer-terms"><?= $e($footer['terms']) ?></p><?php endif ?> <?php if ($footer['terms']): ?><p class="footer-terms"><?= $e($footer['terms']) ?></p><?php endif ?>
<?php if ($footer['registration']): ?><p><a href="https://beian.miit.gov.cn/"><?= $e($footer['registration']) ?></a></p><?php endif ?>
</div> </div>
</div> </div>
</footer> </footer>
+1 -1
View File
@@ -13,7 +13,7 @@ if (str_starts_with($imageUrl, '/')) {
$kind = in_array($page['slug'] ?? '', ['sc', 'shnu-sc'], true) ? 'service' : 'software'; $kind = in_array($page['slug'] ?? '', ['sc', 'shnu-sc'], true) ? 'service' : 'software';
$siteKind = $kind === 'service' ? 'other' : 'software'; $siteKind = $kind === 'service' ? 'other' : 'software';
$header = ($site['header'] ?? []) + SiteDesign::DEFAULT_HEADER; $header = ($site['header'] ?? []) + SiteDesign::DEFAULT_HEADER;
$footer = ($site['footer'] ?? []) + SiteDesign::DEFAULT_FOOTER + $site; $footer = SiteDesign::footer($site);
$nav = $header['links']; $nav = $header['links'];
$contact = $header['button']; $contact = $header['button'];
?> ?>
+10 -4
View File
@@ -17,15 +17,21 @@ $e = View::escape(...);
<?php if (!$group['articles']): ?><p class="empty-state">暂无已发布条目。</p><?php endif ?> <?php if (!$group['articles']): ?><p class="empty-state">暂无已发布条目。</p><?php endif ?>
<ul class="network-list"> <ul class="network-list">
<?php foreach ($group['articles'] as $item): ?> <?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> <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'])): ?> <?php if (!empty($card['image'])): ?>
<img src="<?= $e($card['image']) ?>" alt="" loading="lazy" width="76" height="28"> <img src="<?= $e($card['image']) ?>" alt="" loading="lazy" width="76" height="28">
<?php endif ?> <?php endif ?>
<span><?= $e($item['title']) ?></span> <span><?= $e($item['title']) ?></span>
</a> <?php if ($target !== ''): ?></a><?php else: ?></span><?php endif ?>
<?php if ($standalone && !empty($card['url']) && ($item['body'] !== '' || $item['summary'] !== '')): ?> <?php if ($standalone && !empty($card['url']) && $hasDetail): ?>
<a class="network-detail" href="<?= $e($articlePath) ?>">查看详情</a> <a class="network-detail" href="<?= $e($articlePath) ?>">查看详情</a>
<?php endif ?> <?php endif ?>
</li> </li>
+6 -4
View File
@@ -5,6 +5,8 @@ use App\Content\View;
$e = View::escape(...); $e = View::escape(...);
$home = $page['slug'] === 'home'; $home = $page['slug'] === 'home';
$service = in_array($page['slug'], ['sc', 'shnu-sc'], true); $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 . '"' : ''; $field = static fn (string $name): string => $canvas ? ' data-studio-field="' . $name . '"' : '';
?> ?>
<section class="hero hero-<?= $e($page['slug']) ?>" id="home" data-enter> <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: ?> <?php else: ?>
<p class="overline hero-label"><?= $e($site['footer']['name'] ?? $site['name']) ?></p> <p class="overline hero-label"><?= $e($site['footer']['name'] ?? $site['name']) ?></p>
<?php endif ?> <?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> <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"<?= $field('lead') ?>><?= $e($page['lead']) ?></p> <p class="hero-lead<?= View::alignmentClass($alignments['lead'] ?? null) ?>"<?= $field('lead') ?><?= $alignField('lead') ?>><?= $e($page['lead']) ?></p>
<div class="actions hero-actions"> <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]): ?> <?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> <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 ?> <?php endforeach ?>
</div> </div>
</div> </div>
<?php if ($canvas || $page['image'] !== ''): ?> <?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' : '' ?>> <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'): ?> <?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"> <svg class="home-pipe-flow" viewBox="0 0 640 480" aria-hidden="true" focusable="false">
+9 -4
View File
@@ -3,16 +3,21 @@ use App\Content\View;
$e = View::escape(...); $e = View::escape(...);
$canvas ??= false; $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'])) . '"' : '' ?>> <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="wrap">
<div class="section-heading"> <div class="section-heading">
<h2 id="heading-<?= $e($section['key']) ?>"<?= $canvas ? ' data-studio-part="title"' : '' ?>><?= $e($section['title']) ?></h2> <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<?= $canvas ? ' data-studio-part="lead"' : '' ?>><?= $e($section['lead']) ?></p><?php endif ?> <?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> </div>
<?php if (!empty($section['articleFeed'])): ?> <?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 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> </div>
</section> </section>
+10 -3
View File
@@ -16,23 +16,30 @@ $e = View::escape(...);
<?php if (!$products): ?><p class="empty-state">暂无可查看的产品和服务。</p><?php endif ?> <?php if (!$products): ?><p class="empty-state">暂无可查看的产品和服务。</p><?php endif ?>
<div class="catalog-grid"> <div class="catalog-grid">
<?php foreach ($products as $product): ?> <?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"> <article class="catalog-card">
<?php if (!empty($card['image'])): ?> <?php if (!empty($card['image'])): ?>
<div class="catalog-image"><img src="<?= $e($card['image']) ?>" alt="<?= $e($card['alt'] ?? '') ?>" loading="lazy"></div> <div class="catalog-image"><img src="<?= $e($card['image']) ?>" alt="<?= $e($card['alt'] ?? '') ?>" loading="lazy"></div>
<?php endif ?> <?php endif ?>
<div class="catalog-content"> <div class="catalog-content">
<?php if (!empty($card['category_label'])): ?><p class="overline"><?= $e($card['category_label']) ?></p><?php endif ?> <?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']): ?> <?php if ($product['summary']): ?>
<p><?= $e($product['summary']) ?></p> <p><?= $e($product['summary']) ?></p>
<?php else: ?> <?php else: ?>
<div class="rich"><?= Html::articleBody($product) ?></div> <div class="rich"><?= Html::articleBody($product) ?></div>
<?php endif ?> <?php endif ?>
<?php if ($target !== '' || !empty($card['extra_url'])): ?>
<div class="actions"> <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 ?> <?php if (!empty($card['extra_url'])): ?><a href="<?= $e($card['extra_url']) ?>"><?= $e(($card['extra_label'] ?? '') ?: '相关链接') ?></a><?php endif ?>
</div> </div>
<?php endif ?>
</div> </div>
</article> </article>
<?php endforeach ?> <?php endforeach ?>
+9 -1
View File
@@ -36,7 +36,7 @@ $e = View::escape(...);
<small>每行填写「显示号码 | tel:号码」。</small> <small>每行填写「显示号码 | tel:号码」。</small>
</label> </label>
<div class="form-grid"> <div class="form-grid">
<?php foreach (['products' => '第一列', 'company' => '第二列'] as $key => $text): ?> <?php foreach (['products' => '第一列', 'company' => '第二列', 'resources' => '第三列'] as $key => $text): ?>
<div class="admin-form"> <div class="admin-form">
<label><?= $text ?>标题<input name="<?= $key ?>_title" value="<?= $e($config[$key . '_title']) ?>"></label> <label><?= $text ?>标题<input name="<?= $key ?>_title" value="<?= $e($config[$key . '_title']) ?>"></label>
<label><?= $text ?>链接<textarea name="<?= $key ?>" rows="6"><?= $e(SiteDesign::linkText($config[$key])) ?></textarea> <label><?= $text ?>链接<textarea name="<?= $key ?>" rows="6"><?= $e(SiteDesign::linkText($config[$key])) ?></textarea>
@@ -50,3 +50,11 @@ $e = View::escape(...);
<?php endif ?> <?php endif ?>
<div class="form-submit"><button class="button button-primary" type="submit">保存设置</button></div> <div class="form-submit"><button class="button button-primary" type="submit">保存设置</button></div>
</form> </form>
<?php if ($part === 'footer'): ?>
<form method="post" action="/admin/settings/footer">
<input type="hidden" name="csrf" value="<?= $e($token) ?>">
<input type="hidden" name="version" value="<?= $e($revision) ?>">
<input type="hidden" name="operation" value="restore-footer">
<button class="button button-outline" type="submit" data-confirm="用原站的页脚内容覆盖当前页脚设置?">恢复原站页脚</button>
</form>
<?php endif ?>
+13
View File
@@ -6,6 +6,19 @@ use App\Content\View;
$e = View::escape(...); $e = View::escape(...);
?> ?>
<div class="studio-presets" data-canvas-presets> <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> <label class="studio-template-search">搜索模板<input type="search" data-template-search placeholder="按名称或分类搜索" autocomplete="off"></label>
<div class="studio-template-filters" role="group" aria-label="模板分类"> <div class="studio-template-filters" role="group" aria-label="模板分类">
<button type="button" data-template-filter="" aria-pressed="true">全部</button> <button type="button" data-template-filter="" aria-pressed="true">全部</button>
+1
View File
@@ -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', [SiteController::class, 'archive']);
Route::get('/articles/category/{category:[a-z0-9-]+}', [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/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('/articles/{slug:[a-z0-9-]+}', [SiteController::class, 'article']);
Route::get('/main', static fn () => View::redirect('/articles', 301)); Route::get('/main', static fn () => View::redirect('/articles', 301));
Route::get('/main/category/{id:[0-9]+}.html', [SiteController::class, 'legacyCategory']); Route::get('/main/category/{id:[0-9]+}.html', [SiteController::class, 'legacyCategory']);
+12
View File
@@ -234,3 +234,15 @@
.article-editor-heading { display: flex; align-items: center; justify-content: space-between; gap: .6rem; margin-bottom: .45rem; } .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-heading > .button { min-height: 2.1rem; padding: .25rem .6rem; }
.article-editor-help:empty { display: none; } .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; }
Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

+68 -8
View File
@@ -301,18 +301,22 @@ progress { width: 100%; height: .8rem; accent-color: var(--accent); }
.pagination { display: flex; align-items: center; gap: 1rem; margin-top: 1.5rem; } .pagination { display: flex; align-items: center; gap: 1rem; margin-top: 1.5rem; }
.empty-state { background: var(--paper); padding: 1rem; border-radius: .6rem; } .empty-state { background: var(--paper); padding: 1rem; border-radius: .6rem; }
.site-footer { padding: clamp(2.5rem, 5.8vw, 5.5rem) 0 2rem; background: #edf2fa; border-top: 1px solid var(--line); } .site-footer { padding: clamp(2.5rem, 5.8vw, 5.5rem) 0 2rem; background: #e4ecfc; border-top: 1px solid var(--line); }
.footer-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) repeat(2, minmax(0, .75fr)); gap: 1.5rem 3rem; } .footer-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1.6rem clamp(2rem, 7vw, 7rem); }
.footer-grid > div { display: flex; flex-direction: column; align-items: flex-start; } .footer-company { display: flex; flex-direction: column; align-items: flex-start; }
.footer-logo img { width: clamp(8.125rem, 13vw, 10rem); height: auto; }
.footer-links { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: start; gap: 1rem; }
.footer-links ul { padding: 0; margin: 0; list-style: none; }
.footer-grid a, .footer-meta a { color: var(--muted); text-decoration: none; overflow-wrap: anywhere; } .footer-grid a, .footer-meta a { color: var(--muted); text-decoration: none; overflow-wrap: anywhere; }
.footer-grid a:hover, .footer-meta a:hover { color: var(--accent); text-decoration: underline; } .footer-grid a:hover, .footer-meta a:hover { color: var(--accent); text-decoration: underline; }
.footer-grid a { min-height: 44px; display: inline-flex; align-items: center; } .footer-grid a { min-height: 40px; display: inline-flex; align-items: center; }
.footer-company p, .footer-label { color: var(--ink); font-weight: 640; margin: .2rem 0 .35rem; } .footer-company p, .footer-label { color: var(--ink); font-weight: 640; margin: .2rem 0 .35rem; }
.footer-label { font-size: 1.05rem; line-height: 1.35; }
.footer-company p { margin-top: .6rem; } .footer-company p { margin-top: .6rem; }
.footer-company .footer-payment-label { margin: .25rem 0 0; color: var(--muted); font-size: .87rem; font-weight: 500; }
.footer-company address { color: var(--muted); max-width: 26rem; font-size: .95rem; } .footer-company address { color: var(--muted); max-width: 26rem; font-size: .95rem; }
.footer-meta { display: flex; flex-wrap: wrap; gap: .6rem 1.8rem; padding-top: 1.2rem; margin-top: 1.25rem; border-top: 1px solid var(--line); font-size: .875rem; } .footer-meta { display: grid; gap: .35rem; padding-top: 1.2rem; margin-top: 1.6rem; border-top: 1px solid var(--line); font-size: .875rem; }
.footer-meta p { margin: 0; } .footer-meta p { margin: 0; }
.footer-terms { flex-basis: 100%; }
@media (max-width: 62rem) { @media (max-width: 62rem) {
.masthead-inner { gap: .85rem; } .masthead-inner { gap: .85rem; }
@@ -358,8 +362,9 @@ progress { width: 100%; height: .8rem; accent-color: var(--accent); }
.article-category { grid-column: 1; grid-row: 1; } .article-category { grid-column: 1; grid-row: 1; }
.article-row-title { grid-column: 1 / -1; grid-row: 2; } .article-row-title { grid-column: 1 / -1; grid-row: 2; }
.article-row time { grid-column: 2; grid-row: 1; } .article-row time { grid-column: 2; grid-row: 1; }
.footer-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 1rem; } .footer-grid { grid-template-columns: 1fr; }
.footer-company { grid-column: 1 / -1; } .footer-company { align-items: center; text-align: center; }
.footer-links, .footer-meta { text-align: center; }
} }
@media (max-width: 23rem) { @media (max-width: 23rem) {
.hero-actions .button { width: 100%; } .hero-actions .button { width: 100%; }
@@ -647,3 +652,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 { 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); } .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; } .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); }
+105 -19
View File
@@ -265,7 +265,11 @@ jQuery(function ($) {
const $settings = $layout.find('.studio-inspector'); const $settings = $layout.find('.studio-inspector');
const $sizing = $studio.find('[data-media-sizing]'); const $sizing = $studio.find('[data-media-sizing]');
const $elementTools = $studio.find('[data-element-tools]'); 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 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 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 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]'); const $handle = $studio.find('[data-media-handle]');
@@ -328,7 +332,14 @@ jQuery(function ($) {
function sectionChanges(withEdits = true) { function sectionChanges(withEdits = true) {
return sections.flatMap(({key, version, fields, source, template}) => { return sections.flatMap(({key, version, fields, source, template}) => {
const changes = {}; 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; let value = field === 'body' ? node.innerHTML : node.textContent;
if (field === 'body' && node.contains(selectedElement)) { if (field === 'body' && node.contains(selectedElement)) {
const copy = node.cloneNode(true); const copy = node.cloneNode(true);
@@ -339,7 +350,8 @@ jQuery(function ($) {
changes[field] = withEdits && field === 'body' && version !== null ? bodyEdits(source, value) : value; 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 { } else {
configureText(node, label, part === 'lead'); 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( const source = new TextDecoder('utf-8', {ignoreBOM: true}).decode(Uint8Array.from(
atob(section.dataset.studioSource || ''), (byte) => byte.charCodeAt(0) atob(section.dataset.studioSource || ''), (byte) => byte.charCodeAt(0)
@@ -662,11 +674,12 @@ jQuery(function ($) {
const node = sizingTarget(); const node = sizingTarget();
if (node) { if (node) {
const bounds = previewBounds(node); const bounds = previewBounds(node);
const x = getAlignment(node) === 'right' ? bounds.left : bounds.right;
const y = (bounds.top + bounds.bottom) / 2; const y = (bounds.top + bounds.bottom) / 2;
const visible = bounds.width > 0 && y >= 0 && y <= container.clientHeight 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.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 { } else {
$handle.prop('hidden', true); $handle.prop('hidden', true);
} }
@@ -706,6 +719,24 @@ jQuery(function ($) {
return element !== body && body.contains(element) ? element : null; 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) { function selectElement(node) {
selectionObserver?.disconnect(); selectionObserver?.disconnect();
selectedElement?.removeAttribute('data-studio-selected'); selectedElement?.removeAttribute('data-studio-selected');
@@ -719,10 +750,13 @@ jQuery(function ($) {
const inBody = node.closest('[data-studio-part="body"]') !== null; const inBody = node.closest('[data-studio-part="body"]') !== null;
const canCopy = inBody || (nav && $(node).siblings().length < 19); const canCopy = inBody || (nav && $(node).siblings().length < 19);
const hasProperties = selectedMedia || node.matches('a'); const hasProperties = selectedMedia || node.matches('a');
const aligned = alignmentTarget(node);
syncAlignmentButtons(aligned);
$elementTools.find('[data-element-copy]').prop('hidden', !canCopy); $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); $elementTools.find('[data-element-properties]').prop('hidden', !hasProperties);
if (target) showMediaWidth(currentMediaWidth(target)); if (target) showMediaWidth(currentMediaWidth(target));
selectionObserver?.observe(target || node); selectionObserver?.observe(target || aligned || node);
} }
positionSelection(); 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-delete]', () => changeElement(false))
.on('click', '[data-element-properties]', () => { .on('click', '[data-element-properties]', () => {
if (selectedMedia) replaceMedia(); if (selectedMedia) replaceMedia();
@@ -790,9 +839,10 @@ jQuery(function ($) {
const narrow = node.getBoundingClientRect(); const narrow = node.getBoundingClientRect();
if (classes === null) node.removeAttribute('class'); if (classes === null) node.removeAttribute('class');
else node.setAttribute('class', classes); else node.setAttribute('class', classes);
const rightEdgeTravel = (full.right - narrow.right) / .9; const fromLeft = getAlignment(node) === 'right';
const available = rightEdgeTravel > full.width * .15 ? rightEdgeTravel : full.width; const edgeTravel = (fromLeft ? narrow.left - full.left : full.right - narrow.right) / .9;
return {available, initialWidth: width || Math.round(100 * natural / (full.width || natural || 1))}; 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) { function resizeMedia(width) {
@@ -817,7 +867,8 @@ jQuery(function ($) {
if (!mediaDrag || mediaDrag.id !== pointer.pointerId || !mediaDrag.available) return; if (!mediaDrag || mediaDrag.id !== pointer.pointerId || !mediaDrag.available) return;
if (pointer.clientX !== mediaDrag.x || mediaDrag.moved) { if (pointer.clientX !== mediaDrag.x || mediaDrag.moved) {
mediaDrag.moved = true; 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', () => { }).on('lostpointercapture', () => {
mediaDrag = null; mediaDrag = null;
@@ -836,7 +887,44 @@ jQuery(function ($) {
$layout.on('click', '[data-hero-control]', function () { $layout.on('click', '[data-hero-control]', function () {
heroControls.get(this.dataset.heroControl)?.(); 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 () { $presets.on('click', '[data-canvas-template]', function () {
const markup = $presets.find('template[data-preset="' + this.dataset.canvasTemplate + '"]').get(0).innerHTML; const markup = $presets.find('template[data-preset="' + this.dataset.canvasTemplate + '"]').get(0).innerHTML;
const template = this.dataset.canvasTemplate; const template = this.dataset.canvasTemplate;
@@ -849,10 +937,8 @@ jQuery(function ($) {
$templateStatus.text('先在画布中选择要插入的区块正文。'); $templateStatus.text('先在画布中选择要插入的区块正文。');
return; return;
} }
// Insert at the saved caret without replacing any selected text. insertInBody(markup, activeBody, savedRange);
const insertion = savedRange?.cloneRange(); selectElement(null);
insertion?.collapse(false);
editBody(activeBody, insertion, 'insertHTML', markup);
$templateStatus.text('已插入当前正文。'); $templateStatus.text('已插入当前正文。');
return; return;
} }
@@ -920,8 +1006,8 @@ jQuery(function ($) {
}); });
$doc.on('click.canvas', (event) => { $doc.on('click.canvas', (event) => {
const node = event.target; const node = event.target;
const optional = node.closest?.(heroOrOptional); const field = node.closest?.(canvasFields);
selectElement(doc.getSelection()?.isCollapsed ? optional || editableBodyElement(node) : null); selectElement(doc.getSelection()?.isCollapsed ? field || editableBodyElement(node) : null);
}); });
$doc.on('dblclick.canvas', '[data-studio-part="body"] a', function (event) { $doc.on('dblclick.canvas', '[data-studio-part="body"] a', function (event) {
event.preventDefault(); event.preventDefault();
@@ -950,7 +1036,7 @@ jQuery(function ($) {
}); });
$toolbar.prop('hidden', false); $toolbar.prop('hidden', false);
$layout.find('[data-canvas-jump]').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'); $presets.triggerHandler('studio:canvas-ready');
} }
Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

+2
View File
@@ -13,6 +13,7 @@ CREATE TABLE IF NOT EXISTS pages (
image TEXT NOT NULL, image TEXT NOT NULL,
alt TEXT NOT NULL, alt TEXT NOT NULL,
image_scale INTEGER NOT NULL DEFAULT 0, image_scale INTEGER NOT NULL DEFAULT 0,
alignments TEXT NOT NULL DEFAULT '{}',
actions TEXT NOT NULL, actions TEXT NOT NULL,
quicklinks TEXT NOT NULL, quicklinks TEXT NOT NULL,
status TEXT NOT NULL DEFAULT 'published' CHECK (status IN ('draft', 'published')), 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, lead TEXT NOT NULL,
style TEXT NOT NULL DEFAULT 'plain', style TEXT NOT NULL DEFAULT 'plain',
feed TEXT, feed TEXT,
alignments TEXT NOT NULL DEFAULT '{}',
body TEXT NOT NULL, body TEXT NOT NULL,
position INTEGER NOT NULL, position INTEGER NOT NULL,
version INTEGER NOT NULL DEFAULT 0, version INTEGER NOT NULL DEFAULT 0,
+1 -1
View File
@@ -49,7 +49,7 @@
"title": "来笙动态", "title": "来笙动态",
"lead": "", "lead": "",
"style": "plain", "style": "plain",
"body": "<p><a class=\"back-link\" href=\"/articles\">查看全部动态</a></p>", "body": "",
"feed": { "feed": {
"categories": [ "categories": [
"announcement", "announcement",
+18
View File
@@ -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";
}
+67
View File
@@ -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
+100 -7
View File
@@ -54,6 +54,8 @@ async function run(browser) {
const frame = page.frameLocator('iframe[title="可编辑页面画布"]'); const frame = page.frameLocator('iframe[title="可编辑页面画布"]');
const sizing = page.locator('[data-media-sizing]'); const sizing = page.locator('[data-media-sizing]');
const properties = page.locator('[data-canvas-properties]'); 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 closeProperties = () => properties.locator('[data-property-close]').click();
const image = frame.locator('#fixtures img'); 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('[name=url]').fill('/assets/original/home-hero.webp');
await properties.locator('button[type=submit]').click(); await properties.locator('button[type=submit]').click();
assert.equal(await image.getAttribute('src'), '/assets/original/home-hero.webp'); 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]'); const hero = frame.locator('[data-studio-hero-image]');
await page.locator('iframe[title="可编辑页面画布"]').evaluate((iframe) => iframe.contentWindow.scrollTo(0, 0)); 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(); await sizing.locator('[data-replace-media]').click();
assert.equal(await properties.locator('h2').textContent(), '首屏图片'); assert.equal(await properties.locator('h2').textContent(), '首屏图片');
await closeProperties(); 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 frame.locator('#fixtures a').click();
await tools.getByRole('button', {name: '属性'}).click(); await tools.getByRole('button', {name: '属性'}).click();
await properties.waitFor({state: 'visible'}); await properties.waitFor({state: 'visible'});
@@ -108,6 +125,11 @@ async function run(browser) {
const copyText = frame.locator('#fixtures').getByText('待复制段落', {exact: true}); const copyText = frame.locator('#fixtures').getByText('待复制段落', {exact: true});
await copyText.click(); 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(); await tools.getByRole('button', {name: '复制'}).click();
assert.equal(await copyText.count(), 2); assert.equal(await copyText.count(), 2);
assert.equal(await frame.locator('#copy-fixture').count(), 1); assert.equal(await frame.locator('#copy-fixture').count(), 1);
@@ -119,9 +141,19 @@ async function run(browser) {
await tools.getByRole('button', {name: '删除'}).click(); await tools.getByRole('button', {name: '删除'}).click();
assert.equal(await page.locator('[name=lead]').inputValue(), ''); 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]'); const gallery = page.locator('[data-canvas-presets]');
assert.equal(await gallery.locator('[data-template-group]').count(), 6); await copyText.first().click();
assert.equal(await gallery.locator('[data-template-card]').count(), 14); 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) => { const brokenPreviews = await gallery.locator('[data-template-card] img').evaluateAll(async (images) => {
for (const image of images) image.loading = 'eager'; for (const image of images) image.loading = 'eager';
await Promise.all(images.map((image) => image.decode())); 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 gallery.locator('[data-template-empty]').waitFor({state: 'visible'});
await search.fill('双栏'); await search.fill('双栏');
assert.equal(await gallery.locator('[data-template-card]:visible').count(), 1); 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 search.fill('分类文章');
await gallery.locator('[data-canvas-template=articles]').click(); await gallery.locator('[data-canvas-template=articles]').click();
await frame.locator('section[id^=block-] h2').filter({hasText: '分类文章'}).waitFor(); 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(); 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 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('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.match(await frame.locator('[data-visual]').getAttribute('class'), /studio-media-99/);
assert.equal(await copyText.count(), 2); assert.equal(await copyText.count(), 2);
assert.equal(await frame.locator('#copy-fixture').count(), 1); 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) { 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: '自定义测试分类'}); await post('/admin/article-categories', {slug: category, name: '自定义测试分类'});
const articleSlug = slug + '-article'; const articleSlug = slug + '-article';
await page.goto('/admin/articles/new'); 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=title]').fill('测试 Markdown 和富文本');
await page.locator('[name=slug]').fill(articleSlug); await page.locator('[name=slug]').fill(articleSlug);
await page.locator('[name="categories[]"][value="' + category + '"]').check(); await page.locator('[name="categories[]"][value="' + category + '"]').check();
await page.locator('[name="categories[]"][value=product]').check();
await page.locator('[name=status]').selectOption('published'); await page.locator('[name=status]').selectOption('published');
await markdown.fill('**Markdown 分屏**'); await markdown.fill('**Markdown 分屏**');
await preview.locator('strong').getByText('Markdown 分屏').waitFor(); 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 publishedPath = '/articles/' + articleSlug;
const sourcePage = await context.newPage(); const sourcePage = await context.newPage();
await sourcePage.goto(publishedPath); 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 sourcePage.locator('[itemprop=articleBody] strong').getByText('Markdown 分屏').waitFor();
await page.goto(articleAdmin); await page.goto(articleAdmin);
await editor.locator('.toastui-editor-mode-switch').getByText('所见即所得', {exact: true}).click(); 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.locator('[name="feed_categories[]"][value="' + category + '"]').check();
await page.getByRole('button', {name: '保存区块'}).click(); await page.getByRole('button', {name: '保存区块'}).click();
await page.locator('[data-save-confirmation]').waitFor({state: 'visible'}); 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(); let contentVersion = await page.locator('[name=version]').inputValue();
assert.equal(contentVersion, '1'); assert.equal(contentVersion, '1');
const canvasPath = '/admin/pages/' + slug + '/preview'; 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); assert.equal(await noJSPage.locator('#' + feedId + ' a[href="' + publishedPath + '"]:visible').count(), 2);
await noJS.close(); await noJS.close();
assert((await context.request.get('/articles/category/' + category)).ok()); 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.goto('/services');
await sourcePage.locator('.catalog-card').first().waitFor(); await sourcePage.locator('.catalog-card').first().waitFor();
await sourcePage.goto('/network'); await sourcePage.goto('/network');
@@ -275,11 +318,61 @@ async function verifyArticleLibrary(browser, context, page, post, slug, feedId)
await sourcePage.close(); 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 () => { (async () => {
const browser = await chromium.launch({executablePath: process.env.CHROMIUM_EXECUTABLE || undefined}); const browser = await chromium.launch({executablePath: process.env.CHROMIUM_EXECUTABLE || undefined});
try { try {
await run(browser); 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 { } finally {
await browser.close(); await browser.close();
} }