Check upstream versions and label article-driven components

This commit is contained in:
2026-11-25 22:57:47 +08:00
parent 4ea5d2c133
commit 04cac36b83
14 changed files with 123 additions and 11 deletions
+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\SiteDesign;
use App\Content\SystemInfo;
use App\Content\Updates;
use App\Content\View;
use App\Http\Request;
use RuntimeException;
@@ -160,6 +161,18 @@ class AdminController
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
{
if ($failure = $this->guard($request)) {
@@ -756,7 +769,7 @@ class AdminController
return View::render($view, $data + [
'token' => $token, 'user' => $this->user, 'adminPath' => $request->path(),
'laysiteVersion' => trim(file_get_contents(dirname(__DIR__, 2) . '/VERSION')),
'laysiteVersion' => Updates::current(),
], $status, true);
}
+2 -1
View File
@@ -11,6 +11,7 @@ use App\Content\DesignLibrary;
use App\Content\PageDraft;
use App\Content\PageTemplates;
use App\Content\Repository;
use App\Content\Updates;
use App\Content\View;
use PDOException;
use RuntimeException;
@@ -67,7 +68,7 @@ final class McpController
return match ($method) {
'initialize' => $this->result($id, [
'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.',
]),
'ping' => $this->result($id, (object) []),
+8
View File
@@ -1,5 +1,6 @@
<?php
use App\Content\Licenses;
use App\Content\Updates;
use App\Content\View;
$e = View::escape(...);
@@ -11,6 +12,13 @@ $e = View::escape(...);
<dl>
<div><dt>LaySite</dt><dd><?= $e($laysiteVersion) ?></dd></div>
</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>
<summary>运行环境详情</summary>
<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"/>',
'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"/>',
'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>
+7 -1
View File
@@ -11,7 +11,13 @@ $e = View::escape(...);
<?php foreach ($page['sections'] as $index => $item): ?>
<?php $fixedSlot = $item['style'] === 'hero-links'; ?>
<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">
<a class="button button-outline" href="/admin/pages/<?= $e($slug) ?>/<?= $e($item['key']) ?>">区块设置</a>
<form method="post" action="/admin/page-blocks/<?= $e($slug) ?>">
+5 -2
View File
@@ -29,7 +29,7 @@ $modules = $kind === 'modules';
<?php foreach ($items as $key => $item): ?>
<?php [$label, $markup, $option, $feed] = array_pad($item, 4, null); ?>
<?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 [$previewKind, $previewPreset] = explode('-', $key, 2); ?>
<div class="studio-layout-card-preview">
@@ -43,7 +43,10 @@ $modules = $kind === 'modules';
</button>
<?php endif ?>
<div class="studio-template-meta">
<span><?= $e($label) ?></span>
<div class="studio-component-label">
<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) ?>"
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>