diff --git a/README.md b/README.md
index 9d84e3d..45cd3d8 100644
--- a/README.md
+++ b/README.md
@@ -28,13 +28,14 @@ php bin/admin.php reset admin@example.com
## 后台编辑
- **网站后台**可按名称、地址或发布状态查找页面,从列表打开画布、公开页或草稿预览。
-- **页面设计**支持新建草稿、发布和撤回。首屏标题与简介可在桌面或手机画布中直接编辑。区块支持新增、排序、删除、可视化编辑、媒体插入和 HTML 源码。单击画布元素可用浮动工具条复制或删除。选中媒体后,可拖动边缘手柄调整宽度。浮动工具条可将正文元素、区块标题和首屏元素对齐到左侧、中央或右侧。编辑器左侧分为「组件」「元素」「图层」。先进入分类,再查找并插入模板或基础元素。悬停或键盘聚焦缩略图可放大,点击可打开预览。
+- **页面设计**支持新建草稿、发布和撤回。首屏标题与简介可在桌面或手机画布中直接编辑。区块支持新增、排序、删除、可视化编辑、媒体插入和 HTML 源码。单击画布元素可用浮动工具条复制或删除。选中媒体后,可拖动边缘手柄调整宽度。浮动工具条可将正文元素、区块标题和首屏元素对齐到左侧、中央或右侧。编辑器左侧分为「组件」「元素」「图层」。先进入分类,再查找并插入模板或基础元素。可在功能分类中复用产品图文、特性组、服务报价等内置模板,徽标、按钮组、面包屑、进度、通知和折叠等元素参考 [Preline UI 免费组件文档](https://preline.co/docs/index.html),用本站样式实现。悬停或键盘聚焦缩略图可放大,点击可打开预览。
- **媒体库**集中列出项目静态文件及上传文件,支持查找、选取、复制路径、改名和归档。归档资源的已有 URL 保持可访问。上传文件放在 `LAYSENSE_MEDIA_DIR`,由 `/assets/uploads/` 提供。
- **文章**使用自托管的 TOAST UI Editor 3.2.2(MIT)。Markdown 左侧源码、右侧实时预览,富文本使用所见即所得模式。文章可以加入多个分类,可在「管理分类」创建新分类。
-- **分类文章**支持在任意页面添加,保存区块后在「图层」中编辑分类、展示数量和合并或标签页模式。「查看全部动态」和翻页只列出该区块所选的分类。
+- **普通页面**包括 `/services`、`/articles` 和 `/contact`。产品目录和分类文章模块的设置可在画布编辑。动态页默认显示公告、新闻和产品动态。
+- **分类文章**支持在任意页面添加,选中动态模块后可用浮动工具条打开设置、复制或删除,随页面一起保存。文章列表、产品目录和项目与伙伴卡片共用分类设置。「查看全部」和翻页只列出该区块所选的分类。
- **产品与服务**(`/services`)和**支持项目与合作伙伴**(`/network`)由文章分类生成。通过文章的目录卡片设置图片、链接和排序,使用草稿状态可从目录撤下。
- **网站设置**分别编辑页头标志、导航及按钮,和页脚的公司信息、产品、公司及资源链接和备注。页脚设置可恢复原站内容。CDN 设置接受 HTTPS 源站地址。浏览器看到的公开 `/assets/…` 路径使用该源站。
-- 文章支持摘要和标签。状态选「草稿」可撤回公开文章。已发布文章改网址标识后,旧标识会自动跳转。
+- 文章支持摘要和标签。状态选「草稿」可撤回公开文章。编辑页底部可永久删除文章,重复安装也会保留删除结果。已发布文章改网址标识后,旧标识会自动跳转。
- 首页动态、分类列表和站点地图随发布状态更新。源代码和 SQLite 数据分开管理。安装命令可重复执行,已编辑的内容会保留。
## 生产运行
@@ -71,7 +72,7 @@ location = /admin/media {
| `LAYSENSE_SECURE_COOKIES` | 默认关闭 · 本地 HTTP 使用默认值。生产 HTTPS 设置为 `1`。 |
| `LAYSENSE_TRUSTED_PROXIES` | 默认 `127.0.0.1,::1` · 逗号分隔的受信反代 IP,设为空字符串可关闭信任 |
-SQLite 已启用 WAL。使用上一版多分类文章结构的站点,可用当前 `LAYSENSE_DB` 运行 `php bin/install.php` 增加对齐字段,之后重启 Webman。全新安装时,将 `LAYSENSE_DB` 指向新文件并按上面的步骤初始化和创建管理员。安装会预载网站自带页面、文章、产品和伙伴目录。服务用户需要对 SQLite 目录、媒体目录和 `runtime/` 有写权限。备份可用 `sqlite3 storage/laysense.sqlite ".backup 'laysense-backup.sqlite'"`,媒体目录单独保存。
+SQLite 已启用 WAL。使用上一版多分类文章结构的站点,可用当前 `LAYSENSE_DB` 运行 `php bin/install.php` 增量安装,之后重启 Webman。安装会补齐 `/services`、`/articles` 和 `/contact` 的页面记录,并一次性导入首页五联导航和伙伴动态模块。全新安装时,将 `LAYSENSE_DB` 指向新文件并按上面的步骤初始化和创建管理员。安装会预载网站自带页面、文章、产品和伙伴目录。服务用户需要对 SQLite 目录、媒体目录和 `runtime/` 有写权限。备份可用 `sqlite3 storage/laysense.sqlite ".backup 'laysense-backup.sqlite'"`,媒体目录单独保存。
### CDN
diff --git a/app/Content/BlockTemplates.php b/app/Content/BlockTemplates.php
index c8feba0..a1968d7 100644
--- a/app/Content/BlockTemplates.php
+++ b/app/Content/BlockTemplates.php
@@ -8,6 +8,12 @@ final class BlockTemplates
{
public const ARTICLE_FEED = '{"categories":["announcement","news","product"],"mode":"merged","limit":6}';
+ public const NETWORK_FEED = '{"categories":["supported-projects","partners"],"mode":"network","limit":30}';
+
+ public const CATALOG_FEED = '{"categories":["services"],"mode":"catalog","limit":30}';
+
+ public const PRODUCT_LINKS = '
';
+
public const ELEMENT_GROUPS = [
'text-elements' => ['文字与列表', [
'paragraph' => ['段落', '填写正文。
'],
@@ -16,24 +22,39 @@ final class BlockTemplates
'blockquote' => ['引用', '填写需要引用的内容。
'],
'bullet-list' => ['项目列表', ''],
'ordered-list' => ['编号列表', '- 填写第一项
- 填写第二项
'],
+ 'heading-kicker' => ['标题眉标', '填写分类名称
'],
+ 'tag' => ['徽标', '填写标签
'],
+ 'large-number' => ['重点数字', '填写数字
'],
'definition-list' => ['术语说明', '- 填写术语
- 填写术语说明。
'],
]],
'link-elements' => ['链接与按钮', [
'button' => ['主按钮', '联系来笙
'],
'outline-button' => ['描边按钮', '查看服务
'],
'text-link' => ['文字链接', '阅读文章
'],
+ 'button-group' => ['按钮组', ''],
+ 'breadcrumbs' => ['面包屑', '首页 / 当前页面
'],
+ 'download-link' => ['下载入口', '查看下载
'],
'email-link' => ['邮件链接', '发送邮件
'],
]],
'media-elements' => ['图片与影音', [
'image' => ['图片', '', 'image/'],
'video' => ['视频', '', 'video/'],
'audio' => ['音频', '', 'audio/'],
+ 'qr-image' => ['二维码', '', 'image/'],
+ 'image-link' => ['图片链接', '
'],
]],
'structure-elements' => ['版式与数据', [
'separator' => ['分割线', '
'],
'spacer' => ['留白', ''],
'code' => ['代码块', '填写代码
'],
'basic-table' => ['数据表格', ''],
+ 'progress' => ['进度条', ''],
+ 'alert' => ['提示卡', ''],
+ 'simple-card' => ['内容卡片', '填写卡片标题
填写卡片内容。
'],
+ 'link-card' => ['链接卡片', '查看资料
填写链接指向的资料说明。
打开资料'],
+ 'list-group' => ['列表组', ''],
+ 'empty-card' => ['空状态', ''],
+ 'status-note' => ['状态提示', ''],
'disclosure' => ['折叠内容', ''],
]],
];
@@ -42,7 +63,8 @@ final class BlockTemplates
'content' => ['标题与正文', [
'headline' => ['标题与简介', ''],
'text' => ['正文', '在这里输入区块内容。
'],
- 'articles' => ['分类文章', ''],
+ 'articles' => ['分类文章', '', '', self::ARTICLE_FEED],
+ 'network' => ['支持项目与合作伙伴', '', '', self::NETWORK_FEED],
'list' => ['步骤列表', '- 填写第一步
- 填写第二步
- 填写第三步
'],
'notice' => ['重点提示', ''],
]],
@@ -52,7 +74,7 @@ final class BlockTemplates
'two-actions' => ['双按钮横幅', ''],
]],
'layout' => ['图文与布局', [
- 'image' => ['图文', ''],
+ 'image' => ['产品图文', ''],
'grid' => ['双栏网格', ''],
]],
'media' => ['媒体', [
@@ -74,6 +96,8 @@ final class BlockTemplates
'pricing' => ['双方案报价', ''],
]],
'actions' => ['导航与引导', [
+ 'service-catalog' => ['产品与服务目录', '', '', self::CATALOG_FEED],
+ 'product-links' => ['产品与服务五联导航', self::PRODUCT_LINKS],
'navigation' => ['快速导航', ''],
'cta' => ['行动按钮', '说明下一步。
联系来笙
'],
'resources' => ['资料与链接', ''],
@@ -81,9 +105,55 @@ final class BlockTemplates
]],
];
+ public static function groups(): array
+ {
+ static $groups;
+ if ($groups !== null) {
+ return $groups;
+ }
+
+ $groups = self::GROUPS;
+ $seed = json_decode(file_get_contents(dirname(__DIR__, 2) . '/resources/seed.json'), true, flags: JSON_THROW_ON_ERROR);
+ $sectionGroups = [
+ 'product' => 'layout', 'about' => 'content', 'blog' => 'content',
+ 'features' => 'features', 'support' => 'features', 'why' => 'features', 'stories' => 'features',
+ 'pricing' => 'details', 'comparison' => 'details', 'materials' => 'details', 'fees' => 'details',
+ 'faq' => 'details', 'terms' => 'details',
+ 'get' => 'actions', 'options' => 'actions', 'go' => 'actions', 'benefits' => 'layout',
+ ];
+ foreach ($seed['pages'] as $page) {
+ if (!in_array($page['slug'], ['home', 'highspeaker', 'sc', 'shnu-sc'], true)) {
+ continue;
+ }
+ $links = '';
+ foreach ($page['actions'] as [$url, $label]) {
+ $links .= '' . View::escape($label) . '';
+ }
+ $hero = '![' . View::escape($page['alt']) . '](' . View::escape($page['image']) . ')
'
+ . '
' . View::escape(trim($page['heading'] . ' ' . $page['accent'])) . '
' . View::escape($page['lead'])
+ . '
' . $links . '
';
+ $prefix = 'existing-' . $page['slug'] . '-';
+ $groups['cover'][1][$prefix . 'hero'] = ['产品图文 · ' . $page['name'], $hero];
+ foreach ($page['sections'] as $section) {
+ $group = $sectionGroups[$section['key']] ?? null;
+ if ($group === null) {
+ continue;
+ }
+ $groups[$group][1][$prefix . $section['key']] = [
+ $section['key'] === 'features' ? '特性组' : $section['title'],
+ Html::sanitize($section['body']), $section['lead'],
+ isset($section['feed']) ? Database::json($section['feed']) : null,
+ $section['style'],
+ ];
+ }
+ }
+
+ return $groups;
+ }
+
public static function find(string $key): ?array
{
- foreach (self::GROUPS as [, $templates]) {
+ foreach (self::groups() as [, $templates]) {
if (isset($templates[$key])) {
return $templates[$key];
}
diff --git a/app/Content/Database.php b/app/Content/Database.php
index 2ce7641..4e0c36f 100644
--- a/app/Content/Database.php
+++ b/app/Content/Database.php
@@ -10,6 +10,10 @@ use Throwable;
final class Database
{
+ // Avoid reusing a deleted ID that may still be open in an editing form.
+ public const NEXT_ARTICLE_ID = 'MAX(COALESCE((SELECT MAX(id) FROM articles), 0),
+ COALESCE((SELECT MAX(article_id) FROM article_deletions), 0)) + 1';
+
private static ?PDO $connection = null;
public static function connect(): PDO
@@ -75,13 +79,29 @@ final class Database
}
}
+ if ((int) $pdo->query('PRAGMA user_version')->fetchColumn() === 0) {
+ $heroDirectory = $pdo->prepare("INSERT OR IGNORE INTO sections (page_slug, key, title, lead, style, body, position)
+ VALUES ('home', 'hero-directory', '产品与服务导航', '', 'hero-links', ?, -1)");
+ $heroDirectory->execute([BlockTemplates::PRODUCT_LINKS]);
+ $network = $pdo->prepare("INSERT OR IGNORE INTO sections (page_slug, key, title, lead, style, body, feed, position)
+ SELECT 'home', 'network', '支持项目与合作伙伴', '', 'plain', '', ?, COALESCE(MAX(position), -1) + 1
+ FROM sections WHERE page_slug = 'home'");
+ $network->execute([BlockTemplates::NETWORK_FEED]);
+ if ($heroDirectory->rowCount() + $network->rowCount() > 0) {
+ $pdo->exec("UPDATE pages SET version = version + 1 WHERE slug = 'home'");
+ }
+ $pdo->exec('PRAGMA user_version = 1');
+ }
+
$category = $pdo->prepare('INSERT OR IGNORE INTO article_categories (slug, name) VALUES (?, ?)');
foreach (Repository::CATEGORIES as $slug => $name) {
$category->execute([$slug, $name]);
}
$article = $pdo->prepare("INSERT OR IGNORE INTO articles
- (slug, title, summary, body, body_format, card, tags, status, published_at, updated_at, legacy_path)
- SELECT ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? WHERE NOT EXISTS (SELECT 1 FROM article_redirects WHERE slug = ?)");
+ (id, slug, title, summary, body, body_format, card, tags, status, published_at, updated_at, legacy_path)
+ SELECT " . self::NEXT_ARTICLE_ID . ", ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
+ WHERE NOT EXISTS (SELECT 1 FROM article_redirects WHERE slug = ?)
+ AND NOT EXISTS (SELECT 1 FROM article_deletions WHERE slug = ?)");
$link = $pdo->prepare('INSERT INTO article_category_links (article_id, category_slug) VALUES (?, ?)');
foreach ($seed['articles'] as $item) {
$format = $item['body_format'] ?? 'markdown';
@@ -90,7 +110,7 @@ final class Database
$item['slug'], $item['title'], $item['summary'] ?? '',
$format === 'html' ? Html::sanitize($item['body']) : $item['body'], $format,
self::json($item['card'] ?? []), self::json($item['tags'] ?? []),
- $item['status'] ?? 'published', $date, $date ?? gmdate(DATE_ATOM), $item['legacy'] ?? null, $item['slug'],
+ $item['status'] ?? 'published', $date, $date ?? gmdate(DATE_ATOM), $item['legacy'] ?? null, $item['slug'], $item['slug'],
]);
if ($article->rowCount() === 1) {
$id = $pdo->lastInsertId();
diff --git a/app/Content/Html.php b/app/Content/Html.php
index 60df8c5..34505f2 100644
--- a/app/Content/Html.php
+++ b/app/Content/Html.php
@@ -88,7 +88,7 @@ final class Html
return $result;
}
- public static function sanitize(string $html): string
+ public static function sanitize(string $html, ?string $anchorPrefix = null): string
{
$document = new DOMDocument('1.0', 'UTF-8');
$document->loadHTML('' . $html . '', LIBXML_NOERROR | LIBXML_NOWARNING | LIBXML_NONET);
@@ -97,6 +97,22 @@ final class Html
return '';
}
self::sanitizeChildren($body);
+ if ($anchorPrefix !== null) {
+ $ids = [];
+ foreach ($body->getElementsByTagName('*') as $element) {
+ $id = $element->getAttribute('id');
+ if ($id !== '') {
+ $ids[$id] = $anchorPrefix . '-' . $id;
+ $element->setAttribute('id', $ids[$id]);
+ }
+ }
+ foreach ($body->getElementsByTagName('a') as $link) {
+ $href = $link->getAttribute('href');
+ if (str_starts_with($href, '#') && isset($ids[substr($href, 1)])) {
+ $link->setAttribute('href', '#' . $ids[substr($href, 1)]);
+ }
+ }
+ }
$output = '';
foreach ($body->childNodes as $child) {
$output .= $document->saveHTML($child);
diff --git a/app/Content/Repository.php b/app/Content/Repository.php
index 3d35699..ef44a2f 100644
--- a/app/Content/Repository.php
+++ b/app/Content/Repository.php
@@ -86,7 +86,9 @@ final class Repository
]);
self::checkVersion($query->rowCount());
foreach ($sections as $section) {
- if ($section['version'] === null) {
+ if (!empty($section['delete'])) {
+ self::deleteSection($pdo, $slug, $section['key'], $section['version']);
+ } elseif ($section['version'] === null) {
self::insertSection($pdo, $slug, $section['key'], $section);
} else {
self::updateSection($pdo, $slug, $section['key'], $section, $section['version']);
@@ -111,10 +113,10 @@ final class Repository
self::checkVersion($query->rowCount());
}
- public function createSection(string $page, string $key, string $title, string $style, string $body, ?string $feed = null): void
+ public function createSection(string $page, string $key, string $title, string $style, string $body, ?string $feed = null, string $lead = ''): void
{
- Database::write(function (PDO $pdo) use ($page, $key, $title, $style, $body, $feed): void {
- self::insertSection($pdo, $page, $key, compact('title', 'style', 'body', 'feed') + ['lead' => '']);
+ Database::write(function (PDO $pdo) use ($page, $key, $title, $style, $body, $feed, $lead): void {
+ self::insertSection($pdo, $page, $key, compact('title', 'style', 'body', 'feed', 'lead'));
self::touchPage($pdo, $page, structureChanged: true);
});
}
@@ -129,6 +131,13 @@ final class Repository
}
}
+ private static function deleteSection(PDO $pdo, string $page, string $key, int $version): void
+ {
+ $query = $pdo->prepare('DELETE FROM sections WHERE page_slug = ? AND key = ? AND version = ?');
+ $query->execute([$page, $key, $version]);
+ self::checkVersion($query->rowCount());
+ }
+
public function arrangeSection(string $page, string $key, string $operation, int $version, int $pageVersion): void
{
Database::write(function (PDO $pdo) use ($page, $key, $operation, $version, $pageVersion): void {
@@ -137,14 +146,12 @@ final class Repository
$revision = $current->fetchColumn();
self::checkVersion($revision !== false && (int) $revision === $pageVersion ? 1 : 0);
if ($operation === 'delete') {
- $query = $pdo->prepare('DELETE FROM sections WHERE page_slug = ? AND key = ? AND version = ?');
- $query->execute([$page, $key, $version]);
- self::checkVersion($query->rowCount());
+ self::deleteSection($pdo, $page, $key, $version);
self::touchPage($pdo, $page, structureChanged: true);
return;
}
- $query = $pdo->prepare('SELECT key, version FROM sections WHERE page_slug = ? ORDER BY position, key');
+ $query = $pdo->prepare("SELECT key, version FROM sections WHERE page_slug = ? AND style <> 'hero-links' ORDER BY position, key");
$query->execute([$page]);
$revisions = $query->fetchAll(PDO::FETCH_KEY_PAIR);
if (!array_key_exists($key, $revisions)) {
@@ -257,8 +264,8 @@ final class Repository
];
if ($id === null) {
$query = $pdo->prepare('INSERT INTO articles
- (slug, title, summary, body, body_format, card, tags, status, published_at, updated_at)
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
+ (id, slug, title, summary, body, body_format, card, tags, status, published_at, updated_at)
+ VALUES (' . Database::NEXT_ARTICLE_ID . ', ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
$query->execute($values);
$id = (int) $pdo->lastInsertId();
} else {
@@ -282,6 +289,22 @@ final class Repository
});
}
+ public function deleteArticle(int $id, int $version): void
+ {
+ Database::write(function (PDO $pdo) use ($id, $version): void {
+ // Keep the original seed slug even if the article has been renamed.
+ $deletions = $pdo->prepare('INSERT INTO article_deletions (slug, article_id)
+ SELECT slug, id FROM articles WHERE id = :id
+ UNION ALL SELECT slug, article_id FROM article_redirects WHERE article_id = :id
+ ON CONFLICT (slug) DO UPDATE SET article_id = excluded.article_id');
+ $deletions->execute(['id' => $id]);
+
+ $delete = $pdo->prepare('DELETE FROM articles WHERE id = ? AND version = ?');
+ $delete->execute([$id, $version]);
+ self::checkVersion($delete->rowCount());
+ });
+ }
+
public function sitemapArticles(): iterable
{
$query = $this->pdo->query("SELECT slug, updated_at FROM articles WHERE status = 'published'
diff --git a/app/Content/SiteDesign.php b/app/Content/SiteDesign.php
index 224edc9..1e6d061 100644
--- a/app/Content/SiteDesign.php
+++ b/app/Content/SiteDesign.php
@@ -12,7 +12,7 @@ final class SiteDesign
public const DEFAULT_HEADER = [
'logo' => '/assets/wordmark.webp', 'alt' => 'Laysense 来笙',
'links' => [['/', '首页'], ['/services', '产品与服务'], ['/articles', '动态'], ['/#about', '关于来笙']],
- 'button' => ['#contact', '联系来笙'],
+ 'button' => ['/contact', '联系来笙'],
];
public const DEFAULT_FOOTER = [
@@ -23,7 +23,7 @@ final class SiteDesign
'products_title' => '产品与服务',
'products' => [['/highspeaker', 'HighSpeaker DNS'], ['/pagepan', 'PAGEPAN'], ['/sc', '软著代理服务']],
'company_title' => '公司',
- 'company' => [['/#about', '关于来笙'], ['#contact', '联系来笙']],
+ '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']],
diff --git a/app/Controller/AdminController.php b/app/Controller/AdminController.php
index c9602ab..f28e7c4 100644
--- a/app/Controller/AdminController.php
+++ b/app/Controller/AdminController.php
@@ -135,6 +135,7 @@ class AdminController
return $this->render($request, 'admin-articles', [
'title' => '文章与动态', 'articles' => array_slice($articles, 0, 30), 'pageNumber' => $page,
'hasNext' => count($articles) > 30, 'categories' => $categories, 'category' => $category,
+ 'deleted' => $request->get('deleted') === '1',
]);
}
@@ -221,6 +222,21 @@ class AdminController
], $error !== '' ? 422 : 200);
}
+ public function deleteArticle(Request $request, string $id): Response
+ {
+ if ($failure = $this->guard($request)) {
+ return $failure;
+ }
+
+ try {
+ (new Repository())->deleteArticle((int) $id, $this->version($request));
+ } catch (RuntimeException $exception) {
+ return $this->error($request, $this->validationMessage($exception), $exception instanceof \PDOException ? 500 : 409);
+ }
+
+ return $this->success($request, '/admin/articles?deleted=1');
+ }
+
public function page(Request $request, string $slug): Response
{
if ($failure = $this->guard($request)) {
@@ -268,7 +284,7 @@ class AdminController
strlen($data['image']) > 1000 || ($data['image'] !== '' && !Html::url($data['image'], true)) || !$validButtons) {
throw new RuntimeException('请检查页面标题、说明、图片地址和按钮链接。');
}
- $sections = $this->canvasSections($request->post('canvas_sections', ''), $page['sections']);
+ $sections = $this->canvasSections($request->post('canvas_sections', ''), $page['sections'], $repo->categories());
$repo->savePage($slug, $data, $this->version($request), $sections);
return $this->success($request, '/admin/pages/' . $slug . '?saved=1');
@@ -278,7 +294,7 @@ class AdminController
}
return $this->render($request, 'admin-page', [
- 'title' => '编辑 ' . $page['name'], 'page' => $page, 'wideAdmin' => true, 'error' => $error, 'saved' => $request->get('saved') === '1',
+ 'title' => '编辑 ' . $page['name'], 'page' => $page, 'categories' => $repo->categories(), 'wideAdmin' => true, 'error' => $error, 'saved' => $request->get('saved') === '1',
], $error !== '' ? 422 : 200);
}
@@ -299,12 +315,12 @@ class AdminController
$data = [
'title' => $this->input($request, 'title'), 'lead' => $this->input($request, 'lead'),
'body' => $this->input($request, 'body'),
- 'style' => $request->post('style') === null ? $section['style'] : $this->input($request, 'style'),
+ 'style' => $savedStyle === 'hero-links' || $request->post('style') === null ? $savedStyle : $this->input($request, 'style'),
'feed' => $section['feed'],
];
$section = array_replace($section, $data, ['version' => $this->version($request)]);
try {
- if ($request->post('feed_mode') !== null) {
+ if ($savedStyle !== 'hero-links' && $request->post('feed_mode') !== null) {
$data['feed'] = $section['feed'] = $this->feedInput($request, $categories);
}
$this->checkSection($data, $savedStyle);
@@ -322,7 +338,7 @@ class AdminController
], $error !== '' ? 422 : 200);
}
- private function canvasSections(mixed $payload, array $sections): array
+ private function canvasSections(mixed $payload, array $sections, array $categories): array
{
if ($payload === '') {
return [];
@@ -336,15 +352,46 @@ class AdminController
foreach ($changes as $change) {
$key = $change['key'] ?? null;
$version = $change['version'] ?? null;
- $fields = $change['fields'] ?? null;
+ $fields = $change['fields'] ?? [];
$alignments = $change['alignments'] ?? null;
+ $feed = $change['feed'] ?? null;
+ $delete = ($change['delete'] ?? false) === true;
$isNew = is_array($change) && array_key_exists('version', $change) && $version === null;
- if (!is_string($key) || isset($updates[$key]) || !is_array($fields) || ($fields === [] && $alignments === null)
+ if (!is_string($key) || isset($updates[$key]) || !is_array($fields) || (!$delete && $fields === [] && $alignments === null && $feed === null)
|| ($isNew ? (isset($available[$key]) || !preg_match('/^block-[a-f0-9]{32}$/D', $key))
: (!isset($available[$key]) || !is_int($version) || $version !== (int) $available[$key]['version']))) {
throw new RuntimeException('区块已变更或画布内容无效,请重新打开编辑页。');
}
+ if ($delete) {
+ if ($isNew || empty($available[$key]['feed'])) {
+ throw new RuntimeException('此区块不能通过模块工具删除。');
+ }
+ $updates[$key] = compact('key', 'version', 'delete');
+ continue;
+ }
$section = $available[$key] ?? ['key' => $key, 'title' => '', 'lead' => '', 'body' => '', 'style' => 'plain'];
+ if ($isNew && isset($change['template'])) {
+ $preset = is_string($change['template']) ? BlockTemplates::find($change['template']) : null;
+ if ($preset === null) {
+ throw new RuntimeException('区块模板已失效。');
+ }
+ $section['feed'] = $preset[3] ?? null;
+ $section['style'] = $preset[4] ?? 'plain';
+ }
+ if ($isNew && isset($change['copyOf'])) {
+ $source = $change['copyOf']['key'] ?? null;
+ $sourceVersion = $change['copyOf']['version'] ?? null;
+ if (!is_string($source) || empty($available[$source]['feed']) || $sourceVersion !== (int) $available[$source]['version']) {
+ throw new RuntimeException('原模块已变更,请刷新画布后再复制。');
+ }
+ $section = array_replace($available[$source], ['key' => $key]);
+ }
+ if ($feed !== null) {
+ if (!is_array($feed) || empty($section['feed'])) {
+ throw new RuntimeException('模块设置不正确。');
+ }
+ $section['feed'] = $this->encodeFeed($feed['mode'] ?? null, $feed['categories'] ?? null, $feed['limit'] ?? null, $categories);
+ }
foreach ($fields as $field => $value) {
if (!in_array($field, ['title', 'lead', 'body'], true)) {
throw new RuntimeException('画布内容无效。');
@@ -364,9 +411,6 @@ class AdminController
if (isset($fields['body'])) {
$section['body'] = Html::sanitize($section['body']);
}
- if ($isNew && ($change['template'] ?? null) === 'articles') {
- $section['feed'] = BlockTemplates::ARTICLE_FEED;
- }
$section['version'] = $version;
$updates[$key] = $section;
}
@@ -546,9 +590,14 @@ class AdminController
if ($mode === 'off') {
return null;
}
- $categories = $this->selectedCategories($request->post('feed_categories'));
- $limit = filter_var($this->input($request, 'feed_limit'), FILTER_VALIDATE_INT, ['options' => ['min_range' => 1, 'max_range' => 30]]);
- if (!in_array($mode, ['merged', 'tabs'], true) || !$categories || array_diff($categories, array_keys($available)) || $limit === false) {
+ return $this->encodeFeed($mode, $request->post('feed_categories'), $this->input($request, 'feed_limit'), $available);
+ }
+
+ private function encodeFeed(mixed $mode, mixed $selected, mixed $value, array $available): string
+ {
+ $categories = $this->selectedCategories($selected);
+ $limit = filter_var($value, FILTER_VALIDATE_INT, ['options' => ['min_range' => 1, 'max_range' => 30]]);
+ if (!in_array($mode, ['merged', 'tabs', 'network', 'catalog'], true) || !$categories || array_diff($categories, array_keys($available)) || $limit === false) {
throw new RuntimeException('请选择文章分类,并将展示数量设为 1 至 30。');
}
diff --git a/app/Controller/SiteController.php b/app/Controller/SiteController.php
index 1e9585f..3737909 100644
--- a/app/Controller/SiteController.php
+++ b/app/Controller/SiteController.php
@@ -24,6 +24,16 @@ final class SiteController
if (!$page || $page['status'] !== 'published' || $slug === 'home' && $request->path() !== '/') {
return $this->missing($request);
}
+ if ($slug === 'articles' && $request->get('page') !== null) {
+ foreach ($page['sections'] as $section) {
+ $feed = json_decode($section['feed'] ?? '{}', true, flags: JSON_THROW_ON_ERROR);
+ if (in_array($feed['mode'] ?? null, ['merged', 'tabs'], true)) {
+ return $this->feedArchive($request, $slug, $section['key']);
+ }
+ }
+
+ return $this->missing($request);
+ }
return $this->renderPage($repo, $page);
}
@@ -37,14 +47,23 @@ final class SiteController
continue;
}
$feed = json_decode($section['feed'], true, flags: JSON_THROW_ON_ERROR);
- $tabs = $feed['mode'] === 'tabs' && count($feed['categories']) > 1;
+ $network = $feed['mode'] === 'network';
+ $catalog = $feed['mode'] === 'catalog';
+ $grouped = $network || ($feed['mode'] === 'tabs' && count($feed['categories']) > 1);
+ $archivePath = '/articles/feed/' . $slug . '/' . $section['key'];
+ if ($network && count($feed['categories']) === 2 && !array_diff($feed['categories'], ['supported-projects', 'partners'])) {
+ $archivePath = '/network';
+ }
+ $section['archivePath'] = $page['status'] === 'published' ? $archivePath : null;
$section['articleFeed'] = [];
- $section['archivePath'] = $page['status'] === 'published' ? '/articles/feed/' . $slug . '/' . $section['key'] : null;
- foreach ($tabs ? $feed['categories'] : [''] as $category) {
+ $section['networkFeed'] = $network;
+ $section['catalogFeed'] = $catalog;
+ $section['feedLimit'] = $feed['limit'];
+ foreach ($grouped ? $feed['categories'] : [''] as $category) {
$selected = $category === '' ? $feed['categories'] : [$category];
$section['articleFeed'][] = [
'categories' => $selected, 'label' => $categories[$category] ?? '',
- 'articles' => $repo->articles($selected, limit: $feed['limit']),
+ 'articles' => $repo->articles($selected, limit: $feed['limit'], directoryOrder: $network || $catalog),
];
}
}
@@ -58,23 +77,10 @@ final class SiteController
'description' => $page['description'],
'socialImage' => $page['image'],
'socialAlt' => $page['alt'],
- 'network' => $isHome ? $this->networkGroups($repo) : [],
'previewMode' => $preview, 'canvas' => $preview && $canvas, 'noindex' => $preview,
]);
}
- public function services(Request $request): Response
- {
- $repo = new Repository();
-
- return View::render('services', [
- 'site' => $repo->site(), 'path' => '/services',
- 'title' => '产品与服务 · 来笙 Laysense',
- 'description' => '浏览来笙的建站工具、智能 DNS 和软件著作权服务。',
- 'products' => $repo->articles('services', limit: -1, directoryOrder: true),
- ]);
- }
-
public function network(Request $request): Response
{
$repo = new Repository();
@@ -152,6 +158,7 @@ final class SiteController
'archivePath' => $category === null ? $allPath : $categoryLinks[$category], 'allPath' => $allPath,
'categoryLinks' => $categoryLinks, 'categories' => $categories, 'category' => $category, 'tag' => null,
'categoryScope' => $category === null ? array_keys($categories) : [$category],
+ 'catalog' => $feed['mode'] === 'catalog',
'backPath' => $returnPath, 'backLabel' => '返回原页面', 'noindex' => true,
]);
}
@@ -163,7 +170,7 @@ final class SiteController
return $this->missing($request);
}
$page = (int) $number;
- $articles = $repo->articles($category, $tag, limit: 21, offset: ($page - 1) * 20);
+ $articles = $repo->articles($category, $tag, limit: 21, offset: ($page - 1) * 20, directoryOrder: $view['catalog'] ?? false);
if ($page > 1 && $articles === []) {
return $this->missing($request);
}
@@ -235,11 +242,7 @@ final class SiteController
$repo = new Repository();
$xml = ['', ''];
$pages = $repo->pages(publishedOnly: true);
- $pages[] = ['slug' => 'services', 'updated_at' => null];
$pages[] = ['slug' => 'network', 'updated_at' => null];
- if ($repo->articles(limit: 1)) {
- $pages[] = ['slug' => 'articles', 'updated_at' => null];
- }
foreach ($pages as $page) {
$xml[] = $this->sitemapUrl($page['slug'] === 'home' ? '/' : '/' . $page['slug'], $page['updated_at']);
}
@@ -264,7 +267,7 @@ final class SiteController
$normal = rtrim($path, '/');
$single = preg_match('~^/[a-z0-9-]+$~D', $normal);
$known = $single && ((new Repository())->page(substr($normal, 1))['status'] ?? null) === 'published' && $normal !== '/home';
- if ($known || in_array($normal, ['/services', '/network'], true) || preg_match('~^/articles(?:/[a-z0-9-]+){0,2}$~D', $normal)) {
+ if ($known || $normal === '/network' || preg_match('~^/articles(?:/[a-z0-9-]+){1,2}$~D', $normal)) {
$query = $request->queryString();
return View::redirect($normal . ($query !== '' ? '?' . $query : ''), 301);
diff --git a/app/Controller/StudioController.php b/app/Controller/StudioController.php
index 00799a2..bae5cb6 100644
--- a/app/Controller/StudioController.php
+++ b/app/Controller/StudioController.php
@@ -27,7 +27,7 @@ final class StudioController extends AdminController
$data['name'] = $this->input($request, 'name');
$data['slug'] = $this->input($request, 'slug');
try {
- if (!$this->slug($data['slug']) || in_array($data['slug'], ['admin', 'assets', 'articles', 'home', 'services', 'network', 'news', 'main', 'favicon'], true)
+ if (!$this->slug($data['slug']) || in_array($data['slug'], ['admin', 'assets', 'home', 'network', 'news', 'main', 'favicon'], true)
|| $data['name'] === '' || mb_strlen($data['name']) > 100) {
throw new RuntimeException('请填写页面名称及可用的网址标识。');
}
@@ -74,7 +74,7 @@ final class StudioController extends AdminController
if ($preset === null) {
throw new RuntimeException('请选择区块类型。');
}
- $repo->createSection($slug, $key, $preset[0], 'plain', $preset[1], $type === 'articles' ? BlockTemplates::ARTICLE_FEED : null);
+ $repo->createSection($slug, $key, $preset[0], $preset[4] ?? 'plain', Html::sanitize($preset[1], $key), $preset[3] ?? null, $preset[2] ?? '');
return $this->success($request, "/admin/pages/$slug/$key");
}
diff --git a/app/view/admin-article.php b/app/view/admin-article.php
index ceb9e94..1d00a00 100644
--- a/app/view/admin-article.php
+++ b/app/view/admin-article.php
@@ -51,3 +51,14 @@ $e = View::escape(...);
+
+
+ 删除文章
+
+
+
diff --git a/app/view/admin-articles.php b/app/view/admin-articles.php
index cc13ab2..f314cd7 100644
--- a/app/view/admin-articles.php
+++ b/app/view/admin-articles.php
@@ -12,6 +12,7 @@ $filters = $category ? 'category=' . rawurlencode($category) . '&' : '';
新建文章
+文章已删除。
- = View::fragment('article-list', ['articles' => $articles, 'categoryScope' => $categoryScope ?? null]) ?>
+
+ = View::fragment('service-cards', ['products' => $articles]) ?>
+
+ = View::fragment('article-list', ['articles' => $articles, 'categoryScope' => $categoryScope ?? null]) ?>
+
1 || $hasNext): ?>