Author SHA1 Message Date
ChatGPT 2b01537cf3 Audit merged directory links and test rendered fallbacks 2026-11-21 23:36:20 +08:00
DeepSeek 2ef38bd716 Merge pull request #8: 修复 /network 指向空白文章的死链,统一目录兜底规则
目录卡片:有网址用网址,无网址且有内容才回退文章页,否则不渲染链接。21 项断言 + 三套端到端回归通过。
2026-11-21 23:26:34 +08:00
DeepSeek 62c10b09bc Skip links to empty directory articles 2026-11-21 23:26:15 +08:00
DeepSeek 935bc7f071 Skip links to empty directory articles 2026-11-21 23:26:14 +08:00
DeepSeek 1a025353b2 Merge pull request #7: 修复产品目录卡片标题指向文章页
标题与主按钮统一使用卡片配置的网址,未配置时回退文章页。21 项链接断言通过。
2026-11-21 23:23:56 +08:00
DeepSeek ef1ff93904 Point product cards at their configured URL
The services directory built each card title from the backing article, so
/services linked to /articles/service-1..4 instead of the product pages the
card already carries (PAGEPAN, HighSpeaker, /sc, /shnu-sc). Only the primary
button used card.url, which made the title and the button disagree.

Use the card URL for both, keeping the article page as fallback for entries
without a configured URL, and add a dependency-free regression test.
2026-11-21 23:23:23 +08:00
DeepSeek 74e0de84a6 Merge pull request #6: 限制文章区块归档范围,扩展编辑组件与对齐工具
审计通过(405 项断言 + 浏览器实测对齐链路),合并。合并后需对现有 LAYSENSE_DB 运行 php bin/install.php 补 alignments 列并重启 Webman。
2026-11-21 23:16:53 +08:00
6 changed files with 126 additions and 11 deletions
+39
View File
@@ -0,0 +1,39 @@
<?php
declare(strict_types=1);
namespace App\Content;
use DOMDocument;
use DOMXPath;
final class DirectoryCard
{
public static function links(array $article, string $body): array
{
$detail = self::hasText($article['summary']) || self::hasBody($body) ? '/articles/' . $article['slug'] : '';
$primary = ($article['card']['url'] ?? '') ?: $detail;
return ['primary' => $primary, 'detail' => $primary === $detail ? '' : $detail];
}
private static function hasText(string $text): bool
{
return preg_match('/[^\s\p{Z}\p{Cf}]/u', $text) === 1;
}
private static function hasBody(string $html): bool
{
if (self::hasText(html_entity_decode(strip_tags($html), ENT_QUOTES | ENT_HTML5, 'UTF-8'))) {
return true;
}
if (!str_contains($html, 'src=')) {
return false;
}
$document = new DOMDocument();
$document->loadHTML('<meta charset="utf-8">' . $html, LIBXML_NOERROR | LIBXML_NOWARNING | LIBXML_NONET);
$xpath = new DOMXPath($document);
return (bool) $xpath->evaluate('boolean(//img[@src] | //audio[@src] | //video[@src] | //audio/source[@src] | //video/source[@src])');
}
}
+10 -5
View File
@@ -1,4 +1,6 @@
<?php <?php
use App\Content\DirectoryCard;
use App\Content\Html;
use App\Content\View; use App\Content\View;
$e = View::escape(...); $e = View::escape(...);
@@ -17,16 +19,19 @@ $e = View::escape(...);
<?php if (!$group['articles']): ?><p class="empty-state">暂无已发布条目。</p><?php endif ?> <?php if (!$group['articles']): ?><p class="empty-state">暂无已发布条目。</p><?php endif ?>
<ul class="network-list"> <ul class="network-list">
<?php foreach ($group['articles'] as $item): ?> <?php foreach ($group['articles'] as $item): ?>
<?php $card = $item['card']; $articlePath = '/articles/' . $item['slug']; ?> <?php
$card = $item['card'];
['primary' => $target, 'detail' => $detail] = DirectoryCard::links($item, Html::articleBody($item));
?>
<li> <li>
<a href="<?= $e(($card['url'] ?? '') ?: $articlePath) ?>"> <?php if ($target !== ''): ?><a href="<?= $e($target) ?>"><?php else: ?><span class="network-static"><?php endif ?>
<?php if (!empty($card['image'])): ?> <?php if (!empty($card['image'])): ?>
<img src="<?= $e($card['image']) ?>" alt="" loading="lazy" width="76" height="28"> <img src="<?= $e($card['image']) ?>" alt="" loading="lazy" width="76" height="28">
<?php endif ?> <?php endif ?>
<span><?= $e($item['title']) ?></span> <span><?= $e($item['title']) ?></span>
</a> <?php if ($target !== ''): ?></a><?php else: ?></span><?php endif ?>
<?php if ($standalone && !empty($card['url']) && ($item['body'] !== '' || $item['summary'] !== '')): ?> <?php if ($standalone && $detail !== ''): ?>
<a class="network-detail" href="<?= $e($articlePath) ?>">查看详情</a> <a class="network-detail" href="<?= $e($detail) ?>">查看详情</a>
<?php endif ?> <?php endif ?>
</li> </li>
<?php endforeach ?> <?php endforeach ?>
+14 -5
View File
@@ -1,4 +1,5 @@
<?php <?php
use App\Content\DirectoryCard;
use App\Content\Html; use App\Content\Html;
use App\Content\View; use App\Content\View;
@@ -16,23 +17,31 @@ $e = View::escape(...);
<?php if (!$products): ?><p class="empty-state">暂无可查看的产品和服务。</p><?php endif ?> <?php if (!$products): ?><p class="empty-state">暂无可查看的产品和服务。</p><?php endif ?>
<div class="catalog-grid"> <div class="catalog-grid">
<?php foreach ($products as $product): ?> <?php foreach ($products as $product): ?>
<?php $card = $product['card']; $articlePath = '/articles/' . $product['slug']; ?> <?php
$card = $product['card'];
$body = Html::articleBody($product);
['primary' => $target, 'detail' => $detail] = DirectoryCard::links($product, $body);
$extra = $card['extra_url'] ?? '';
?>
<article class="catalog-card"> <article class="catalog-card">
<?php if (!empty($card['image'])): ?> <?php if (!empty($card['image'])): ?>
<div class="catalog-image"><img src="<?= $e($card['image']) ?>" alt="<?= $e($card['alt'] ?? '') ?>" loading="lazy"></div> <div class="catalog-image"><img src="<?= $e($card['image']) ?>" alt="<?= $e($card['alt'] ?? '') ?>" loading="lazy"></div>
<?php endif ?> <?php endif ?>
<div class="catalog-content"> <div class="catalog-content">
<?php if (!empty($card['category_label'])): ?><p class="overline"><?= $e($card['category_label']) ?></p><?php endif ?> <?php if (!empty($card['category_label'])): ?><p class="overline"><?= $e($card['category_label']) ?></p><?php endif ?>
<h2><a href="<?= $e($articlePath) ?>"><?= $e($product['title']) ?></a></h2> <h2><?php if ($target !== ''): ?><a href="<?= $e($target) ?>"><?= $e($product['title']) ?></a><?php else: ?><?= $e($product['title']) ?><?php endif ?></h2>
<?php if ($product['summary']): ?> <?php if ($product['summary']): ?>
<p><?= $e($product['summary']) ?></p> <p><?= $e($product['summary']) ?></p>
<?php else: ?> <?php else: ?>
<div class="rich"><?= Html::articleBody($product) ?></div> <div class="rich"><?= $body ?></div>
<?php endif ?> <?php endif ?>
<?php if ($target !== '' || $extra !== ''): ?>
<div class="actions"> <div class="actions">
<a class="button button-primary" href="<?= $e(($card['url'] ?? '') ?: $articlePath) ?>"><?= $e(($card['label'] ?? '') ?: '了解详情') ?></a> <?php if ($target !== ''): ?><a class="button button-primary" href="<?= $e($target) ?>"><?= $e(($card['label'] ?? '') ?: '了解详情') ?></a><?php endif ?>
<?php if (!empty($card['extra_url'])): ?><a href="<?= $e($card['extra_url']) ?>"><?= $e(($card['extra_label'] ?? '') ?: '相关链接') ?></a><?php endif ?> <?php if ($extra !== '' && $extra !== $target): ?><a href="<?= $e($extra) ?>"><?= $e(($card['extra_label'] ?? '') ?: '相关链接') ?></a><?php endif ?>
<?php if ($detail !== '' && $detail !== $extra): ?><a class="catalog-detail" href="<?= $e($detail) ?>">查看详情</a><?php endif ?>
</div> </div>
<?php endif ?>
</div> </div>
</article> </article>
<?php endforeach ?> <?php endforeach ?>
+3 -1
View File
@@ -282,7 +282,9 @@ progress { width: 100%; height: .8rem; accent-color: var(--accent); }
.network-group + .network-group { margin-top: 2.2rem; } .network-group + .network-group { margin-top: 2.2rem; }
.network-group h3 { margin-bottom: .8rem; } .network-group h3 { margin-bottom: .8rem; }
.network-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 11rem), 1fr)); gap: .7rem; } .network-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 11rem), 1fr)); gap: .7rem; }
.network-list li > * { display: flex; align-items: center; gap: .75rem; min-height: 4rem; height: 100%; border-radius: .65rem; background: var(--white); border: 1px solid var(--line); color: var(--ink); text-decoration: none; padding: .75rem; transition: transform 160ms ease, border-color 160ms ease; } .network-list li { display: flex; flex-direction: column; gap: .35rem; }
.network-list li > * { display: flex; align-items: center; gap: .75rem; min-height: 4rem; border-radius: .65rem; background: var(--white); border: 1px solid var(--line); color: var(--ink); text-decoration: none; padding: .75rem; transition: transform 160ms ease, border-color 160ms ease; }
.network-list li > :first-child { flex: 1; }
.network-list a:hover { transform: translateY(-2px); border-color: var(--accent); color: var(--accent); } .network-list a:hover { transform: translateY(-2px); border-color: var(--accent); color: var(--accent); }
.network-list img { max-width: 3rem; max-height: 1.8rem; object-fit: contain; object-position: left; } .network-list img { max-width: 3rem; max-height: 1.8rem; object-fit: contain; object-position: left; }
.network-list img[src$="oneprovider_invert.svg"] { background: #29354a; border-radius: .25rem; padding: .21rem; } .network-list img[src$="oneprovider_invert.svg"] { background: #29354a; border-radius: .25rem; padding: .21rem; }
+56
View File
@@ -0,0 +1,56 @@
<?php
declare(strict_types=1);
require dirname(__DIR__) . '/vendor/autoload.php';
use App\Content\View;
$primary = 'https://example.com/product?a=1&b=2';
$cases = [
'configured-with-detail' => [['card' => ['url' => $primary], 'body' => '<p>有正文</p>'], $primary, true],
'configured-only' => [['card' => ['url' => '/pagepan']], '/pagepan', false],
'summary-only' => [['summary' => '仅摘要'], '/articles/summary-only', false],
'editor-placeholder' => [['body' => '<p><br></p><p>&nbsp;&#8203;</p>'], '', false],
'markdown-comment' => [['body' => '<!-- 草稿注释 -->', 'body_format' => 'markdown'], '', false],
'media-body' => [['body' => '<video controls><source src="/assets/demo.mp4"></video>'], '/articles/media-body', false],
'unconfigured' => [[], '', false],
];
$items = [];
foreach ($cases as $slug => [$fields]) {
$items[] = $fields + ['slug' => $slug, 'title' => $slug, 'card' => [], 'summary' => '', 'body' => '', 'body_format' => 'html'];
}
function parseFragment(string $html): DOMXPath
{
$document = new DOMDocument();
$document->loadHTML('<meta charset="utf-8">' . $html, LIBXML_NOERROR | LIBXML_NOWARNING | LIBXML_NONET);
return new DOMXPath($document);
}
function equal(mixed $actual, mixed $expected, string $message): void
{
if ($actual !== $expected) {
throw new RuntimeException($message . ' ' . json_encode([$expected, $actual], JSON_UNESCAPED_UNICODE));
}
}
$services = parseFragment(View::fragment('services', ['products' => $items]));
$network = parseFragment(View::fragment('network-groups', [
'network' => ['partners' => ['name' => '合作伙伴', 'articles' => $items]], 'standalone' => true,
]));
foreach ($cases as $slug => [, $target, $detail]) {
$card = "//article[h2='$slug' or div/h2='$slug']";
equal($services->evaluate("count($card)"), 1.0, "$slug 服务卡片存在");
equal($services->evaluate("string($card/div/h2/a/@href)"), $target, "$slug 服务标题目标");
equal($services->evaluate("string($card/div/div/a[contains(@class, 'button-primary')]/@href)"), $target, "$slug 服务按钮目标");
equal($services->evaluate("boolean($card/div/div/a[@class='catalog-detail'][@href='/articles/$slug'])"), $detail, "$slug 服务独立详情");
$item = "//li[*[1]/span='$slug']";
equal($network->evaluate("count($item)"), 1.0, "$slug 伙伴卡片存在");
equal($network->evaluate("string($item/*[1]/@href)"), $target, "$slug 伙伴卡片目标");
equal($network->evaluate("boolean($item/a[@class='network-detail'][@href='/articles/$slug'])"), $detail, "$slug 伙伴独立详情");
}
printf("通过 %d 组目录卡片测试。\n", count($cases));
+4
View File
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")/.."
exec "${PHP_BIN:-php}" tests/directory-links.php