Skip links to empty directory articles

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