forked from laysense/laysense.cn
Make catalog and article landing pages editable
This commit is contained in:
@@ -581,7 +581,7 @@ class AdminController
|
||||
{
|
||||
$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'], true) || !$categories || array_diff($categories, array_keys($available)) || $limit === false) {
|
||||
if (!in_array($mode, ['merged', 'tabs', 'network', 'catalog'], true) || !$categories || array_diff($categories, array_keys($available)) || $limit === false) {
|
||||
throw new RuntimeException('请选择文章分类,并将展示数量设为 1 至 30。');
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -38,6 +48,7 @@ final class SiteController
|
||||
}
|
||||
$feed = json_decode($section['feed'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$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'])) {
|
||||
@@ -46,11 +57,13 @@ final class SiteController
|
||||
$section['archivePath'] = $page['status'] === 'published' ? $archivePath : null;
|
||||
$section['articleFeed'] = [];
|
||||
$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'], directoryOrder: $network),
|
||||
'articles' => $repo->articles($selected, limit: $feed['limit'], directoryOrder: $network || $catalog),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -68,18 +81,6 @@ final class SiteController
|
||||
]);
|
||||
}
|
||||
|
||||
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();
|
||||
@@ -157,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,
|
||||
]);
|
||||
}
|
||||
@@ -168,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);
|
||||
}
|
||||
@@ -240,11 +242,7 @@ final class SiteController
|
||||
$repo = new Repository();
|
||||
$xml = ['<?xml version="1.0" encoding="UTF-8"?>', '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'];
|
||||
$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']);
|
||||
}
|
||||
@@ -269,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);
|
||||
|
||||
@@ -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('请填写页面名称及可用的网址标识。');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user