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
+43 -37
View File
@@ -1,37 +1,43 @@
<?php <?php
use App\Content\View; use App\Content\View;
$e = View::escape(...); $e = View::escape(...);
?> ?>
<section class="section network" aria-label="支持项目与合作伙伴"> <section class="section network" aria-label="支持项目与合作伙伴">
<div class="wrap"> <div class="wrap">
<?php if (!$standalone): ?> <?php if (!$standalone): ?>
<div class="section-heading inline-heading"> <div class="section-heading inline-heading">
<h2>支持项目与合作伙伴</h2> <h2>支持项目与合作伙伴</h2>
<a class="button button-outline" href="/network">查看全部</a> <a class="button button-outline" href="/network">查看全部</a>
</div> </div>
<?php endif ?> <?php endif ?>
<?php foreach ($network as $slug => $group): ?> <?php foreach ($network as $slug => $group): ?>
<div class="network-group" id="<?= $e($slug) ?>"> <div class="network-group" id="<?= $e($slug) ?>">
<?php if ($standalone): ?><h2><?= $e($group['name']) ?></h2><?php else: ?><h3><?= $e($group['name']) ?></h3><?php endif ?> <?php if ($standalone): ?><h2><?= $e($group['name']) ?></h2><?php else: ?><h3><?= $e($group['name']) ?></h3><?php endif ?>
<?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
<li> // 优先跳卡片配置的网址;没有网址时,只有文章本身有内容才回退到文章页,否则不渲染链接。
<a href="<?= $e(($card['url'] ?? '') ?: $articlePath) ?>"> $card = $item['card'];
<?php if (!empty($card['image'])): ?> $articlePath = '/articles/' . $item['slug'];
<img src="<?= $e($card['image']) ?>" alt="" loading="lazy" width="76" height="28"> $hasDetail = $item['body'] !== '' || $item['summary'] !== '';
<?php endif ?> $target = ($card['url'] ?? '') ?: ($hasDetail ? $articlePath : '');
<span><?= $e($item['title']) ?></span> ?>
</a> <li>
<?php if ($standalone && !empty($card['url']) && ($item['body'] !== '' || $item['summary'] !== '')): ?> <?php if ($target !== ''): ?><a href="<?= $e($target) ?>"><?php else: ?><span class="network-static"><?php endif ?>
<a class="network-detail" href="<?= $e($articlePath) ?>">查看详情</a> <?php if (!empty($card['image'])): ?>
<?php endif ?> <img src="<?= $e($card['image']) ?>" alt="" loading="lazy" width="76" height="28">
</li> <?php endif ?>
<?php endforeach ?> <span><?= $e($item['title']) ?></span>
</ul> <?php if ($target !== ''): ?></a><?php else: ?></span><?php endif ?>
</div> <?php if ($standalone && !empty($card['url']) && $hasDetail): ?>
<?php endforeach ?> <a class="network-detail" href="<?= $e($articlePath) ?>">查看详情</a>
</div> <?php endif ?>
</section> </li>
<?php endforeach ?>
</ul>
</div>
<?php endforeach ?>
</div>
</section>
+48 -45
View File
@@ -1,45 +1,48 @@
<?php <?php
use App\Content\Html; use App\Content\Html;
use App\Content\View; use App\Content\View;
$e = View::escape(...); $e = View::escape(...);
?> ?>
<section class="section catalog-hero"> <section class="section catalog-hero">
<div class="wrap"> <div class="wrap">
<nav class="breadcrumbs" aria-label="面包屑"><a href="/">首页</a><span aria-hidden="true">/</span><span aria-current="page">产品与服务</span></nav> <nav class="breadcrumbs" aria-label="面包屑"><a href="/">首页</a><span aria-hidden="true">/</span><span aria-current="page">产品与服务</span></nav>
<h1>产品与服务</h1> <h1>产品与服务</h1>
<p>自托管建站、开源智能 DNS 与软件著作权代理服务。</p> <p>自托管建站、开源智能 DNS 与软件著作权代理服务。</p>
</div> </div>
</section> </section>
<section class="section catalog-listing" aria-label="产品与服务目录"> <section class="section catalog-listing" aria-label="产品与服务目录">
<div class="wrap"> <div class="wrap">
<?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 <?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"> ?>
<?php if (!empty($card['image'])): ?> <article class="catalog-card">
<div class="catalog-image"><img src="<?= $e($card['image']) ?>" alt="<?= $e($card['alt'] ?? '') ?>" loading="lazy"></div> <?php if (!empty($card['image'])): ?>
<?php endif ?> <div class="catalog-image"><img src="<?= $e($card['image']) ?>" alt="<?= $e($card['alt'] ?? '') ?>" loading="lazy"></div>
<div class="catalog-content"> <?php endif ?>
<?php if (!empty($card['category_label'])): ?><p class="overline"><?= $e($card['category_label']) ?></p><?php endif ?> <div class="catalog-content">
<h2><a href="<?= $e($target) ?>"><?= $e($product['title']) ?></a></h2> <?php if (!empty($card['category_label'])): ?><p class="overline"><?= $e($card['category_label']) ?></p><?php endif ?>
<?php if ($product['summary']): ?> <h2><?php if ($target !== ''): ?><a href="<?= $e($target) ?>"><?= $e($product['title']) ?></a><?php else: ?><?= $e($product['title']) ?><?php endif ?></h2>
<p><?= $e($product['summary']) ?></p> <?php if ($product['summary']): ?>
<?php else: ?> <p><?= $e($product['summary']) ?></p>
<div class="rich"><?= Html::articleBody($product) ?></div> <?php else: ?>
<?php endif ?> <div class="rich"><?= Html::articleBody($product) ?></div>
<div class="actions"> <?php endif ?>
<a class="button button-primary" href="<?= $e($target) ?>"><?= $e(($card['label'] ?? '') ?: '了解详情') ?></a> <?php if ($target !== '' || !empty($card['extra_url'])): ?>
<?php if (!empty($card['extra_url'])): ?><a href="<?= $e($card['extra_url']) ?>"><?= $e(($card['extra_label'] ?? '') ?: '相关链接') ?></a><?php endif ?> <div class="actions">
</div> <?php if ($target !== ''): ?><a class="button button-primary" href="<?= $e($target) ?>"><?= $e(($card['label'] ?? '') ?: '了解详情') ?></a><?php endif ?>
</div> <?php if (!empty($card['extra_url'])): ?><a href="<?= $e($card['extra_url']) ?>"><?= $e(($card['extra_label'] ?? '') ?: '相关链接') ?></a><?php endif ?>
</article> </div>
<?php endforeach ?> <?php endif ?>
</div> </div>
</div> </article>
</section> <?php endforeach ?>
</div>
</div>
</section>