Skip links to empty directory articles

This commit is contained in:
2026-11-21 23:26:15 +08:00
parent 935bc7f071
commit 62c10b09bc
+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>