Scope article feeds and expand canvas editing
This commit is contained in:
@@ -39,10 +39,12 @@ final class SiteController
|
||||
$feed = json_decode($section['feed'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$tabs = $feed['mode'] === 'tabs' && count($feed['categories']) > 1;
|
||||
$section['articleFeed'] = [];
|
||||
$section['archivePath'] = $page['status'] === 'published' ? '/articles/feed/' . $slug . '/' . $section['key'] : null;
|
||||
foreach ($tabs ? $feed['categories'] : [''] as $category) {
|
||||
$selected = $category === '' ? $feed['categories'] : [$category];
|
||||
$section['articleFeed'][] = [
|
||||
'label' => $categories[$category] ?? '',
|
||||
'articles' => $repo->articles($category === '' ? $feed['categories'] : $category, limit: $feed['limit']),
|
||||
'categories' => $selected, 'label' => $categories[$category] ?? '',
|
||||
'articles' => $repo->articles($selected, limit: $feed['limit']),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -102,6 +104,60 @@ final class SiteController
|
||||
}
|
||||
$title = $category ? $categories[$category] : ($tag ?: '来笙动态');
|
||||
$path = '/articles' . ($category ? '/category/' . $category : ($tag ? '/tag/' . rawurlencode($tag) : ''));
|
||||
|
||||
$categoryLinks = [];
|
||||
foreach (array_keys($categories) as $key) {
|
||||
$categoryLinks[$key] = '/articles/category/' . $key;
|
||||
}
|
||||
|
||||
return $this->renderArchive($request, $repo, $category, $tag, [
|
||||
'headline' => $title, 'description' => '查看来笙的公告、新闻和产品动态。',
|
||||
'archivePath' => $path, 'allPath' => '/articles',
|
||||
'categoryLinks' => $categoryLinks,
|
||||
'categories' => $categories, 'category' => $category, 'tag' => $tag,
|
||||
'backPath' => $category || $tag ? '/articles' : null, 'backLabel' => '全部动态',
|
||||
]);
|
||||
}
|
||||
|
||||
public function feedArchive(Request $request, string $slug, string $key): Response
|
||||
{
|
||||
$repo = new Repository();
|
||||
$section = $repo->publishedFeed($slug, $key);
|
||||
if (!$section) {
|
||||
return $this->missing($request);
|
||||
}
|
||||
$feed = json_decode($section['feed'], true, flags: JSON_THROW_ON_ERROR);
|
||||
$labels = $repo->categories();
|
||||
$categories = [];
|
||||
foreach ($feed['categories'] as $value) {
|
||||
if (isset($labels[$value])) {
|
||||
$categories[$value] = $labels[$value];
|
||||
}
|
||||
}
|
||||
$category = $request->get('category');
|
||||
if (!$categories || ($category !== null && (!is_string($category) || !isset($categories[$category])))) {
|
||||
return $this->missing($request);
|
||||
}
|
||||
|
||||
$allPath = '/articles/feed/' . $slug . '/' . $key;
|
||||
$returnPath = ($slug === 'home' ? '/' : '/' . $slug) . '#' . $key;
|
||||
$categoryLinks = [];
|
||||
foreach (array_keys($categories) as $value) {
|
||||
$categoryLinks[$value] = $allPath . '?category=' . rawurlencode((string) $value);
|
||||
}
|
||||
|
||||
return $this->renderArchive($request, $repo, $category ?? array_keys($categories), null, [
|
||||
'headline' => $section['title'] . ($category !== null ? ' · ' . $categories[$category] : ''),
|
||||
'description' => '查看' . implode('、', $categories) . '分类下的文章。',
|
||||
'archivePath' => $category === null ? $allPath : $categoryLinks[$category], 'allPath' => $allPath,
|
||||
'categoryLinks' => $categoryLinks, 'categories' => $categories, 'category' => $category, 'tag' => null,
|
||||
'categoryScope' => $category === null ? array_keys($categories) : [$category],
|
||||
'backPath' => $returnPath, 'backLabel' => '返回原页面', 'noindex' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
private function renderArchive(Request $request, Repository $repo, string|array|null $category, ?string $tag, array $view): Response
|
||||
{
|
||||
$number = $request->get('page', '1');
|
||||
if (!is_scalar($number) || !preg_match('/^[1-9][0-9]{0,4}$/D', (string) $number)) {
|
||||
return $this->missing($request);
|
||||
@@ -111,13 +167,12 @@ final class SiteController
|
||||
if ($page > 1 && $articles === []) {
|
||||
return $this->missing($request);
|
||||
}
|
||||
$path = $view['archivePath'];
|
||||
|
||||
return View::render('archive', [
|
||||
'site' => $repo->site(), 'title' => $title . ' · 来笙', 'headline' => $title,
|
||||
'description' => '查看来笙的公告、新闻和产品动态。',
|
||||
'path' => $path . ($page > 1 ? '?page=' . $page : ''), 'archivePath' => $path,
|
||||
'categories' => $categories, 'category' => $category, 'tag' => $tag, 'pageNumber' => $page,
|
||||
'hasNext' => count($articles) > 20, 'articles' => array_slice($articles, 0, 20),
|
||||
return View::render('archive', $view + [
|
||||
'site' => $repo->site(), 'title' => $view['headline'] . ' · 来笙',
|
||||
'path' => $page > 1 ? View::archivePage($path, $page) : $path,
|
||||
'pageNumber' => $page, 'hasNext' => count($articles) > 20, 'articles' => array_slice($articles, 0, 20),
|
||||
'noindex' => $articles === [],
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user