Single source of truth for FAQ deep-link anchor formatting and parsing on the `/faqs` page, covering both category-level and item-level hash targets. ## Key Components | Export | Type | Description | |---|---|---| | `faqSectionSlug` | `function` | Generates a `faq-` anchor id for a category section | | `faqItemAnchor` | `function` | Generates a `faq-item-` anchor id for an individual FAQ row | | `FaqHashTarget` | `type` | Discriminated union representing a parsed hash result (`item` or `section`) | | `parseFaqHash` | `function` | Parses a `/faqs#…` hash string into a typed `FaqHashTarget` or `null` | ## Hash Format Contract ```text /faqs#faq-pricing → section anchor (jump-nav, scroll-spy) /faqs#faq-item-42 → item anchor (chat citation, auto-expand + scroll) /faqs#anything-else → null (unrecognised, callers early-out) ``` ## Usage Example ```typescript import { faqSectionSlug, faqItemAnchor, parseFaqHash } from './faq-anchor' // Rendering anchors const sectionId = faqSectionSlug('Pricing & Plans') // → 'faq-pricing-plans' const itemId = faqItemAnchor(42) // → 'faq-item-42' // Parsing on mount (e.g. FaqSection auto-open logic) const target = parseFaqHash(window.location.hash) if (target?.kind === 'item') { const row = items.find(i => String(i.id) === target.rawId) row?.expand() } else if (target?.kind === 'section') { document.getElementById(target.slug)?.scrollIntoView() } // target === null → no hash or unrecognised prefix, no-op ``` ## Notes - **Collision safety:** The `faq-item-` namespace is reserved exclusively for item anchors; `parseFaqHash` uses a digits-only regex so word-suffixed slugs like `faq-item-whatever` are correctly classified as sections. - **`rawId` is a string** — coercion to compare against `item.id` is intentionally deferred to the call site. - Centralising format helpers and the parser in one file prevents format drift across the page component, chat RAG mapper, and any future consumers. **Source:** [`faq-anchor.ts`](https://github.com/flamingo-stack/openframe-oss-lib/blob/main/faq-anchor.ts)