Add canvas element tools and categorized article editing
This commit is contained in:
@@ -6,7 +6,6 @@ namespace App\Controller;
|
||||
|
||||
use App\Content\Html;
|
||||
use App\Content\Repository;
|
||||
use App\Content\SiteDesign;
|
||||
use App\Content\View;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
@@ -32,6 +31,22 @@ final class SiteController
|
||||
{
|
||||
$slug = $page['slug'];
|
||||
$isHome = $slug === 'home';
|
||||
$categories = $repo->categories();
|
||||
foreach ($page['sections'] as &$section) {
|
||||
if (!$section['feed']) {
|
||||
continue;
|
||||
}
|
||||
$feed = json_decode($section['feed'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$tabs = $feed['mode'] === 'tabs' && count($feed['categories']) > 1;
|
||||
$section['articleFeed'] = [];
|
||||
foreach ($tabs ? $feed['categories'] : [''] as $category) {
|
||||
$section['articleFeed'][] = [
|
||||
'label' => $categories[$category] ?? '',
|
||||
'articles' => $repo->articles($category === '' ? $feed['categories'] : $category, limit: $feed['limit']),
|
||||
];
|
||||
}
|
||||
}
|
||||
unset($section);
|
||||
|
||||
return View::render('page', [
|
||||
'site' => $repo->site(),
|
||||
@@ -41,25 +56,51 @@ final class SiteController
|
||||
'description' => $page['description'],
|
||||
'socialImage' => $page['image'],
|
||||
'socialAlt' => $page['alt'],
|
||||
'articles' => $isHome ? $repo->articles(limit: 3) : [],
|
||||
'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' => (new Repository())->site(), 'path' => '/services',
|
||||
'site' => $repo->site(), 'path' => '/services',
|
||||
'title' => '产品与服务 · 来笙 Laysense',
|
||||
'description' => '浏览来笙的建站工具、智能 DNS 和软件著作权服务。',
|
||||
'products' => SiteDesign::catalog(),
|
||||
'products' => $repo->articles('services', limit: -1, directoryOrder: true),
|
||||
]);
|
||||
}
|
||||
|
||||
public function network(Request $request): Response
|
||||
{
|
||||
$repo = new Repository();
|
||||
|
||||
return View::render('network', [
|
||||
'site' => $repo->site(), 'path' => '/network', 'title' => '支持项目与合作伙伴 · 来笙',
|
||||
'description' => '浏览来笙支持的开源项目和合作伙伴。', 'network' => $this->networkGroups($repo),
|
||||
]);
|
||||
}
|
||||
|
||||
private function networkGroups(Repository $repo): array
|
||||
{
|
||||
$groups = [];
|
||||
foreach (array_diff_key(Repository::DIRECTORIES, ['services' => true]) as $slug => $name) {
|
||||
$groups[$slug] = ['name' => $name, 'articles' => $repo->articles($slug, limit: -1, directoryOrder: true)];
|
||||
}
|
||||
|
||||
return $groups;
|
||||
}
|
||||
|
||||
public function archive(Request $request, ?string $category = null, ?string $tag = null): Response
|
||||
{
|
||||
$repo = new Repository();
|
||||
$title = $category ? Repository::CATEGORIES[$category] : ($tag ?: '来笙动态');
|
||||
$categories = $repo->categories();
|
||||
if ($category !== null && !isset($categories[$category])) {
|
||||
return $this->missing($request);
|
||||
}
|
||||
$title = $category ? $categories[$category] : ($tag ?: '来笙动态');
|
||||
$path = '/articles' . ($category ? '/category/' . $category : ($tag ? '/tag/' . rawurlencode($tag) : ''));
|
||||
$number = $request->get('page', '1');
|
||||
if (!is_scalar($number) || !preg_match('/^[1-9][0-9]{0,4}$/D', (string) $number)) {
|
||||
@@ -75,7 +116,7 @@ final class SiteController
|
||||
'site' => $repo->site(), 'title' => $title . ' · 来笙', 'headline' => $title,
|
||||
'description' => '查看来笙的公告、新闻和产品动态。',
|
||||
'path' => $path . ($page > 1 ? '?page=' . $page : ''), 'archivePath' => $path,
|
||||
'category' => $category, 'tag' => $tag, 'pageNumber' => $page,
|
||||
'categories' => $categories, 'category' => $category, 'tag' => $tag, 'pageNumber' => $page,
|
||||
'hasNext' => count($articles) > 20, 'articles' => array_slice($articles, 0, 20),
|
||||
'noindex' => $articles === [],
|
||||
]);
|
||||
@@ -100,13 +141,15 @@ final class SiteController
|
||||
|
||||
return $redirect ? View::redirect('/articles/' . $redirect['slug'], 301) : $this->missing($request);
|
||||
}
|
||||
$articleHtml = Html::markdown($article['body']);
|
||||
$articleHtml = Html::articleBody($article);
|
||||
|
||||
return View::render('article', [
|
||||
'site' => $repo->site(), 'article' => $article, 'articleHtml' => $articleHtml,
|
||||
'title' => $article['title'] . ' · 来笙',
|
||||
'description' => $article['summary'] ?: mb_substr(trim(strip_tags($articleHtml)), 0, 150) ?: $article['title'],
|
||||
'path' => '/articles/' . $article['slug'], 'noindex' => trim($articleHtml) === '',
|
||||
'path' => '/articles/' . $article['slug'],
|
||||
'socialImage' => $article['card']['image'] ?? '', 'socialAlt' => $article['card']['alt'] ?? '',
|
||||
'noindex' => trim($articleHtml) === '' && !$article['summary'] && empty($article['card']['url']) && empty($article['card']['image']),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -138,6 +181,7 @@ final class SiteController
|
||||
$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];
|
||||
}
|
||||
@@ -165,7 +209,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 || $normal === '/services' || preg_match('~^/articles(?:/[a-z0-9-]+){0,2}$~D', $normal)) {
|
||||
if ($known || in_array($normal, ['/services', '/network'], true) || preg_match('~^/articles(?:/[a-z0-9-]+){0,2}$~D', $normal)) {
|
||||
$query = $request->queryString();
|
||||
|
||||
return View::redirect($normal . ($query !== '' ? '?' . $query : ''), 301);
|
||||
|
||||
Reference in New Issue
Block a user