Migrate the Laysense production snapshot to LaySite 1.3
This commit is contained in:
@@ -9,6 +9,7 @@ use RuntimeException;
|
||||
final class Assets
|
||||
{
|
||||
public const DEFAULT_ICON = '/assets/system/laysite-mark.webp';
|
||||
public const SITE_ICON = '/assets/favicon.png';
|
||||
public const JQUERY = '/assets/jquery-4.0.0.min.js';
|
||||
public const TOAST_UI_EDITOR = '/assets/vendor/toastui/toastui-editor.min.js';
|
||||
|
||||
|
||||
@@ -8,9 +8,9 @@ final class BlockTemplates
|
||||
{
|
||||
public const ARTICLE_FEED = '{"categories":["announcement","news","product"],"mode":"merged","limit":6}';
|
||||
|
||||
public const NETWORK_FEED = '{"categories":["projects","partners"],"mode":"network","limit":30}';
|
||||
public const NETWORK_FEED = '{"categories":["supported-projects","partners"],"mode":"network","limit":30}';
|
||||
|
||||
public const CATALOG_FEED = '{"categories":["catalog"],"mode":"catalog","limit":30}';
|
||||
public const CATALOG_FEED = '{"categories":["services"],"mode":"catalog","limit":30}';
|
||||
|
||||
public const ELEMENT_GROUPS = [
|
||||
'text-elements' => ['文字与列表', [
|
||||
|
||||
+15
-10
@@ -62,6 +62,21 @@ final class Database
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($version < 4) {
|
||||
$columns = array_column($pdo->query('PRAGMA table_info(pages)')->fetchAll(), 'name');
|
||||
foreach (['header_id', 'footer_id', 'palette_id', 'layout_id'] as $column) {
|
||||
if (!in_array($column, $columns, true)) {
|
||||
$pdo->exec("ALTER TABLE pages ADD COLUMN $column INTEGER REFERENCES design_presets(id)");
|
||||
}
|
||||
}
|
||||
$pdo->exec('CREATE UNIQUE INDEX IF NOT EXISTS pages_layout_id ON pages(layout_id)');
|
||||
}
|
||||
if ($version < 6 && !in_array('page_type', array_column($pdo->query('PRAGMA table_info(pages)')->fetchAll(), 'name'), true)) {
|
||||
$pdo->exec("ALTER TABLE pages ADD COLUMN page_type TEXT NOT NULL DEFAULT 'page' CHECK (page_type IN ('page', 'maintenance', 'not-found'))");
|
||||
}
|
||||
if ($version === 0 && $pdo->query('SELECT id FROM site_settings WHERE id = 1')->fetchColumn() === false) {
|
||||
SiteSnapshot::install($pdo);
|
||||
}
|
||||
$pdo->prepare('INSERT OR IGNORE INTO site_settings (id, payload) VALUES (1, ?)')->execute([self::json(['name' => '我的网站'])]);
|
||||
$pdo->prepare("INSERT OR IGNORE INTO pages
|
||||
(slug, name, title, description, heading, accent, lead, image, alt, actions, quicklinks)
|
||||
@@ -82,16 +97,6 @@ final class Database
|
||||
if ($version < 2) {
|
||||
OAuthCredentials::migrateLegacy($pdo);
|
||||
}
|
||||
if ($version < 4) {
|
||||
$columns = $pdo->query('PRAGMA table_info(pages)')->fetchAll();
|
||||
if (!in_array('layout_id', array_column($columns, 'name'), true)) {
|
||||
$pdo->exec('ALTER TABLE pages ADD COLUMN layout_id INTEGER REFERENCES design_presets(id)');
|
||||
}
|
||||
$pdo->exec('CREATE UNIQUE INDEX IF NOT EXISTS pages_layout_id ON pages(layout_id)');
|
||||
}
|
||||
if ($version < 6 && !in_array('page_type', array_column($pdo->query('PRAGMA table_info(pages)')->fetchAll(), 'name'), true)) {
|
||||
$pdo->exec("ALTER TABLE pages ADD COLUMN page_type TEXT NOT NULL DEFAULT 'page' CHECK (page_type IN ('page', 'maintenance', 'not-found'))");
|
||||
}
|
||||
if ($version < 5) {
|
||||
LayoutPage::migrate($pdo);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ final class Html
|
||||
public const ALIGNMENTS = ['left', 'center', 'right'];
|
||||
|
||||
private const TAGS = [
|
||||
'a' => ['href', 'target', 'rel', 'aria-label'], 'article' => [], 'audio' => ['src', 'controls', 'preload'], 'b' => [], 'blockquote' => [], 'br' => [],
|
||||
'a' => ['href', 'target', 'rel', 'aria-label'], 'address' => [], 'article' => [], 'audio' => ['src', 'controls', 'preload'], 'b' => [], 'blockquote' => [], 'br' => [],
|
||||
'button' => ['aria-expanded', 'aria-controls', 'hidden'], 'caption' => [], 'code' => [], 'dd' => [], 'details' => [], 'div' => ['role', 'aria-label', 'tabindex'],
|
||||
'dl' => [], 'dt' => [], 'em' => [], 'figure' => [], 'figcaption' => [], 'footer' => [],
|
||||
'h1' => [], 'h2' => [], 'h3' => [], 'h4' => [], 'h5' => [], 'h6' => [], 'header' => [], 'hr' => [], 'i' => [],
|
||||
|
||||
@@ -6,6 +6,15 @@ 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;
|
||||
|
||||
@@ -10,7 +10,7 @@ use RuntimeException;
|
||||
final class Repository
|
||||
{
|
||||
public const DIRECTORIES = [
|
||||
'catalog' => '目录', 'projects' => '项目', 'partners' => '合作伙伴',
|
||||
'services' => '产品与服务', 'supported-projects' => '来笙支持项目', 'partners' => '来笙合作伙伴',
|
||||
];
|
||||
public const CATEGORIES = ['announcement' => '公告', 'news' => '新闻', 'product' => '产品'] + self::DIRECTORIES;
|
||||
private const ARTICLE_FIELDS = 'articles.*, (SELECT json_group_object(c.slug, c.name)
|
||||
|
||||
@@ -233,7 +233,7 @@ final class SiteBackup
|
||||
$tables['site_settings'] = [['id' => 1, 'payload' => Database::json($site)]];
|
||||
foreach ($tables['sections'] as &$row) {
|
||||
PageDraft::slug($row['key'] ?? null, ['home', 'contact', 'main-content', 'primary-navigation', 'preview']);
|
||||
if (!in_array($row['style'] ?? '', ['plain', 'tinted', 'hero-links', 'layout'], true)) {
|
||||
if (!in_array($row['style'] ?? '', ['plain', 'tinted', 'hero-links', 'layout', 'about', 'projects', 'demos'], true)) {
|
||||
throw new RuntimeException('备份包含未知区块样式。');
|
||||
}
|
||||
$row['body'] = Html::sanitize($row['body'] ?? '');
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Content;
|
||||
|
||||
use PDO;
|
||||
use Pdo\Sqlite;
|
||||
|
||||
final class SiteSnapshot
|
||||
{
|
||||
private const TABLES = [
|
||||
'site_settings', 'design_presets', 'pages', 'sections',
|
||||
'article_categories', 'articles', 'article_category_links',
|
||||
'article_redirects', 'article_deletions', 'media',
|
||||
];
|
||||
|
||||
public static function install(PDO $target): void
|
||||
{
|
||||
$readOnly = class_exists(Sqlite::class)
|
||||
? [Sqlite::ATTR_OPEN_FLAGS => Sqlite::OPEN_READONLY]
|
||||
: [PDO::SQLITE_ATTR_OPEN_FLAGS => PDO::SQLITE_OPEN_READONLY];
|
||||
$source = new PDO('sqlite:' . dirname(__DIR__, 2) . '/resources/laysense-site.sqlite',
|
||||
options: $readOnly + [PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC]);
|
||||
foreach (self::TABLES as $table) {
|
||||
$insert = null;
|
||||
foreach ($source->query('SELECT * FROM ' . $table) as $row) {
|
||||
$insert ??= $target->prepare(sprintf(
|
||||
'INSERT INTO %s (%s) VALUES (%s)',
|
||||
$table,
|
||||
implode(', ', array_keys($row)),
|
||||
implode(', ', array_fill(0, count($row), '?')),
|
||||
));
|
||||
$insert->execute(array_values($row));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -97,7 +97,7 @@ final class View
|
||||
|
||||
public static function absolute(string $path): string
|
||||
{
|
||||
return rtrim(Environment::get('LAYSITE_SITE_URL') ?: 'http://127.0.0.1:8787', '/') . $path;
|
||||
return rtrim(Environment::get('LAYSITE_SITE_URL') ?: 'https://laysense.cn', '/') . $path;
|
||||
}
|
||||
|
||||
public static function date(?string $value, string $format = 'Y年n月j日'): string
|
||||
|
||||
@@ -209,7 +209,29 @@ final class SiteController
|
||||
|
||||
public function favicon(Request $request): Response
|
||||
{
|
||||
return View::redirect(Assets::DEFAULT_ICON, 301);
|
||||
return View::redirect(Assets::SITE_ICON, 301);
|
||||
}
|
||||
|
||||
public function legacyArticle(Request $request, string $id): Response
|
||||
{
|
||||
$article = (new Repository())->legacyArticle('/news/id/' . $id . '.html');
|
||||
|
||||
return $article ? View::redirect('/articles/' . $article['slug'], 301) : $this->missing($request);
|
||||
}
|
||||
|
||||
public function legacyCategory(Request $request, string $id): Response
|
||||
{
|
||||
$target = [
|
||||
'1' => '/articles/category/product', '2' => '/articles/category/news', '3' => '/articles/category/announcement',
|
||||
'5' => '/#supported-projects', '6' => '/#partners',
|
||||
][$id] ?? null;
|
||||
|
||||
return $target ? View::redirect($target, 301) : $this->missing($request);
|
||||
}
|
||||
|
||||
public function legacyTag(Request $request, string $tag): Response
|
||||
{
|
||||
return View::redirect('/articles/tag/' . rawurlencode(rawurldecode($tag)), 301);
|
||||
}
|
||||
|
||||
public function canvasStyle(Request $request): Response
|
||||
|
||||
+5
-4
@@ -6,7 +6,7 @@ use App\Content\DesignLibrary;
|
||||
|
||||
$e = View::escape(...);
|
||||
$canonical = $path !== null && empty($previewMode) ? View::absolute($path) : null;
|
||||
$imageUrl = !empty($socialImage) ? Assets::url($socialImage, $cdn) : '';
|
||||
$imageUrl = Assets::url(($socialImage ?? '') ?: '/assets/original/home-hero.webp', $cdn);
|
||||
if (str_starts_with($imageUrl, '/')) {
|
||||
$imageUrl = View::absolute($imageUrl);
|
||||
}
|
||||
@@ -21,7 +21,7 @@ $showFooter = $page['visibility']['footer'] ?? true;
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title><?= $e($title) ?></title>
|
||||
<link rel="icon" href="<?= $e(Assets::DEFAULT_ICON) ?>" type="image/webp">
|
||||
<link rel="icon" href="<?= $e(Assets::SITE_ICON) ?>" type="image/png">
|
||||
<meta name="description" content="<?= $e($description) ?>">
|
||||
<meta name="theme-color" content="#f5f7fb">
|
||||
<?php if ($canonical): ?>
|
||||
@@ -36,7 +36,7 @@ $showFooter = $page['visibility']['footer'] ?? true;
|
||||
<meta property="og:description" content="<?= $e($description) ?>">
|
||||
<?php if ($imageUrl !== ''): ?>
|
||||
<meta property="og:image" content="<?= $e($imageUrl) ?>">
|
||||
<meta property="og:image:alt" content="<?= $e($socialAlt ?? '') ?>">
|
||||
<meta property="og:image:alt" content="<?= $e(($socialAlt ?? '') ?: '来笙 Laysense') ?>">
|
||||
<?php endif ?>
|
||||
<?php if (isset($article)): ?>
|
||||
<meta property="article:published_time" content="<?= $e(View::date($article['published_at'], DATE_ATOM)) ?>">
|
||||
@@ -44,13 +44,14 @@ $showFooter = $page['visibility']['footer'] ?? true;
|
||||
<?php endif ?>
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<link rel="stylesheet" href="/assets/site.css">
|
||||
<link rel="stylesheet" href="/assets/laysense.css">
|
||||
<?php if (!empty($canvas) || str_contains($content . ($headerMarkup ?? '') . ($footerMarkup ?? ''), 'studio-style-')): ?><link rel="stylesheet" href="<?= $e(CanvasStyle::stylesheetUrl()) ?>"><?php endif ?>
|
||||
<?php if ($theme !== ''): ?><link rel="stylesheet" href="/assets/page-themes.css"><?php endif ?>
|
||||
<?php if ($palette): ?><link rel="stylesheet" data-page-palette href="/palette/<?= $e($palette['id']) ?>.css?v=<?= $e($palette['version']) ?>"><?php endif ?>
|
||||
<script src="<?= $e(Assets::JQUERY) ?>" defer></script>
|
||||
<script src="/assets/site.js" defer></script>
|
||||
</head>
|
||||
<body>
|
||||
<body<?= in_array($page['slug'] ?? '', ['sc', 'shnu-sc'], true) ? ' class="copyright-service"' : '' ?>>
|
||||
<a class="skip-link" href="#main-content">跳到内容</a>
|
||||
<?php if (empty($page['layout_kind']) && ($showHeader || !empty($canvas))): ?>
|
||||
<?php if (isset($headerMarkup)): ?><div role="banner" data-site-area="header"<?= $showHeader ? '' : ' hidden' ?>><?= $headerMarkup ?></div>
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<svg class="home-pipe-flow" viewBox="0 0 640 480" aria-hidden="true" focusable="false">
|
||||
<defs>
|
||||
<path id="hero-pipe-tower" pathLength="100" d="M174 347 241 312 Q246 310 246 305 L246 299 Q246 295 252 293 L273 282"/>
|
||||
<path id="hero-pipe-disk" pathLength="100" d="M409 282 428 293 Q433 296 433 300 L433 304 Q433 307 438 309 L500 337"/>
|
||||
<path id="hero-pipe-node" pathLength="100" d="M119 201 125 205 Q129 207 129 212 L129 214 Q130 217 134 219 L190 243"/>
|
||||
<path id="hero-pipe-chart" pathLength="100" d="M443 226 471 213 Q478 208 483 209 L488 207 Q492 205 492 200 L492 182"/>
|
||||
</defs>
|
||||
<g class="home-pipe-route"><use href="#hero-pipe-tower"/><use href="#hero-pipe-tower"/></g>
|
||||
<g class="home-pipe-route"><use href="#hero-pipe-disk"/><use href="#hero-pipe-disk"/></g>
|
||||
<g class="home-pipe-route"><use href="#hero-pipe-node"/><use href="#hero-pipe-node"/></g>
|
||||
<g class="home-pipe-route"><use href="#hero-pipe-chart"/><use href="#hero-pipe-chart"/></g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1004 B |
+11
-3
@@ -1,10 +1,12 @@
|
||||
<?php
|
||||
use App\Content\Buttons;
|
||||
use App\Content\CanvasStyle;
|
||||
use App\Content\PageTemplates;
|
||||
use App\Content\View;
|
||||
|
||||
$e = View::escape(...);
|
||||
$home = $page['slug'] === 'home';
|
||||
$service = in_array($page['slug'], ['sc', 'shnu-sc'], true);
|
||||
$shared = !empty($page['layout_kind']);
|
||||
$system = ($page['page_type'] ?? 'page') !== 'page';
|
||||
$showHero = $page['visibility']['hero'] ?? true;
|
||||
@@ -38,7 +40,7 @@ $field = static fn (string $name): string => $canvas ? ' data-studio-field="' .
|
||||
<?php else: ?>
|
||||
<p class="overline hero-label"><?= $e($site['name']) ?></p>
|
||||
<?php endif ?>
|
||||
<h1<?= isset($alignments['heading']) ? ' class="' . trim(View::alignmentClass($alignments['heading'])) . '"' : '' ?><?= $alignField('heading') ?>><span class="hero-heading-primary<?= $style('heading') ?>"<?= $field('heading') ?><?= $styleField('heading') ?>><?= $text('heading', $page['heading']) ?></span><?php if ($canvas): ?><span class="studio-accent<?= $style('accent') ?>"<?= $field('accent') ?><?= $styleField('accent') ?>><?= $text('accent', $page['accent']) ?></span><?php elseif ($page['accent'] !== ''): ?><br><span class="<?= trim($style('accent')) ?>"><?= $text('accent', $page['accent']) ?></span><?php endif ?></h1>
|
||||
<h1<?= isset($alignments['heading']) ? ' class="' . trim(View::alignmentClass($alignments['heading'])) . '"' : '' ?><?= $alignField('heading') ?>><span class="hero-heading-primary<?= $style('heading') ?>"<?= $field('heading') ?><?= $styleField('heading') ?>><?= $text('heading', $page['heading']) ?></span><?php if ($canvas): ?><span class="studio-accent<?= $style('accent') ?>"<?= $field('accent') ?><?= $styleField('accent') ?>><?= $text('accent', $page['accent']) ?></span><?php elseif ($page['accent'] !== ''): ?><br><span class="<?= trim($style('accent')) ?>"><?= $text('accent', $page['accent']) ?></span><?php endif ?><?php if ($home && !$canvas): ?><span class="home-cursor" aria-hidden="true">_</span><?php endif ?></h1>
|
||||
<p class="hero-lead<?= View::alignmentClass($alignments['lead'] ?? null) ?><?= $style('lead') ?>"<?= $field('lead') ?><?= $alignField('lead') ?><?= $styleField('lead') ?>><?= $text('lead', $page['lead']) ?></p>
|
||||
<div class="actions hero-actions<?= View::alignmentClass($alignments['actions'] ?? null) ?><?= $style('actions') ?>"<?= $alignField('actions') ?><?= $styleField('actions') ?>>
|
||||
<?php foreach (Buttons::validate($page['actions']) as $index => [$url, $label, $buttonStyle, $blank]): ?>
|
||||
@@ -48,8 +50,9 @@ $field = static fn (string $name): string => $canvas ? ' data-studio-field="' .
|
||||
</div>
|
||||
</div>
|
||||
<?php if ($canvas || $page['image'] !== ''): ?>
|
||||
<div class="hero-visual app-frame<?= $page['image_scale'] ? ' studio-media-' . $e($page['image_scale']) : '' ?><?= View::alignmentClass($alignments['image'] ?? null) ?><?= $style('image') ?>" data-visual<?= $alignField('image') ?><?= $styleField('image') ?><?= $page['image'] === '' ? ' hidden' : '' ?>>
|
||||
<div class="hero-visual <?= $home ? 'hero-illustration' : ($service ? 'app-frame hero-service-art' : 'app-frame') ?><?= $page['image_scale'] ? ' studio-media-' . $e($page['image_scale']) : '' ?><?= View::alignmentClass($alignments['image'] ?? null) ?><?= $style('image') ?>" data-visual<?= $alignField('image') ?><?= $styleField('image') ?><?= $page['image'] === '' ? ' hidden' : '' ?>>
|
||||
<img<?= $page['image'] === '' ? '' : ' src="' . $e($page['image']) . '"' ?> alt="<?= $e($page['alt']) ?>" width="1448" height="1086" fetchpriority="high"<?= $canvas ? ' data-studio-hero-image' : '' ?>>
|
||||
<?php if ($home && !$canvas && $page['image'] === '/assets/original/home-hero.webp'): ?><?= View::fragment('laysense-home-motion') ?><?php endif ?>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
@@ -71,9 +74,14 @@ $field = static fn (string $name): string => $canvas ? ' data-studio-field="' .
|
||||
<?php endif ?>
|
||||
<?php foreach ($page['sections'] as $section): ?>
|
||||
<?php if ($section['style'] !== 'hero-links'): ?>
|
||||
<?= View::fragment('section', ['section' => $section, 'moment' => false, 'canvas' => $canvas, 'pageSlug' => $page['slug']]) ?>
|
||||
<?= View::fragment('section', ['section' => $section, 'moment' => $home && $section['key'] === 'about', 'canvas' => $canvas, 'pageSlug' => $page['slug']]) ?>
|
||||
<?php endif ?>
|
||||
<?php endforeach ?>
|
||||
<?php if ($showHero && ($credit = PageTemplates::photoCredit($page['image']))): ?>
|
||||
<p class="wrap page-photo-credit">摄影 <a href="<?= $e($credit[2]) ?>"><?= $e($credit[0]) ?></a> ·
|
||||
<?php if ($credit[3]): ?><a href="<?= $e($credit[3]) ?>"><?= $e($credit[1]) ?></a><?php else: ?><?= $e($credit[1]) ?><?php endif ?>
|
||||
</p>
|
||||
<?php endif ?>
|
||||
<?php if ($canvas): ?>
|
||||
<?php if ($shared): ?>
|
||||
<p class="wrap studio-layout-empty" data-studio-empty-layout hidden>从「组件」添加版式,或在页面设置中显示首屏。</p>
|
||||
|
||||
@@ -48,10 +48,10 @@ $catalog = $section['catalogFeed'] ?? false;
|
||||
</div>
|
||||
<?php if ($network): ?>
|
||||
<?php foreach ($section['articleFeed'] as $group): ?>
|
||||
<?php $slug = $group['categories'][0]; $anchor = ($pageSlug ?? '') === 'home' && $section['key'] === 'network' ? $slug : $section['key'] . '-group-' . $slug; ?>
|
||||
<?php $slug = $group['categories'][0]; $anchor = in_array($pageSlug ?? '', ['home', 'network'], true) && $section['key'] === 'network' ? $slug : $section['key'] . '-group-' . $slug; ?>
|
||||
<div class="network-group" id="<?= $e($anchor) ?>">
|
||||
<h3><?= $e($group['label']) ?></h3>
|
||||
<?= View::fragment('network-items', ['articles' => $group['articles'], 'standalone' => false]) ?>
|
||||
<?= View::fragment('network-items', ['articles' => $group['articles'], 'standalone' => ($pageSlug ?? '') === 'network']) ?>
|
||||
</div>
|
||||
<?php endforeach ?>
|
||||
<?php if ($section['archivePath'] !== null): ?><p class="article-feed-archive"><a class="back-link" href="<?= $e($section['archivePath']) ?>">查看全部</a></p><?php endif ?>
|
||||
|
||||
Reference in New Issue
Block a user