Files
laysense.cn/app/Content/PageTemplates.php
T

50 lines
1.8 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Content;
final class PageTemplates
{
public static function photoCredit(string $image): ?array
{
return match ($image) {
'/assets/page-templates/studio-letterpress.webp' => ['Adam Lusch', 'CC BY-SA 2.0', 'https://commons.wikimedia.org/wiki/File:Wood_Type_close-up.jpg', 'https://creativecommons.org/licenses/by-sa/2.0/'],
'/assets/page-templates/dusk-dunes.webp' => ['Bob Wick / BLM Utah', '公有领域', 'https://commons.wikimedia.org/wiki/File:Utah_Dunes_Landscape_-_West_Desert_District.jpg', null],
default => null,
};
}
public static function groups(): array
{
static $groups;
return $groups ??= require dirname(__DIR__, 2) . '/resources/page-templates.php';
}
public static function find(string $key): ?array
{
foreach (self::groups() as $theme => $group) {
if (!isset($group['pages'][$key])) {
continue;
}
$template = $group['pages'][$key];
$sections = [];
$quicklinks = [];
foreach ($template['sections'] as [$anchor, $title, $style, $body, $feed]) {
$sections[] = ['key' => $anchor, 'title' => $title, 'style' => $style, 'body' => Html::sanitize($body, $anchor),
'lead' => '', 'feed' => $feed, 'alignments' => '{}', 'version' => 0];
$quicklinks[] = ['#' . $anchor, $title];
}
return array_replace($template, [
'slug' => $key, 'theme' => $theme, 'title' => $template['name'], 'accent' => '',
'lead' => $template['description'], 'quicklinks' => $quicklinks, 'status' => 'draft',
'alignments' => [], 'image_scale' => 0, 'sections' => $sections,
]);
}
return null;
}
}