From ef1ff939041cac9f081a237f4528e7d5920b8f98 Mon Sep 17 00:00:00 2001 From: DeepSeek Audit Date: Sat, 21 Nov 2026 23:23:23 +0800 Subject: [PATCH] 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. --- app/view/services.php | 10 ++++-- tests/dircheck.php | 18 +++++++++++ tests/directory-links.sh | 67 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 3 deletions(-) create mode 100644 tests/dircheck.php create mode 100644 tests/directory-links.sh diff --git a/app/view/services.php b/app/view/services.php index d5bcecd..76ef6c4 100644 --- a/app/view/services.php +++ b/app/view/services.php @@ -16,21 +16,25 @@ $e = View::escape(...);

暂无可查看的产品和服务。

- +
<?= $e($card['alt'] ?? '') ?>

-

+

- +
diff --git a/tests/dircheck.php b/tests/dircheck.php new file mode 100644 index 0000000..b1d352c --- /dev/null +++ b/tests/dircheck.php @@ -0,0 +1,18 @@ +卡片网址是否已发布 +$pdo = Database::connect(); +$query = $pdo->query("SELECT a.slug, a.card, a.status FROM articles a + WHERE EXISTS (SELECT 1 FROM article_category_links l WHERE l.article_id = a.id + AND l.category_slug IN ('services', 'supported-projects', 'partners')) + ORDER BY a.id"); +foreach ($query as $row) { + $card = json_decode($row['card'], true) ?: []; + echo $row['slug'], '|', $card['url'] ?? '', '|', $row['status'], "\n"; +} diff --git a/tests/directory-links.sh b/tests/directory-links.sh new file mode 100644 index 0000000..872b302 --- /dev/null +++ b/tests/directory-links.sh @@ -0,0 +1,67 @@ +#!/usr/bin/env bash +# 目录页(/services、/network)的卡片链接必须指向卡片配置的网址,而不是 /articles/ +set -u +cd "$(dirname "$0")/.." || exit 1 +BASE=http://127.0.0.1:8787 +PASS=0; FAIL=0 +ok(){ PASS=$((PASS+1)); printf ' ok %s\n' "$1"; } +no(){ FAIL=$((FAIL+1)); printf ' FAIL %s -> %s\n' "$1" "${2:-}"; } + +SERVICES=$(curl -s "$BASE/services") +NETWORK=$(curl -s "$BASE/network") +ROWS=$(php tests/dircheck.php) + +echo "== /services 卡片链接 ==" +while IFS='|' read -r slug url status; do + [ -z "$slug" ] && continue + [ -z "$url" ] && continue + if echo "$SERVICES" | grep -q "href=\"$url\""; then ok "$slug 标题/按钮指向 $url"; else no "$slug 未指向 $url"; fi + if echo "$SERVICES" | grep -q "href=\"/articles/$slug\""; then no "$slug 仍出现 /articles/$slug"; else ok "$slug 不再指向文章页"; fi +done <<< "$(echo "$ROWS" | grep -E '^service-')" + +echo "== /network 卡片链接 ==" +while IFS='|' read -r slug url status; do + [ -z "$slug" ] && continue + [ -z "$url" ] && continue + if echo "$NETWORK" | grep -q "href=\"$url\""; then ok "$slug 指向 $url"; else no "$slug 未指向 $url"; fi + if echo "$NETWORK" | grep -q "href=\"/articles/$slug\""; then no "$slug 仍出现 /articles/$slug"; else ok "$slug 不再指向文章页"; fi +done <<< "$(echo "$ROWS" | grep -E '^network-')" + +echo "== 标题链接与按钮链接一致性 ==" +python3 - "$BASE" <<'PY' +import re, sys, html, urllib.request +base = sys.argv[1] +def get(path): + return urllib.request.urlopen(base + path, timeout=10).read().decode() +page = get('/services') +cards = re.findall(r'
.*?
', page, re.S) +bad = 0 +for card in cards: + links = re.findall(r']*href="([^"]+)"', card) + title = re.search(r'