Point product cards at their configured URL

The services directory built each card title from the backing article, so
/services linked to /articles/service-1..4 instead of the product pages the
card already carries (PAGEPAN, HighSpeaker, /sc, /shnu-sc). Only the primary
button used card.url, which made the title and the button disagree.

Use the card URL for both, keeping the article page as fallback for entries
without a configured URL, and add a dependency-free regression test.
This commit is contained in:
2026-11-21 23:23:23 +08:00
parent 74e0de84a6
commit ef1ff93904
3 changed files with 92 additions and 3 deletions
+7 -3
View File
@@ -16,21 +16,25 @@ $e = View::escape(...);
<?php if (!$products): ?><p class="empty-state">暂无可查看的产品和服务。</p><?php endif ?>
<div class="catalog-grid">
<?php foreach ($products as $product): ?>
<?php $card = $product['card']; $articlePath = '/articles/' . $product['slug']; ?>
<?php
// 目录卡片指向卡片自己配置的网址,文章页只在未设置网址时兜底。
$card = $product['card'];
$target = ($card['url'] ?? '') ?: '/articles/' . $product['slug'];
?>
<article class="catalog-card">
<?php if (!empty($card['image'])): ?>
<div class="catalog-image"><img src="<?= $e($card['image']) ?>" alt="<?= $e($card['alt'] ?? '') ?>" loading="lazy"></div>
<?php endif ?>
<div class="catalog-content">
<?php if (!empty($card['category_label'])): ?><p class="overline"><?= $e($card['category_label']) ?></p><?php endif ?>
<h2><a href="<?= $e($articlePath) ?>"><?= $e($product['title']) ?></a></h2>
<h2><a href="<?= $e($target) ?>"><?= $e($product['title']) ?></a></h2>
<?php if ($product['summary']): ?>
<p><?= $e($product['summary']) ?></p>
<?php else: ?>
<div class="rich"><?= Html::articleBody($product) ?></div>
<?php endif ?>
<div class="actions">
<a class="button button-primary" href="<?= $e(($card['url'] ?? '') ?: $articlePath) ?>"><?= $e(($card['label'] ?? '') ?: '了解详情') ?></a>
<a class="button button-primary" href="<?= $e($target) ?>"><?= $e(($card['label'] ?? '') ?: '了解详情') ?></a>
<?php if (!empty($card['extra_url'])): ?><a href="<?= $e($card['extra_url']) ?>"><?= $e(($card['extra_label'] ?? '') ?: '相关链接') ?></a><?php endif ?>
</div>
</div>