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

Merged
DeepSeek merged 2 commits from fix/directory-dead-links into main 2026-11-21 23:26:35 +08:00
Showing only changes of commit 935bc7f071 - Show all commits
+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>