Merge pull request #8: 修复 /network 指向空白文章的死链,统一目录兜底规则

目录卡片:有网址用网址,无网址且有内容才回退文章页,否则不渲染链接。21 项断言 + 三套端到端回归通过。
This commit is contained in:
2026-11-21 23:26:34 +08:00
2 changed files with 91 additions and 82 deletions
+10 -4
View File
@@ -17,15 +17,21 @@ $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'];
$articlePath = '/articles/' . $item['slug'];
$hasDetail = $item['body'] !== '' || $item['summary'] !== '';
$target = ($card['url'] ?? '') ?: ($hasDetail ? $articlePath : '');
?>
<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 && !empty($card['url']) && $hasDetail): ?>
<a class="network-detail" href="<?= $e($articlePath) ?>">查看详情</a> <a class="network-detail" href="<?= $e($articlePath) ?>">查看详情</a>
<?php endif ?> <?php endif ?>
</li> </li>
+7 -4
View File
@@ -17,9 +17,10 @@ $e = View::escape(...);
<div class="catalog-grid"> <div class="catalog-grid">
<?php foreach ($products as $product): ?> <?php foreach ($products as $product): ?>
<?php <?php
// 目录卡片指向卡片自己配置的网址,文章页只在未设置网址时兜底。 // 目录卡片指向卡片自己配置的网址;没有网址时,只有文章本身有内容才回退到文章页。
$card = $product['card']; $card = $product['card'];
$target = ($card['url'] ?? '') ?: '/articles/' . $product['slug']; $hasDetail = $product['body'] !== '' || $product['summary'] !== '';
$target = ($card['url'] ?? '') ?: ($hasDetail ? '/articles/' . $product['slug'] : '');
?> ?>
<article class="catalog-card"> <article class="catalog-card">
<?php if (!empty($card['image'])): ?> <?php if (!empty($card['image'])): ?>
@@ -27,16 +28,18 @@ $e = View::escape(...);
<?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($target) ?>"><?= $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"><?= Html::articleBody($product) ?></div>
<?php endif ?> <?php endif ?>
<?php if ($target !== '' || !empty($card['extra_url'])): ?>
<div class="actions"> <div class="actions">
<a class="button button-primary" href="<?= $e($target) ?>"><?= $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 (!empty($card['extra_url'])): ?><a href="<?= $e($card['extra_url']) ?>"><?= $e(($card['extra_label'] ?? '') ?: '相关链接') ?></a><?php endif ?>
</div> </div>
<?php endif ?>
</div> </div>
</article> </article>
<?php endforeach ?> <?php endforeach ?>