forked from laysense/laysite
Prepare LaySite 1.5.1 page routing and template updates
This commit is contained in:
@@ -19,7 +19,11 @@ final class SiteController
|
||||
{
|
||||
public function home(Request $request): Response
|
||||
{
|
||||
return $this->page($request, 'home');
|
||||
$repo = new Repository();
|
||||
$page = $repo->homepage();
|
||||
$response = $page ? $this->renderPage($repo, $page, root: true) : $this->missing($request);
|
||||
|
||||
return $response->withHeader('Cache-Control', 'no-store');
|
||||
}
|
||||
|
||||
public function license(Request $request): Response
|
||||
@@ -35,8 +39,8 @@ final class SiteController
|
||||
{
|
||||
$repo = new Repository();
|
||||
$page = $repo->page($slug);
|
||||
if (!$page || $page['layout_kind'] !== null || $page['page_type'] !== 'page'
|
||||
|| $page['status'] !== 'published' || $slug === 'home' && $request->path() !== '/') {
|
||||
if (!$page || $page['layout_kind'] !== null || !in_array($page['page_type'], ['page', 'home'], true)
|
||||
|| $page['status'] !== 'published') {
|
||||
return $this->missing($request);
|
||||
}
|
||||
if ($slug === 'articles' && $request->get('page') !== null) {
|
||||
@@ -52,17 +56,17 @@ final class SiteController
|
||||
return $this->renderPage($repo, $page);
|
||||
}
|
||||
|
||||
public function renderPage(Repository $repo, array $page, bool $preview = false, bool $canvas = false, int $status = 200): Response
|
||||
public function renderPage(Repository $repo, array $page, bool $preview = false, bool $canvas = false, int $status = 200, bool $root = false): Response
|
||||
{
|
||||
$slug = $page['slug'];
|
||||
$isHome = $slug === 'home';
|
||||
$showHero = $page['visibility']['hero'] ?? true;
|
||||
$page = $repo->withSectionFeeds($page);
|
||||
|
||||
return View::render('page', [
|
||||
'site' => $repo->site(),
|
||||
'page' => $page,
|
||||
'path' => ($page['page_type'] ?? 'page') !== 'page' ? null : ($isHome ? '/' : '/' . $slug),
|
||||
'path' => empty($page['layout_kind']) && in_array($page['page_type'] ?? 'page', ['page', 'home'], true)
|
||||
? ($root ? '/' : '/' . $slug) : null,
|
||||
'title' => $page['title'],
|
||||
'description' => $page['description'],
|
||||
'socialImage' => $showHero ? $page['image'] : '',
|
||||
@@ -116,7 +120,7 @@ final class SiteController
|
||||
}
|
||||
|
||||
$allPath = '/articles/feed/' . $slug . '/' . $key;
|
||||
$returnPath = ($slug === 'home' ? '/' : '/' . $slug) . '#' . $key;
|
||||
$returnPath = '/' . $slug . '#' . $key;
|
||||
$categoryLinks = [];
|
||||
foreach (array_keys($categories) as $value) {
|
||||
$categoryLinks[$value] = $allPath . '?category=' . rawurlencode((string) $value);
|
||||
@@ -190,8 +194,11 @@ 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);
|
||||
if (in_array('home', array_column($pages, 'page_type'), true)) {
|
||||
$xml[] = $this->sitemapUrl('/', null);
|
||||
}
|
||||
foreach ($pages as $page) {
|
||||
$xml[] = $this->sitemapUrl($page['slug'] === 'home' ? '/' : '/' . $page['slug'], $page['updated_at']);
|
||||
$xml[] = $this->sitemapUrl('/' . $page['slug'], $page['updated_at']);
|
||||
}
|
||||
foreach ($repo->sitemapArticles() as $article) {
|
||||
$xml[] = $this->sitemapUrl('/articles/' . $article['slug'], $article['updated_at']);
|
||||
@@ -231,7 +238,8 @@ final class SiteController
|
||||
$entry = preg_match('~^/(?:admin|account)(?:/|$)~D', $normal)
|
||||
&& Route::dispatch($request->method(), $normal)[0] === Dispatcher::FOUND;
|
||||
$single = preg_match('~^/[a-z0-9]+(?:-[a-z0-9]+)*$~D', $normal);
|
||||
if ($entry || ($single && $normal !== '/home' && ((new Repository())->page(substr($normal, 1))['status'] ?? null) === 'published')
|
||||
$page = $single ? (new Repository())->page(substr($normal, 1)) : null;
|
||||
if ($entry || ($page && $page['layout_kind'] === null && in_array($page['page_type'], ['page', 'home'], true) && $page['status'] === 'published')
|
||||
|| preg_match('~^/articles(?:/[a-z0-9-]+){1,2}$~D', $normal)) {
|
||||
$query = $request->queryString();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user