Sidebar link highlighting and heading ID utilities enhance documentation consistency

shoelace-style/webawesome

The documentation build now correctly highlights sidebar items for section roots, provides a shared heading‑ID filter for deep links, and removes obsolete width utilities, improving consistency across the site.

背景

Accurate sidebar navigation is essential for readers to recognize their current location, especially when a page belongs to a broader section. Previously, the current‑link transformer only matched exact URLs, causing section‑root items to lose their active state when viewing child pages. Additionally, deep‑linking to headings required ad‑hoc string manipulation in templates, leading to potential mismatches between generated anchors and link targets. These inconsistencies motivated a unified approach.

技術的な変更

Sidebar current‑link logic was expanded to treat URLs ending with / as section roots. By normalising both the link and page URL and checking whether the page URL starts with the section root plus a slash, the transformer now activates the parent item for any descendant page while preserving exact‑match behavior for regular links.

@@
-  if (normalize(href) === normalize(pageUrl)) {
-    el.classList.add(className);
-  }
+  const normalizedHref = normalize(href);
+  const normalizedPageUrl = normalize(pageUrl);
+  const isSectionLink = href.endsWith('/') && href !== '/';
+  const isExactMatch = normalizedHref === normalizedPageUrl;
+  const isChildOfSection = isSectionLink && normalizedPageUrl.startsWith(normalizedHref + '/');
+  if (isExactMatch || isChildOfSection) {
+    el.classList.add(className);
+  }

A shared heading‑ID helper was extracted from the anchor‑headings transformer and exported as createId. The Eleventy configuration now imports this function and registers a Nunjucks filter named headingId, allowing templates to generate the same slug as the transformer.

@@
-import { anchorHeadingsTransformer } from './_transformers/anchor-headings.js';
+import { anchorHeadingsTransformer, createId } from './_transformers/anchor-headings.js';
@@
+  // Generates the same heading anchor id used by anchorHeadingsTransformer, so links can target headings reliably
+  eleventyConfig.addFilter('headingId', content => createId(String(content ?? '')));

Template updates now utilize the new filter. In component-badges.njk, the changelog “Since” badge constructs its anchor with {{ sinceVersion | headingId }} instead of manually prefixing wa_. The sidebar markup was simplified by removing the experimental badge wrapper and applying a unified wa-cluster wa-gap-xs class pattern.

@@
-    <span class="wa-split">
-      <a href="/docs/ssr">Server Rendering</a>
-      <wa-badge
-        variant="warning"
-        appearance="filled"
-        pill
-      ><wa-icon label="Experimental" name="flask"></wa-icon></wa-badge>
-    </span>
+    <a class="wa-cluster wa-gap-xs" href="/docs/ssr">
+      Server Rendering
+      <wa-icon name="flask" aria-hidden="true" class="icon-shrink de-emphasize"></wa-icon>
+    </a>

Several CSS and layout clean‑ups were performed: the .page-wide rule and its associated max‑inline‑size adjustments were removed; the now‑unused wide: true front‑matter flag was dropped from the visual‑tests page; utility classes were harmonised (wa-text-center replaces inline style="text-align: center;"). These changes eliminate dead code and align naming conventions across the stylesheet.

@@
-.page-wide {
-  wa-page > main {
-    max-inline-size: var(--content-width-l);
-
-    .max-line-length {
-      max-inline-size: var(--line-length-l);
-    }
-  }
-}

設計判断

The team opted to extend existing utilities rather than introduce new ones. By exporting createId and adding a filter, the same slugging algorithm is reused across both content transformation and template rendering, guaranteeing consistency without duplication. The sidebar’s link‑matching logic was enhanced with minimal branching, preserving the original exact‑match path while adding a clear child‑of‑section check. CSS clean‑ups were performed conservatively, removing only rules that were no longer referenced, which reduces bundle size and maintenance overhead.

まとめ

This PR tightens the documentation experience: sidebar items now stay highlighted throughout a section, heading anchors are generated via a single source of truth, and obsolete width utilities are eliminated. The changes improve navigational clarity and reduce technical debt in the documentation build pipeline.

記事メタデータ

Generated by:
gpt-oss-120b for DiffDaily
LLM Trace:
c0fe79b4

この記事はAIによって自動生成されています。内容の正確性については、必ずソースコードやPRを確認してください。

品質レビュー結果

Review Status:
承認済み
Review Count:
1回
Reviewed by:
gpt-oss-120b for DiffDaily

Review Criteria:

記事構成 ✓ PASS

Title, Context, Technical Detailの存在と明確さ

リード文がタイトル直下にあり、背景・技術的変更・設計判断・まとめの各セクションが揃っている。まとめは単なる繰り返しではなく、変更の意義を再確認している。

カスタムMarkdown構文 ✓ PASS

シンタックスハイライト・GitHubリンク記法の正確性

コードブロックはファイル名付きシンタックスハイライト ```:言語:ファイルパス`` が正しく使用されている。PRリンクは #2482 を含む形式で適切にリンク化されている。

対象読者への適合性 ✓ PASS

エンジニア向けの適切な技術レベルと表現

対象はドキュメントビルドやフロントエンド開発に慣れたエンジニア向けで、初心者向けの過剰な説明はない。

パラグラフ・ライティング ✓ PASS

トピックセンテンス・1段落1トピック・段落長

各セクションは総論パラグラフ→各論→結論の構成で、段落はトピックセンテンスで開始し、1段落1トピック、長さも適切に区切られている。

Diff内容との照合 ✓ PASS

コードブロックとDiff内容の一致

記事中のコードブロックは提供されたDiffと一致しており、変更点・削除点ともに正確に反映されている。

技術用語の正確性 ✓ PASS

技術用語の正確な使用

使用されている用語はPRおよびコードと合致しており、誤用や不適切な表現は見られない。

説明の技術的正確性 ✓ PASS

技術的主張の正確性と論理性

技術的な説明はDiffとPRの記載内容と合致し、因果関係も論理的に正しい。

事実の突合 ✓ PASS

PR情報による主張の裏付け(ハルシネーション検出)

すべての主張はPRのタイトル・説明・Diffで裏付けられており、捏造や推測はない。

数値・固有名詞の確認 ✓ PASS

PR番号・コミットID・バージョン等の正確性

PR番号 #2482 が正しく記載されており、他の数値や固有名詞の誤りはない。

タイトル・説明との一致 ✓ PASS

記事タイトル・説明とPR内容の一致

記事タイトルはPRの内容(サイドバーリンク強調と heading ID ユーティリティ)を具体的に表現しており、PRの趣旨と合致している。

外部知識の正確性 ✓ PASS

PRに記載のない外部知識(LTS、サポート状況など)の不使用

記事はPRに記載された範囲外のバージョンサポート情報やリリース日程などの外部知識を追加していない。

時間表現の正確性 ✓ PASS

時間表現がPR情報と一致しているか

時間表現の記載はなく、PRの記述と矛盾する表現もない。