1 Commits
Author SHA1 Message Date
ChatGPT 04cac36b83 Check upstream versions and label article-driven components 2026-11-25 22:57:47 +08:00
14 changed files with 123 additions and 11 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
LaySite: anothor AI website builder LaySite: another AI website builder
Copyright (C) 2026 Shanghai Laysense Information Technology Co. Ltd. <Laysense.cn> Copyright (C) 2026 Shanghai Laysense Information Technology Co. Ltd. <Laysense.cn>
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
+3 -1
View File
@@ -106,7 +106,9 @@ php bin/backup.php export /srv/backups/laysite-2026-11.tar
php bin/backup.php import /srv/backups/laysite-2026-11.tar --replace php bin/backup.php import /srv/backups/laysite-2026-11.tar --replace
``` ```
使用 Git 标签选择更新版本。更新命令先备份,再检出所选版本、安装锁定依赖并运行 SQLite 初始化或迁移。更新时暂停 Webman,更新结束后重新启动。保持源代码工作区干净,并将备份放到部署路径之外。 可在「账户 → 关于系统」点击「检查更新」,比较本机版本与 `git.laysense.com/laysense/laysite` 的 `main` 分支版本。
使用 Git 标签选择部署版本。更新命令先备份,再检出所选版本、安装锁定依赖并运行 SQLite 初始化或迁移。更新时暂停 Webman,更新结束后重新启动。保持源代码工作区干净,并将备份放到部署路径之外。
```sh ```sh
bin/update.sh check bin/update.sh check
+51
View File
@@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
namespace App\Content;
use CurlHandle;
use RuntimeException;
final class Updates
{
public const REPOSITORY = 'https://git.laysense.com/laysense/laysite';
public static function current(): string
{
return trim(file_get_contents(dirname(__DIR__, 2) . '/VERSION'));
}
public static function check(): array
{
$curl = curl_init(self::REPOSITORY . '/raw/branch/main/VERSION');
if ($curl === false) {
throw new RuntimeException('无法连接上游仓库,请稍后重试。');
}
$body = '';
curl_setopt_array($curl, [
CURLOPT_CONNECTTIMEOUT_MS => 2500,
CURLOPT_TIMEOUT_MS => 6000,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_USERAGENT => 'LaySite version check',
CURLOPT_WRITEFUNCTION => static function (CurlHandle $handle, string $chunk) use (&$body): int {
if (strlen($body) + strlen($chunk) > 128) {
return 0;
}
$body .= $chunk;
return strlen($chunk);
},
]);
if (curl_exec($curl) === false || curl_getinfo($curl, CURLINFO_RESPONSE_CODE) !== 200) {
throw new RuntimeException('无法读取上游版本,请稍后重试。');
}
if (!preg_match('/^v?(\d+\.\d+\.\d+)$/D', trim($body), $version)) {
throw new RuntimeException('上游仓库返回的版本格式无效。');
}
$current = self::current();
$latest = $version[1];
return ['current' => $current, 'latest' => $latest, 'comparison' => version_compare($latest, $current)];
}
}
+14 -1
View File
@@ -17,6 +17,7 @@ use App\Content\Passwords;
use App\Content\Repository; use App\Content\Repository;
use App\Content\SiteDesign; use App\Content\SiteDesign;
use App\Content\SystemInfo; use App\Content\SystemInfo;
use App\Content\Updates;
use App\Content\View; use App\Content\View;
use App\Http\Request; use App\Http\Request;
use RuntimeException; use RuntimeException;
@@ -160,6 +161,18 @@ class AdminController
return $this->json(SystemInfo::sample()); return $this->json(SystemInfo::sample());
} }
public function aboutUpdate(Request $request): Response
{
if ($failure = $this->guard($request)) {
return $failure;
}
try {
return $this->json(Updates::check());
} catch (RuntimeException $error) {
return $this->json(['message' => $error->getMessage()], 502);
}
}
public function aboutLicense(Request $request, string $key): Response public function aboutLicense(Request $request, string $key): Response
{ {
if ($failure = $this->guard($request)) { if ($failure = $this->guard($request)) {
@@ -756,7 +769,7 @@ class AdminController
return View::render($view, $data + [ return View::render($view, $data + [
'token' => $token, 'user' => $this->user, 'adminPath' => $request->path(), 'token' => $token, 'user' => $this->user, 'adminPath' => $request->path(),
'laysiteVersion' => trim(file_get_contents(dirname(__DIR__, 2) . '/VERSION')), 'laysiteVersion' => Updates::current(),
], $status, true); ], $status, true);
} }
+2 -1
View File
@@ -11,6 +11,7 @@ use App\Content\DesignLibrary;
use App\Content\PageDraft; use App\Content\PageDraft;
use App\Content\PageTemplates; use App\Content\PageTemplates;
use App\Content\Repository; use App\Content\Repository;
use App\Content\Updates;
use App\Content\View; use App\Content\View;
use PDOException; use PDOException;
use RuntimeException; use RuntimeException;
@@ -67,7 +68,7 @@ final class McpController
return match ($method) { return match ($method) {
'initialize' => $this->result($id, [ 'initialize' => $this->result($id, [
'protocolVersion' => in_array($params['protocolVersion'] ?? null, self::PROTOCOLS, true) ? $params['protocolVersion'] : self::PROTOCOLS[0], 'protocolVersion' => in_array($params['protocolVersion'] ?? null, self::PROTOCOLS, true) ? $params['protocolVersion'] : self::PROTOCOLS[0],
'capabilities' => ['tools' => (object) []], 'serverInfo' => ['name' => 'laysite', 'version' => trim(file_get_contents(dirname(__DIR__, 2) . '/VERSION'))], 'capabilities' => ['tools' => (object) []], 'serverInfo' => ['name' => 'laysite', 'version' => Updates::current()],
'instructions' => 'Create or revise draft pages. A human can open the editor URL to review, refine and publish.', 'instructions' => 'Create or revise draft pages. A human can open the editor URL to review, refine and publish.',
]), ]),
'ping' => $this->result($id, (object) []), 'ping' => $this->result($id, (object) []),
+8
View File
@@ -1,5 +1,6 @@
<?php <?php
use App\Content\Licenses; use App\Content\Licenses;
use App\Content\Updates;
use App\Content\View; use App\Content\View;
$e = View::escape(...); $e = View::escape(...);
@@ -11,6 +12,13 @@ $e = View::escape(...);
<dl> <dl>
<div><dt>LaySite</dt><dd><?= $e($laysiteVersion) ?></dd></div> <div><dt>LaySite</dt><dd><?= $e($laysiteVersion) ?></dd></div>
</dl> </dl>
<div data-about-updates>
<div class="actions">
<button type="button" class="button button-outline" data-update-check hidden><?= View::fragment('studio-icon', ['icon' => 'refresh']) ?>检查更新</button>
<a href="<?= $e(Updates::REPOSITORY) ?>" target="_blank" rel="noopener noreferrer">上游仓库</a>
</div>
<p class="field-note" data-update-status role="status"></p>
</div>
<details class="admin-options admin-about-details" data-about-metrics> <details class="admin-options admin-about-details" data-about-metrics>
<summary>运行环境详情</summary> <summary>运行环境详情</summary>
<dl> <dl>
+1
View File
@@ -26,6 +26,7 @@ $paths = [
'desktop' => '<rect x="3" y="4.5" width="18" height="12" rx="2"/><path d="M12 16.5v4m-4 0h8"/>', 'desktop' => '<rect x="3" y="4.5" width="18" height="12" rx="2"/><path d="M12 16.5v4m-4 0h8"/>',
'phone' => '<rect x="7" y="3" width="10" height="18" rx="2"/><path d="M11 17.5h2"/>', 'phone' => '<rect x="7" y="3" width="10" height="18" rx="2"/><path d="M11 17.5h2"/>',
'archive' => '<rect x="4" y="4" width="16" height="4" rx="1"/><path d="M5 8v12h14V8m-9 4h4"/>', 'archive' => '<rect x="4" y="4" width="16" height="4" rx="1"/><path d="M5 8v12h14V8m-9 4h4"/>',
'refresh' => '<path d="M20 7v5h-5M4 17v-5h5"/><path d="M5.6 8a7.5 7.5 0 0 1 12.3-2.1L20 8.5M4 15.5l2.1 2.6A7.5 7.5 0 0 0 18.4 16"/>',
]; ];
?> ?>
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><?= $paths[$icon] ?? $paths['external'] ?></svg> <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><?= $paths[$icon] ?? $paths['external'] ?></svg>
+7 -1
View File
@@ -11,7 +11,13 @@ $e = View::escape(...);
<?php foreach ($page['sections'] as $index => $item): ?> <?php foreach ($page['sections'] as $index => $item): ?>
<?php $fixedSlot = $item['style'] === 'hero-links'; ?> <?php $fixedSlot = $item['style'] === 'hero-links'; ?>
<li> <li>
<div><strong><?= $e($item['title']) ?></strong><small>#<?= $e($item['key']) ?></small></div> <div>
<div class="studio-component-label">
<strong><?= $e($item['title']) ?></strong>
<?php if (isset($item['feed'])): ?><span class="studio-dynamic-badge">动态</span><?php endif ?>
</div>
<small>#<?= $e($item['key']) ?></small>
</div>
<div class="actions studio-block-actions"> <div class="actions studio-block-actions">
<a class="button button-outline" href="/admin/pages/<?= $e($slug) ?>/<?= $e($item['key']) ?>">区块设置</a> <a class="button button-outline" href="/admin/pages/<?= $e($slug) ?>/<?= $e($item['key']) ?>">区块设置</a>
<form method="post" action="/admin/page-blocks/<?= $e($slug) ?>"> <form method="post" action="/admin/page-blocks/<?= $e($slug) ?>">
+4 -1
View File
@@ -29,7 +29,7 @@ $modules = $kind === 'modules';
<?php foreach ($items as $key => $item): ?> <?php foreach ($items as $key => $item): ?>
<?php [$label, $markup, $option, $feed] = array_pad($item, 4, null); ?> <?php [$label, $markup, $option, $feed] = array_pad($item, 4, null); ?>
<?php if ($modules): ?> <?php if ($modules): ?>
<article class="studio-template-card" data-template-card data-library-item data-template-search-text="<?= $e($label . ' ' . $key) ?>"> <article class="studio-template-card" data-template-card data-library-item data-template-search-text="<?= $e($label . ' ' . $key . ($feed !== null ? ' 动态' : '')) ?>">
<?php if (($item[4] ?? '') === 'layout'): ?> <?php if (($item[4] ?? '') === 'layout'): ?>
<?php [$previewKind, $previewPreset] = explode('-', $key, 2); ?> <?php [$previewKind, $previewPreset] = explode('-', $key, 2); ?>
<div class="studio-layout-card-preview"> <div class="studio-layout-card-preview">
@@ -43,7 +43,10 @@ $modules = $kind === 'modules';
</button> </button>
<?php endif ?> <?php endif ?>
<div class="studio-template-meta"> <div class="studio-template-meta">
<div class="studio-component-label">
<span><?= $e($label) ?></span> <span><?= $e($label) ?></span>
<?php if ($feed !== null): ?><span class="studio-dynamic-badge">动态</span><?php endif ?>
</div>
<button type="button" class="button button-outline" disabled data-canvas-template="<?= $e($key) ?>" <button type="button" class="button button-outline" disabled data-canvas-template="<?= $e($key) ?>"
data-template-title="<?= $e($label) ?>" data-template-lead="<?= $e($option) ?>" data-template-style="<?= $e($item[4] ?? 'plain') ?>" data-template-title="<?= $e($label) ?>" data-template-lead="<?= $e($option) ?>" data-template-style="<?= $e($item[4] ?? 'plain') ?>"
<?= $feed !== null ? 'data-template-feed="' . $e($feed) . '"' : '' ?> aria-label="添加<?= $e($label) ?>组件">添加</button> <?= $feed !== null ? 'data-template-feed="' . $e($feed) . '"' : '' ?> aria-label="添加<?= $e($label) ?>组件">添加</button>
+1
View File
@@ -36,6 +36,7 @@ Route::post('/admin/logout', [AdminController::class, 'logout']);
Route::add(['GET', 'POST'], '/admin/password', [AdminController::class, 'password']); Route::add(['GET', 'POST'], '/admin/password', [AdminController::class, 'password']);
Route::get('/admin/about', [AdminController::class, 'about']); Route::get('/admin/about', [AdminController::class, 'about']);
Route::get('/admin/about/metrics', [AdminController::class, 'aboutMetrics']); Route::get('/admin/about/metrics', [AdminController::class, 'aboutMetrics']);
Route::get('/admin/about/update', [AdminController::class, 'aboutUpdate']);
Route::get('/admin/about/license/{key:[a-z0-9][a-z0-9-]*}', [AdminController::class, 'aboutLicense']); Route::get('/admin/about/license/{key:[a-z0-9][a-z0-9-]*}', [AdminController::class, 'aboutLicense']);
Route::get('/admin', [AdminController::class, 'dashboard']); Route::get('/admin', [AdminController::class, 'dashboard']);
Route::add(['GET', 'POST'], '/admin/article-categories', [AdminController::class, 'articleCategories']); Route::add(['GET', 'POST'], '/admin/article-categories', [AdminController::class, 'articleCategories']);
+22
View File
@@ -1,6 +1,28 @@
'use strict'; 'use strict';
jQuery(function ($) { jQuery(function ($) {
const $updates = $('[data-about-updates]');
const $check = $updates.find('[data-update-check]');
const $updateStatus = $updates.find('[data-update-status]');
$check.prop('hidden', false).on('click', function () {
$check.prop('disabled', true);
$updateStatus.text('正在查询上游仓库…');
$.ajax({url: '/admin/about/update', dataType: 'json', timeout: 7500})
.done(({current, latest, comparison}) => {
if (comparison > 0) {
$updateStatus.text('发现新版本 ' + latest + ',当前版本为 ' + current + '。');
} else if (comparison < 0) {
$updateStatus.text('当前版本 ' + current + ' 高于上游版本 ' + latest + '。');
} else {
$updateStatus.text('当前版本 ' + current + ' 已与上游仓库一致。');
}
})
.fail(({status, responseJSON}) => {
$updateStatus.text(status === 401 ? '登录已过期,请重新登录。' : (responseJSON?.message ?? '检查更新失败,请重试。'));
})
.always(() => $check.prop('disabled', false));
});
const $metrics = $('[data-about-metrics]'); const $metrics = $('[data-about-metrics]');
if (!$metrics.length) return; if (!$metrics.length) return;
+3 -1
View File
@@ -7,7 +7,6 @@
.admin-main { padding-block: clamp(1.65rem, 4vw, 3.25rem); } .admin-main { padding-block: clamp(1.65rem, 4vw, 3.25rem); }
.admin-version { margin-block-start: auto; padding-block: 1rem; border-block-start: 1px solid var(--line); color: var(--muted); font-size: .875rem; } .admin-version { margin-block-start: auto; padding-block: 1rem; border-block-start: 1px solid var(--line); color: var(--muted); font-size: .875rem; }
.settings-stack { display: grid; gap: .9rem; margin: 0; padding: 1rem; border: 1px solid var(--line); border-radius: .65rem; min-inline-size: 0; } .settings-stack { display: grid; gap: .9rem; margin: 0; padding: 1rem; border: 1px solid var(--line); border-radius: .65rem; min-inline-size: 0; }
.admin-about { max-inline-size: 52rem; }
.admin-system-info dl { margin: 0; } .admin-system-info dl { margin: 0; }
.admin-system-info dl > div { display: grid; grid-template-columns: minmax(7.5rem, 1fr) 2fr; gap: .65rem 1rem; padding-block: .85rem; border-block-start: 1px solid var(--line); } .admin-system-info dl > div { display: grid; grid-template-columns: minmax(7.5rem, 1fr) 2fr; gap: .65rem 1rem; padding-block: .85rem; border-block-start: 1px solid var(--line); }
.admin-system-info dt { color: var(--muted); } .admin-system-info dt { color: var(--muted); }
@@ -15,6 +14,7 @@
.admin-system-info dd small { display: block; font-family: var(--sans); color: var(--muted); } .admin-system-info dd small { display: block; font-family: var(--sans); color: var(--muted); }
.admin-system-info .admin-about-details { margin-block-start: .75rem; } .admin-system-info .admin-about-details { margin-block-start: .75rem; }
.admin-system-info .field-note { margin-block: .5rem 0; } .admin-system-info .field-note { margin-block: .5rem 0; }
.admin-system-info [data-update-status]:empty { display: none; }
.admin-about-details { background: var(--paper); } .admin-about-details { background: var(--paper); }
.admin-license-project { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .65rem 1rem; margin-bottom: 1rem; } .admin-license-project { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .65rem 1rem; margin-bottom: 1rem; }
.admin-license-project p { margin: .2rem 0 0; color: var(--muted); } .admin-license-project p { margin: .2rem 0 0; color: var(--muted); }
@@ -263,6 +263,8 @@
.studio-template-image:hover img, .studio-template-image:focus-visible img { transform: scale(1.07); } .studio-template-image:hover img, .studio-template-image:focus-visible img { transform: scale(1.07); }
.studio-template-meta { display: flex; align-items: center; justify-content: space-between; gap: .3rem; padding: .3rem .38rem .3rem .55rem; font-size: .875rem; } .studio-template-meta { display: flex; align-items: center; justify-content: space-between; gap: .3rem; padding: .3rem .38rem .3rem .55rem; font-size: .875rem; }
.studio-template-meta .button { min-height: 33px; font-size: .8rem; flex: 0 0 auto; padding: .2rem .45rem; } .studio-template-meta .button { min-height: 33px; font-size: .8rem; flex: 0 0 auto; padding: .2rem .45rem; }
.studio-component-label { display: flex; flex-wrap: wrap; align-items: center; gap: .2rem .35rem; min-inline-size: 0; }
.studio-dynamic-badge { padding: .1rem .35rem; color: var(--accent-deep); background: var(--accent-light); border-radius: .35rem; font-size: .72rem; font-weight: 650; white-space: nowrap; }
.studio-template-peek { .studio-template-peek {
position: fixed; position: fixed;
z-index: 2; z-index: 2;
+4 -2
View File
@@ -1430,9 +1430,11 @@ jQuery(function ($) {
const {key, fixed, version} = entry; const {key, fixed, version} = entry;
const index = eligible.indexOf(entry); const index = eligible.indexOf(entry);
const $row = $('<li>', {'data-layer-key': key}).appendTo($layers); const $row = $('<li>', {'data-layer-key': key}).appendTo($layers);
const $label = $('<div>').append($('<strong>', { const $label = $('<div>').appendTo($row);
const $title = $('<div>', {class: 'studio-component-label'}).append($('<strong>', {
'data-layer-title': '', text: plainText(entry.fields.title.node) || '未命名区块' 'data-layer-title': '', text: plainText(entry.fields.title.node) || '未命名区块'
})).appendTo($row); })).appendTo($label);
if (entry.feed) $('<span>', {class: 'studio-dynamic-badge', text: '动态'}).appendTo($title);
if (fixed || version === null) $label.append($('<small>').text(fixed ? '首屏目录' : '待保存')); if (fixed || version === null) $label.append($('<small>').text(fixed ? '首屏目录' : '待保存'));
const $actions = $('<div>', {class: 'actions studio-block-actions'}).appendTo($row); const $actions = $('<div>', {class: 'actions studio-block-actions'}).appendTo($row);
$actions.append(button('定位', 'jump'), button('上移', 'up', fixed || index === 0), $actions.append(button('定位', 'jump'), button('上移', 'up', fixed || index === 0),
+1 -1
View File
@@ -2,7 +2,7 @@
<?php <?php
/* /*
* LaySite: anothor AI website builder * LaySite: another AI website builder
* Copyright (C) 2026 Shanghai Laysense Information Technology Co. Ltd. <Laysense.cn> * Copyright (C) 2026 Shanghai Laysense Information Technology Co. Ltd. <Laysense.cn>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify