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
|
||||
|
||||
Reference in New Issue
Block a user