@flamingo-stack/openframe-frontend-core 0.0.286 → 0.0.287-snapshot.20260618163006

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/dist/{chunk-HLQW7MWJ.cjs → chunk-3SDBXXDP.cjs} +21 -21
  2. package/dist/{chunk-HLQW7MWJ.cjs.map → chunk-3SDBXXDP.cjs.map} +1 -1
  3. package/dist/{chunk-4WACBTZU.cjs → chunk-6AW25OS6.cjs} +25 -25
  4. package/dist/{chunk-4WACBTZU.cjs.map → chunk-6AW25OS6.cjs.map} +1 -1
  5. package/dist/{chunk-QCKN37OP.cjs → chunk-6CSW5TMS.cjs} +35 -35
  6. package/dist/{chunk-QCKN37OP.cjs.map → chunk-6CSW5TMS.cjs.map} +1 -1
  7. package/dist/{chunk-YVB3VDIQ.js → chunk-7EYWERFT.js} +2 -2
  8. package/dist/chunk-AISIZLZP.js +619 -0
  9. package/dist/chunk-AISIZLZP.js.map +1 -0
  10. package/dist/{chunk-6N26CURS.cjs → chunk-D6RK5YXX.cjs} +25 -3
  11. package/dist/chunk-D6RK5YXX.cjs.map +1 -0
  12. package/dist/chunk-DVUFNTI2.cjs +619 -0
  13. package/dist/chunk-DVUFNTI2.cjs.map +1 -0
  14. package/dist/{chunk-FSBDVT6R.js → chunk-EFYXPR43.js} +2 -2
  15. package/dist/{chunk-XQL4WDML.js → chunk-GJDXIVEQ.js} +3 -3
  16. package/dist/{chunk-D5YY5U6J.cjs → chunk-JQ4I743L.cjs} +11 -11
  17. package/dist/{chunk-D5YY5U6J.cjs.map → chunk-JQ4I743L.cjs.map} +1 -1
  18. package/dist/{chunk-DDAT4RKX.js → chunk-ODR6A6FC.js} +24 -2
  19. package/dist/chunk-ODR6A6FC.js.map +1 -0
  20. package/dist/{chunk-GDF2R2ER.cjs → chunk-OXC72UIP.cjs} +120 -120
  21. package/dist/{chunk-GDF2R2ER.cjs.map → chunk-OXC72UIP.cjs.map} +1 -1
  22. package/dist/{chunk-RQ6RTBKF.cjs → chunk-RG6FNZUA.cjs} +65 -27
  23. package/dist/chunk-RG6FNZUA.cjs.map +1 -0
  24. package/dist/{chunk-5BTZOVDQ.js → chunk-RWCA2ZQK.js} +2 -2
  25. package/dist/{chunk-QF2X6PTD.js → chunk-TY2EB7VK.js} +58 -20
  26. package/dist/chunk-TY2EB7VK.js.map +1 -0
  27. package/dist/{chunk-VCQ3CTYK.js → chunk-ZYLQMCHW.js} +3 -3
  28. package/dist/components/chat/index.cjs +3 -3
  29. package/dist/components/chat/index.js +2 -2
  30. package/dist/components/contact/index.cjs +4 -4
  31. package/dist/components/contact/index.js +3 -3
  32. package/dist/components/docs/index.cjs +3 -3
  33. package/dist/components/docs/index.js +2 -2
  34. package/dist/components/embeds/index.cjs +8 -4
  35. package/dist/components/embeds/index.cjs.map +1 -1
  36. package/dist/components/embeds/index.d.ts +2 -0
  37. package/dist/components/embeds/index.d.ts.map +1 -1
  38. package/dist/components/embeds/index.js +7 -3
  39. package/dist/components/embeds/og-link-preview.d.ts +114 -0
  40. package/dist/components/embeds/og-link-preview.d.ts.map +1 -0
  41. package/dist/components/faq/faq-section.d.ts.map +1 -1
  42. package/dist/components/faq/index.cjs +4 -4
  43. package/dist/components/faq/index.js +3 -3
  44. package/dist/components/faq-accordion.d.ts.map +1 -1
  45. package/dist/components/features/index.cjs +3 -3
  46. package/dist/components/features/index.js +2 -2
  47. package/dist/components/index.cjs +146 -142
  48. package/dist/components/index.cjs.map +1 -1
  49. package/dist/components/index.js +11 -7
  50. package/dist/components/index.js.map +1 -1
  51. package/dist/components/navigation/index.cjs +3 -3
  52. package/dist/components/navigation/index.js +2 -2
  53. package/dist/components/related-content/index.cjs +4 -4
  54. package/dist/components/related-content/index.js +3 -3
  55. package/dist/components/tickets/index.cjs +53 -53
  56. package/dist/components/tickets/index.js +4 -4
  57. package/dist/components/ui/index.cjs +3 -3
  58. package/dist/components/ui/index.js +2 -2
  59. package/dist/index.cjs +9 -3
  60. package/dist/index.cjs.map +1 -1
  61. package/dist/index.js +8 -2
  62. package/dist/types/marketing.d.ts +1 -1
  63. package/dist/types/marketing.d.ts.map +1 -1
  64. package/dist/utils/faq-anchor.d.ts +51 -0
  65. package/dist/utils/faq-anchor.d.ts.map +1 -0
  66. package/dist/utils/index.cjs +23 -1
  67. package/dist/utils/index.cjs.map +1 -1
  68. package/dist/utils/index.d.ts +2 -0
  69. package/dist/utils/index.d.ts.map +1 -1
  70. package/dist/utils/index.js +21 -2
  71. package/dist/utils/index.js.map +1 -1
  72. package/dist/utils/list-url.d.ts.map +1 -1
  73. package/package.json +1 -1
  74. package/src/components/embeds/index.ts +7 -0
  75. package/src/components/embeds/og-link-preview.tsx +446 -0
  76. package/src/components/faq/faq-section.tsx +78 -26
  77. package/src/components/faq-accordion.tsx +8 -1
  78. package/src/types/marketing.ts +1 -0
  79. package/src/utils/faq-anchor.ts +70 -0
  80. package/src/utils/index.ts +7 -0
  81. package/src/utils/list-url.ts +1 -0
  82. package/dist/chunk-6N26CURS.cjs.map +0 -1
  83. package/dist/chunk-BBZ7AX5H.cjs +0 -290
  84. package/dist/chunk-BBZ7AX5H.cjs.map +0 -1
  85. package/dist/chunk-C6SCWXDP.js +0 -290
  86. package/dist/chunk-C6SCWXDP.js.map +0 -1
  87. package/dist/chunk-DDAT4RKX.js.map +0 -1
  88. package/dist/chunk-QF2X6PTD.js.map +0 -1
  89. package/dist/chunk-RQ6RTBKF.cjs.map +0 -1
  90. /package/dist/{chunk-YVB3VDIQ.js.map → chunk-7EYWERFT.js.map} +0 -0
  91. /package/dist/{chunk-FSBDVT6R.js.map → chunk-EFYXPR43.js.map} +0 -0
  92. /package/dist/{chunk-XQL4WDML.js.map → chunk-GJDXIVEQ.js.map} +0 -0
  93. /package/dist/{chunk-5BTZOVDQ.js.map → chunk-RWCA2ZQK.js.map} +0 -0
  94. /package/dist/{chunk-VCQ3CTYK.js.map → chunk-ZYLQMCHW.js.map} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"list-url.d.ts","sourceRoot":"","sources":["../../src/utils/list-url.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAWH;;;;iEAIiE;AACjE,wBAAgB,uBAAuB,CAAC,cAAc,EAAE,MAAM,GAAG,MAAM,CAEtE;AA4BD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,YAAY,CAAC,cAAc,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,IAAI,SAAK,GAAG,MAAM,GAAG,IAAI,CAa5F"}
1
+ {"version":3,"file":"list-url.d.ts","sourceRoot":"","sources":["../../src/utils/list-url.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAWH;;;;iEAIiE;AACjE,wBAAgB,uBAAuB,CAAC,cAAc,EAAE,MAAM,GAAG,MAAM,CAEtE;AA6BD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,YAAY,CAAC,cAAc,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,IAAI,SAAK,GAAG,MAAM,GAAG,IAAI,CAa5F"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flamingo-stack/openframe-frontend-core",
3
- "version": "0.0.286",
3
+ "version": "0.0.287-snapshot.20260618163006",
4
4
  "description": "Shared design system and components for all Flamingo platforms",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -9,3 +9,10 @@ export type { GoogleSheetsViewerProps } from './google-sheets-viewer'
9
9
 
10
10
  export { FigmaEmbed } from './figma-embed'
11
11
  export type { FigmaEmbedProps } from './figma-embed'
12
+
13
+ export { OGLinkPreview, OGLinkErrorBoundary } from './og-link-preview'
14
+ export type {
15
+ OGLinkPreviewProps,
16
+ OGData,
17
+ BuildPlaceholderUrl,
18
+ } from './og-link-preview'
@@ -0,0 +1,446 @@
1
+ "use client"
2
+
3
+ import React, { useState, useEffect, Component, ReactNode } from 'react'
4
+ import Image from '../../embed-shims/next-image'
5
+ import { useImageEdgeColor } from '../../hooks'
6
+
7
+ /**
8
+ * Open-Graph metadata returned by the consumer's scrape endpoint.
9
+ *
10
+ * The shape MUST match the JSON the OG endpoint serves at `ogEndpointPath`.
11
+ * The hub's `/api/blog/og-scraper` returns exactly these fields — embedders
12
+ * with a different endpoint must return the same shape (or adapt at the
13
+ * route boundary). Keeps the consumer surface trivial: one URL → one card.
14
+ */
15
+ export interface OGData {
16
+ title: string
17
+ description: string
18
+ image: string
19
+ originalImage?: string
20
+ url: string
21
+ siteName: string
22
+ type: string
23
+ favicon: string
24
+ }
25
+
26
+ interface ErrorBoundaryProps {
27
+ children: ReactNode
28
+ fallback: ReactNode
29
+ }
30
+
31
+ interface ErrorBoundaryState {
32
+ hasError: boolean
33
+ }
34
+
35
+ /**
36
+ * Tiny error boundary tailored for OG link previews — caught errors quietly
37
+ * fall back to the `fallback` prop (typically a plain hyperlink) so a single
38
+ * broken third-party preview can't crash a whole article view.
39
+ *
40
+ * Named `OGLinkErrorBoundary` (not the generic `ErrorBoundary`) because the
41
+ * lib already exports a separate `ErrorBoundary` from
42
+ * `components/features/error-boundary.tsx`. The top-level `components/index.ts`
43
+ * barrel re-exports both `./embeds` and `./features` via `export *`, so a
44
+ * second `ErrorBoundary` here collides as TS2308.
45
+ */
46
+ export class OGLinkErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
47
+ constructor(props: ErrorBoundaryProps) {
48
+ super(props)
49
+ this.state = { hasError: false }
50
+ }
51
+
52
+ static getDerivedStateFromError(): ErrorBoundaryState {
53
+ return { hasError: true }
54
+ }
55
+
56
+ componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
57
+ console.warn('Link preview error caught by boundary:', error, errorInfo)
58
+ }
59
+
60
+ render() {
61
+ if (this.state.hasError) return this.props.fallback
62
+ return this.props.children
63
+ }
64
+ }
65
+
66
+ /**
67
+ * Builds a placeholder image URL when the scrape returns no image. Hub passes
68
+ * its own `buildOgPlaceholderUrl` (which resolves CSS-var ODS colors against
69
+ * the platform's brand palette + hits `/api/og-placeholder`); other embedders
70
+ * can omit the prop to disable the placeholder entirely.
71
+ *
72
+ * Receives the post-scrape `title` and `siteName` so the placeholder can echo
73
+ * the actual card content, not a generic graphic.
74
+ */
75
+ export type BuildPlaceholderUrl = (
76
+ title: string,
77
+ siteName: string,
78
+ ) => string | null
79
+
80
+ export interface OGLinkPreviewProps {
81
+ /** The external URL to preview. */
82
+ url: string
83
+ /** Origin / base URL the OG endpoint is served from. Empty / undefined
84
+ * means same-origin (hub-direct use). Embed contexts pass the hub's
85
+ * origin here (e.g. `'https://hub.example.com'`) so the fetch hits
86
+ * the hub instead of the embedder origin.
87
+ *
88
+ * Pattern matches lib's `useNatsDialogSubscription({apiBaseUrl})` +
89
+ * `buildSuggestionUrl({apiBaseUrl})` so all embed-ready surfaces share
90
+ * one configuration knob. */
91
+ apiBaseUrl?: string
92
+ /** Path of the OG endpoint on the configured base. Default
93
+ * `'/api/blog/og-scraper'` matches the hub's route. Override if the
94
+ * embedder serves the same `OGData` shape from a different path. */
95
+ ogEndpointPath?: string
96
+ /** Optional placeholder-builder. Omit to disable the placeholder image
97
+ * (the card then degrades to a favicon+title chip when no scraped image
98
+ * is available). The hub injects its `buildOgPlaceholderUrl` here. */
99
+ buildPlaceholderUrl?: BuildPlaceholderUrl
100
+ /** Override the scraped title (used by publication cards that already know
101
+ * the title locally — e.g. a CMS-managed press link). */
102
+ fallbackTitle?: string
103
+ /** Override the scraped description. */
104
+ fallbackDescription?: string
105
+ /** Override the scraped image — useful when the scrape returns no image but
106
+ * the embedder has a CMS-stored hero image to fall back to. */
107
+ fallbackImage?: string
108
+ /** Publication / source name shown alongside the favicon (e.g. "TechCrunch"). */
109
+ publicationName?: string
110
+ /** Publication logo URL shown alongside the title (defaults to favicon). */
111
+ publicationLogo?: string
112
+ /** Card variant. `compact` = horizontal layout (~120px tall) suited for
113
+ * in-doc placements; `default` = larger vertical layout for press / hero
114
+ * positions. */
115
+ variant?: 'default' | 'compact'
116
+ /** Disable the synthesized placeholder image even when `buildPlaceholderUrl`
117
+ * is provided — used by the markdown renderer to keep doc cards lighter. */
118
+ enablePlaceholder?: boolean
119
+ }
120
+
121
+ function getDomain(urlStr: string): string {
122
+ try { return new URL(urlStr).hostname.replace('www.', '') }
123
+ catch { return 'External Link' }
124
+ }
125
+
126
+ function domainToTitle(domain: string): string {
127
+ return domain.split('.')[0].replace(/-/g, ' ').replace(/\b\w/g, c => c.toUpperCase())
128
+ }
129
+
130
+ const ExternalLinkIcon = ({ size = 16 }: { size?: number }) => (
131
+ <svg width={size} height={size} fill="none" stroke="currentColor" viewBox="0 0 24 24" className="text-ods-text-secondary group-hover:text-ods-accent transition-colors flex-shrink-0">
132
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14" />
133
+ </svg>
134
+ )
135
+
136
+ const Favicon = ({ src, size = 'w-6 h-6' }: { src: string; size?: string }) => (
137
+ <img src={src} alt="" className={size} onError={(e) => { (e.target as HTMLImageElement).style.display = 'none' }} />
138
+ )
139
+
140
+ /**
141
+ * Rich Open-Graph link preview card with skeleton, fallback, and image-edge
142
+ * background detection.
143
+ *
144
+ * Flow:
145
+ * 1. Validate URL early (no network for malformed input, localhost, or
146
+ * RFC1918 ranges — those render as plain `<a>` tags).
147
+ * 2. `GET ogEndpointPath?url=<encoded>` — embedder serves the shape declared
148
+ * in `OGData`.
149
+ * 3. Resolve image: scraped og:image → `originalImage` fallback → `fallbackImage`
150
+ * prop → `buildPlaceholderUrl(title, siteName)`. Each step has its own
151
+ * error toggle so a 404 / CORS-tainted image gracefully degrades.
152
+ * 4. Extract a letterbox background color from the resolved image via
153
+ * `useImageEdgeColor`. Same-origin proxy is REQUIRED for cross-origin
154
+ * images so the `<canvas>` extraction doesn't taint.
155
+ * 5. Render compact (h-[120px] horizontal) or default (vertical w/ aspect-video
156
+ * hero) variant, with image-less degraded variants for each.
157
+ */
158
+ export const OGLinkPreview: React.FC<OGLinkPreviewProps> = ({
159
+ url,
160
+ apiBaseUrl,
161
+ ogEndpointPath = '/api/blog/og-scraper',
162
+ buildPlaceholderUrl,
163
+ fallbackTitle,
164
+ fallbackDescription,
165
+ fallbackImage,
166
+ publicationName,
167
+ publicationLogo,
168
+ variant = 'default',
169
+ enablePlaceholder = true,
170
+ }) => {
171
+ const [ogData, setOgData] = useState<OGData | null>(null)
172
+ const [loading, setLoading] = useState(true)
173
+ const [error, setError] = useState(false)
174
+ const [imageError, setImageError] = useState(false)
175
+ const [originalImageError, setOriginalImageError] = useState(false)
176
+ const [fallbackImageError, setFallbackImageError] = useState(false)
177
+
178
+ let isValidUrl = true
179
+ let isLocalhost = false
180
+ try {
181
+ if (url && typeof url === 'string') {
182
+ const urlObj = new URL(url)
183
+ if (['localhost', '127.0.0.1', '0.0.0.0'].includes(urlObj.hostname) ||
184
+ urlObj.hostname.startsWith('192.168.') || urlObj.hostname.startsWith('10.') || urlObj.hostname.startsWith('172.')) {
185
+ isLocalhost = true
186
+ }
187
+ } else {
188
+ isValidUrl = false
189
+ }
190
+ } catch {
191
+ isValidUrl = false
192
+ }
193
+
194
+ useEffect(() => {
195
+ if (!isValidUrl || isLocalhost) return
196
+
197
+ const fetchOGData = async () => {
198
+ try {
199
+ new URL(url)
200
+ setLoading(true)
201
+ // Compose `${base}${path}?url=…`. Empty base → relative path
202
+ // (same-origin); absolute base → cross-origin embed against the hub.
203
+ // Plain string concat is safer than `new URL(path, base)` because
204
+ // the latter resolves `path` against the BASE's pathname when
205
+ // `path` is relative, producing surprising URLs when the embedder
206
+ // serves the lib from a subpath.
207
+ const endpoint = `${apiBaseUrl ?? ''}${ogEndpointPath}?url=${encodeURIComponent(url)}`
208
+ const response = await fetch(endpoint)
209
+ if (response.ok) {
210
+ const data = await response.json()
211
+ if (data?.title && data.title !== 'Link Preview Unavailable') {
212
+ setOgData(data)
213
+ } else {
214
+ setError(true)
215
+ }
216
+ } else {
217
+ setError(true)
218
+ }
219
+ } catch {
220
+ setError(true)
221
+ } finally {
222
+ setLoading(false)
223
+ }
224
+ }
225
+
226
+ fetchOGData()
227
+ }, [url, isValidUrl, isLocalhost, apiBaseUrl, ogEndpointPath])
228
+
229
+ const isCompact = variant === 'compact'
230
+ const domain = getDomain(url)
231
+
232
+ const effectiveData: OGData | null = ogData ?? (error ? {
233
+ title: fallbackTitle || domainToTitle(domain),
234
+ description: fallbackDescription || domain,
235
+ image: '',
236
+ url,
237
+ siteName: publicationName || domain,
238
+ type: 'website',
239
+ favicon: `https://www.google.com/s2/favicons?domain=${domain}&sz=32`,
240
+ } : null)
241
+
242
+ // Hub-injected placeholder builder — fires only when the post-scrape image
243
+ // chain is empty AND `enablePlaceholder` is true. `null` when unprovided.
244
+ const placeholderImageUrl =
245
+ enablePlaceholder && buildPlaceholderUrl && effectiveData?.title
246
+ ? buildPlaceholderUrl(effectiveData.title, effectiveData.siteName || domain)
247
+ : null
248
+
249
+ const resolvedImageUrl = (effectiveData?.image && !imageError)
250
+ ? effectiveData.image
251
+ : (effectiveData?.originalImage && !originalImageError)
252
+ ? effectiveData.originalImage
253
+ : (fallbackImage && !fallbackImageError)
254
+ ? fallbackImage
255
+ : placeholderImageUrl
256
+
257
+ const hasImage = !!resolvedImageUrl
258
+ const isFallbackImage = resolvedImageUrl === fallbackImage
259
+ const isPlaceholder = resolvedImageUrl === placeholderImageUrl && !isFallbackImage
260
+ const bgColor = useImageEdgeColor(resolvedImageUrl ?? null, 'var(--ods-bg-secondary)')
261
+
262
+ const renderSkeleton = () => isCompact ? (
263
+ <div className="my-4">
264
+ <div className="flex flex-row border border-ods-border rounded-lg overflow-hidden bg-ods-card h-[120px]">
265
+ <div className="w-[200px] h-full flex-shrink-0 bg-ods-skeleton animate-pulse" />
266
+ <div className="flex-1 p-3 flex flex-col justify-center">
267
+ <div className="bg-ods-skeleton rounded animate-pulse h-4 w-3/4 mb-2" />
268
+ <div className="bg-ods-skeleton rounded animate-pulse h-3 w-full mb-1" />
269
+ <div className="bg-ods-skeleton rounded animate-pulse h-3 w-2/3 mb-2" />
270
+ <div className="bg-ods-skeleton rounded animate-pulse h-3 w-1/3" />
271
+ </div>
272
+ </div>
273
+ </div>
274
+ ) : (
275
+ <div className="my-6">
276
+ <div className="block border border-ods-border rounded-lg overflow-hidden bg-ods-card">
277
+ <div className="aspect-video w-full bg-ods-skeleton overflow-hidden relative animate-pulse" />
278
+ <div className="p-4">
279
+ <div className="flex items-start gap-3">
280
+ <div className="w-6 h-6 bg-ods-skeleton rounded flex-shrink-0 mt-0.5 animate-pulse" />
281
+ <div className="flex-1 min-w-0">
282
+ <div className="h-[2.5rem] leading-[1.25rem] mb-2 overflow-hidden">
283
+ <div className="bg-ods-skeleton rounded animate-pulse" style={{ height: '1.25rem', marginBottom: '0.25rem' }} />
284
+ <div className="bg-ods-skeleton rounded animate-pulse w-3/4" style={{ height: '1.25rem' }} />
285
+ </div>
286
+ <div className="h-[2.5rem] leading-[1.25rem] mb-2 overflow-hidden">
287
+ <div className="bg-ods-skeleton rounded animate-pulse" style={{ height: '1.25rem', marginBottom: '0.25rem' }} />
288
+ <div className="bg-ods-skeleton rounded animate-pulse w-5/6" style={{ height: '1.25rem' }} />
289
+ </div>
290
+ <div className="flex items-center gap-2">
291
+ <div className="bg-ods-skeleton rounded animate-pulse" style={{ height: '0.75rem', width: '6rem' }} />
292
+ <div className="bg-ods-skeleton rounded animate-pulse" style={{ height: '0.75rem', width: '5rem' }} />
293
+ </div>
294
+ </div>
295
+ </div>
296
+ </div>
297
+ </div>
298
+ </div>
299
+ )
300
+
301
+ if (!url || typeof url !== 'string' || !isValidUrl) return renderSkeleton()
302
+
303
+ if (isLocalhost) {
304
+ return (
305
+ <div className="my-6">
306
+ <a href={url} target="_blank" rel="noopener noreferrer"
307
+ className="inline-flex items-center gap-2 text-ods-accent hover:text-ods-accent-hover transition-colors">
308
+ <span className="underline">{url}</span>
309
+ <ExternalLinkIcon size={14} />
310
+ </a>
311
+ </div>
312
+ )
313
+ }
314
+
315
+ if (loading) return renderSkeleton()
316
+ if (!effectiveData) return renderSkeleton()
317
+
318
+ const title = fallbackTitle || effectiveData.title
319
+ // Empty string when the scrape returned nothing — descriptions render
320
+ // conditionally below. Avoids the legacy `'No description available'` filler
321
+ // that signaled "broken card" to users.
322
+ const description = fallbackDescription || effectiveData.description || ''
323
+ const ogDomain = getDomain(effectiveData.url)
324
+ const faviconSrc = effectiveData.favicon || `https://www.google.com/s2/favicons?domain=${ogDomain}&sz=32`
325
+ const logoSrc = publicationLogo || faviconSrc
326
+
327
+ const handleImageError = () => {
328
+ if (effectiveData.image && !imageError) setImageError(true)
329
+ else if (effectiveData.originalImage && !originalImageError) setOriginalImageError(true)
330
+ else setFallbackImageError(true)
331
+ }
332
+
333
+ const renderImage = () => {
334
+ if (!resolvedImageUrl) return null
335
+ if (isPlaceholder) {
336
+ return (
337
+ <img src={resolvedImageUrl} alt={title}
338
+ className="absolute inset-0 w-full h-full object-cover rounded-md" />
339
+ )
340
+ }
341
+ if (isFallbackImage) {
342
+ return (
343
+ <Image src={resolvedImageUrl} alt={title} fill
344
+ className="object-contain rounded-md group-hover:scale-105 transition-transform duration-300"
345
+ onError={handleImageError}
346
+ unoptimized={resolvedImageUrl.includes('/render/image/')} />
347
+ )
348
+ }
349
+ return (
350
+ <img src={resolvedImageUrl} alt={title}
351
+ className="absolute inset-0 w-full h-full object-contain rounded-md group-hover:scale-105 transition-transform duration-300"
352
+ onError={handleImageError} />
353
+ )
354
+ }
355
+
356
+ if (isCompact) {
357
+ if (!hasImage) {
358
+ return (
359
+ <div className="my-4">
360
+ <a href={effectiveData.url} target="_blank" rel="noopener noreferrer"
361
+ className="flex flex-row items-center gap-3 border border-ods-border rounded-lg overflow-hidden bg-ods-card hover:border-ods-accent transition-all duration-200 group px-4 py-3">
362
+ <div className="w-8 h-8 bg-ods-bg-secondary rounded-lg flex items-center justify-center flex-shrink-0">
363
+ <Favicon src={faviconSrc} size="w-5 h-5" />
364
+ </div>
365
+ <div className="flex-1 min-w-0">
366
+ <h3 className="font-sans text-sm font-semibold text-ods-text-primary group-hover:text-ods-accent transition-colors truncate">{title}</h3>
367
+ {description && (
368
+ <p className="font-sans text-xs text-ods-text-secondary truncate">{description}</p>
369
+ )}
370
+ </div>
371
+ <ExternalLinkIcon size={14} />
372
+ </a>
373
+ </div>
374
+ )
375
+ }
376
+ return (
377
+ <div className="my-4">
378
+ <a href={effectiveData.url} target="_blank" rel="noopener noreferrer"
379
+ className="flex flex-row border border-ods-border rounded-lg overflow-hidden bg-ods-card hover:border-ods-accent transition-colors group h-[120px]">
380
+ <div className="w-[200px] h-full flex-shrink-0 overflow-hidden relative flex items-center justify-center rounded-lg transition-colors duration-300" style={{ backgroundColor: bgColor }}>
381
+ {renderImage()}
382
+ </div>
383
+ <div className="flex-1 p-3 flex flex-col justify-center min-w-0">
384
+ <h3 className="font-sans text-sm font-semibold text-ods-text-primary overflow-hidden group-hover:text-ods-accent transition-colors"
385
+ style={{ display: '-webkit-box', WebkitLineClamp: 1, WebkitBoxOrient: 'vertical' }}>{title}</h3>
386
+ {description && (
387
+ <p className="font-sans text-xs text-ods-text-secondary overflow-hidden mt-1"
388
+ style={{ display: '-webkit-box', WebkitLineClamp: 2, WebkitBoxOrient: 'vertical' }}>{description}</p>
389
+ )}
390
+ <div className="text-xs text-ods-text-secondary mt-1 truncate">{effectiveData.siteName || ogDomain}</div>
391
+ </div>
392
+ </a>
393
+ </div>
394
+ )
395
+ }
396
+
397
+ if (!hasImage) {
398
+ return (
399
+ <div className="my-6">
400
+ <a href={effectiveData.url} target="_blank" rel="noopener noreferrer"
401
+ className="flex items-center gap-3 border border-ods-border rounded-lg overflow-hidden bg-ods-card hover:border-ods-accent transition-all duration-200 group px-4 py-3">
402
+ <div className="w-10 h-10 bg-ods-bg-secondary rounded-lg flex items-center justify-center flex-shrink-0">
403
+ <Favicon src={faviconSrc} />
404
+ </div>
405
+ <div className="flex-1 min-w-0">
406
+ <h3 className="font-sans font-semibold text-ods-text-primary text-base group-hover:text-ods-accent transition-colors truncate">{title}</h3>
407
+ {description && (
408
+ <p className="font-sans text-sm text-ods-text-secondary truncate">{description}</p>
409
+ )}
410
+ </div>
411
+ <ExternalLinkIcon />
412
+ </a>
413
+ </div>
414
+ )
415
+ }
416
+
417
+ return (
418
+ <div className="my-6">
419
+ <a href={effectiveData.url} target="_blank" rel="noopener noreferrer"
420
+ className="block border border-ods-border rounded-lg overflow-hidden bg-ods-card hover:border-ods-accent transition-colors group">
421
+ <div className="aspect-video w-full overflow-hidden relative flex items-center justify-center rounded-lg transition-colors duration-300" style={{ backgroundColor: bgColor }}>
422
+ {renderImage()}
423
+ </div>
424
+ <div className="p-4">
425
+ <div className="flex items-start gap-3">
426
+ <img src={logoSrc} alt={publicationName || ''} className="w-6 h-6 rounded object-contain flex-shrink-0 mt-0.5"
427
+ onError={(e) => { (e.target as HTMLImageElement).style.display = 'none' }} />
428
+ <div className="flex-1 min-w-0">
429
+ <h3 className="font-sans font-semibold text-ods-text-primary text-base overflow-hidden group-hover:text-ods-accent transition-colors h-[2.5rem] leading-[1.25rem] mb-2"
430
+ style={{ display: '-webkit-box', WebkitLineClamp: 2, WebkitBoxOrient: 'vertical' }}>{title}</h3>
431
+ {description && (
432
+ <p className="font-sans text-sm text-ods-text-secondary overflow-hidden h-[2.5rem] leading-[1.25rem] mb-2"
433
+ style={{ display: '-webkit-box', WebkitLineClamp: 2, WebkitBoxOrient: 'vertical' }}>{description}</p>
434
+ )}
435
+ <div className="flex items-center gap-2 text-xs text-ods-text-secondary">
436
+ <span className="font-medium">{effectiveData.siteName}</span>
437
+ <span>•</span>
438
+ <span className="truncate">{ogDomain}</span>
439
+ </div>
440
+ </div>
441
+ </div>
442
+ </div>
443
+ </a>
444
+ </div>
445
+ )
446
+ }
@@ -7,6 +7,7 @@ import { useSelfFetch } from '../../hooks/use-self-fetch'
7
7
  import { buildSuggestionUrl } from '../../utils/suggestion-url'
8
8
  import { serializeJsonLd } from '../../utils/common'
9
9
  import { scrollElementIntoView } from '../../utils/scroll-into-view'
10
+ import { faqSectionSlug, faqItemAnchor, parseFaqHash, type FaqHashTarget } from '../../utils/faq-anchor'
10
11
  import { cn } from '../../utils/cn'
11
12
  import { buildFaqJsonLdFromFaqs, type FaqSchemaOptions } from './json-ld'
12
13
  import { SECTION_HEADING_CLASS } from '../layout/page-heading'
@@ -59,19 +60,6 @@ function buildFaqsUrl(
59
60
  return buildSuggestionUrl('/api/faqs', { apiBaseUrl, entityType, entityId, count: minResults })
60
61
  }
61
62
 
62
- /** Stable, URL-safe anchor id for a category. Prefixed so it can't collide
63
- * with other in-page ids, and so a bare numeric/blank section still yields a
64
- * valid id. */
65
- function sectionSlug(section: string): string {
66
- return (
67
- 'faq-' +
68
- section
69
- .toLowerCase()
70
- .replace(/[^a-z0-9]+/g, '-')
71
- .replace(/^-+|-+$/g, '')
72
- )
73
- }
74
-
75
63
  interface FaqGroup {
76
64
  /** null → the uncategorized bucket: no heading, no jump pill, rendered last. */
77
65
  section: string | null
@@ -98,7 +86,7 @@ function groupFaqsBySection(faqs: Faq[]): FaqGroup[] {
98
86
  }
99
87
  let group = byName.get(name)
100
88
  if (!group) {
101
- group = { section: name, slug: sectionSlug(name), items: [] }
89
+ group = { section: name, slug: faqSectionSlug(name), items: [] }
102
90
  byName.set(name, group)
103
91
  order.push(name)
104
92
  }
@@ -113,6 +101,12 @@ function groupFaqsBySection(faqs: Faq[]): FaqGroup[] {
113
101
  * scroll uses, so a category jump lands below the header, not under it. */
114
102
  const FAQ_NAV_HEADER_OFFSET = 96
115
103
 
104
+ /** Map key for the uncategorized bucket — `group.slug` is null for it, so
105
+ * every per-group map (default-open ids, accordion keys) uses this sentinel
106
+ * to keep the lookup typed. */
107
+ const UNCATEGORIZED_KEY = '__uncategorized__'
108
+ const groupKey = (g: FaqGroup): string => g.slug ?? UNCATEGORIZED_KEY
109
+
116
110
  /**
117
111
  * Grouped FAQ layout: a category jump-nav above stacked `<h2>` category
118
112
  * sections (each its own accordion). Isolated into its own component so the
@@ -177,6 +171,54 @@ function GroupedFaqList({
177
171
  // eslint-disable-next-line react-hooks/exhaustive-deps
178
172
  }, [slugKey])
179
173
 
174
+ // ─── Hash dispatch — `/faqs#faq-item-<id>` or `/faqs#faq-<section-slug>` ──
175
+ // Tracks the current hash so:
176
+ // 1. an item-kind hash seeds `defaultOpenIds` on the matching accordion
177
+ // (auto-expands the cited question);
178
+ // 2. either kind triggers the cancellation-proof tween scroll with the
179
+ // sticky-header offset (native browser hash scroll runs once, ignores
180
+ // our offset — re-running the tween puts the target in the right spot).
181
+ // Listens to `hashchange` so back/forward replays the same behavior. SSR-
182
+ // safe: initial null state matches the server render; the first effect
183
+ // tick on the client updates it.
184
+ const [hashTarget, setHashTarget] = useState<FaqHashTarget | null>(null)
185
+ useEffect(() => {
186
+ const refresh = () => setHashTarget(parseFaqHash(window.location.hash))
187
+ refresh()
188
+ window.addEventListener('hashchange', refresh)
189
+ return () => window.removeEventListener('hashchange', refresh)
190
+ }, [])
191
+
192
+ // Per-group default-open set when the hash points at an item. The map key
193
+ // matches `groupKey(group)` so the render-time lookup is O(1) per group.
194
+ const defaultOpenByGroupKey = useMemo(() => {
195
+ if (hashTarget?.kind !== 'item') return null
196
+ const targetId = hashTarget.rawId
197
+ const result = new Map<string, (string | number)[]>()
198
+ for (const group of groups) {
199
+ const hit = group.items.find((i) => String(i.id) === targetId)
200
+ if (hit) result.set(groupKey(group), [hit.id])
201
+ }
202
+ return result.size > 0 ? result : null
203
+ }, [groups, hashTarget])
204
+
205
+ // Accordion is uncontrolled — `defaultOpenIds` is only consumed at mount,
206
+ // so a new item hash needs a remount to honor it. Keying off the item-id
207
+ // suffix triggers exactly the remount we need (and stays stable when the
208
+ // hash points at a section, so category navigation never disturbs the
209
+ // accordion's open state).
210
+ const accordionKeySuffix =
211
+ hashTarget?.kind === 'item' ? `item:${hashTarget.rawId}` : 'default'
212
+
213
+ useEffect(() => {
214
+ if (!hashTarget) return
215
+ const elId =
216
+ hashTarget.kind === 'item' ? faqItemAnchor(hashTarget.rawId) : hashTarget.slug
217
+ const el = document.getElementById(elId)
218
+ if (el) scrollElementIntoView(el, { headerOffset: FAQ_NAV_HEADER_OFFSET })
219
+ if (hashTarget.kind === 'section') setActiveSlug(hashTarget.slug)
220
+ }, [hashTarget])
221
+
180
222
  const handleJump = useCallback(
181
223
  (e: React.MouseEvent<HTMLAnchorElement>, slug: string) => {
182
224
  e.preventDefault()
@@ -215,18 +257,28 @@ function GroupedFaqList({
215
257
  </nav>
216
258
  )}
217
259
  <div className="space-y-10">
218
- {groups.map((group) => (
219
- <section
220
- key={group.slug ?? 'faq-uncategorized'}
221
- id={group.slug ?? undefined}
222
- className="scroll-mt-24 space-y-4"
223
- >
224
- {group.section && (
225
- <CategoryHeading className={SECTION_HEADING_CLASS}>{group.section}</CategoryHeading>
226
- )}
227
- <FaqAccordion items={group.items} />
228
- </section>
229
- ))}
260
+ {groups.map((group) => {
261
+ const key = groupKey(group)
262
+ return (
263
+ <section
264
+ key={key}
265
+ id={group.slug ?? undefined}
266
+ className="scroll-mt-24 space-y-4"
267
+ >
268
+ {group.section && (
269
+ <CategoryHeading className={SECTION_HEADING_CLASS}>{group.section}</CategoryHeading>
270
+ )}
271
+ <FaqAccordion
272
+ // Re-key on item-hash changes so the remount picks up the new
273
+ // `defaultOpenIds` (the accordion is uncontrolled). Stable for
274
+ // section hashes — category navigation doesn't disturb state.
275
+ key={`${key}:${accordionKeySuffix}`}
276
+ items={group.items}
277
+ defaultOpenIds={defaultOpenByGroupKey?.get(key)}
278
+ />
279
+ </section>
280
+ )
281
+ })}
230
282
  </div>
231
283
  </div>
232
284
  )
@@ -3,6 +3,7 @@
3
3
  import React, { useRef, useState, useEffect, useCallback } from 'react'
4
4
  import { ChevronButton } from './ui/chevron-button'
5
5
  import { cn } from "../utils/cn"
6
+ import { faqItemAnchor } from "../utils/faq-anchor"
6
7
 
7
8
  export interface FaqItem {
8
9
  id: number | string
@@ -60,7 +61,13 @@ export function FaqAccordion({ items, defaultOpenIds = [] }: FaqAccordionProps)
60
61
  return (
61
62
  <div
62
63
  key={item.id}
63
- className={cn('group transition-colors hover:bg-[#1E1E1E]', isOpen ? 'bg-ods-bg' : 'bg-transparent')}
64
+ // Per-row anchor — chat citation chips (`/faqs#faq-item-<id>`) land
65
+ // here via native browser hash scroll AND via `FaqSection`'s tween
66
+ // dispatch. `scroll-mt-24` keeps the row header below the 96px
67
+ // sticky nav offset (matches `<section>`'s scroll-margin for
68
+ // category anchors).
69
+ id={faqItemAnchor(item.id)}
70
+ className={cn('group scroll-mt-24 transition-colors hover:bg-[#1E1E1E]', isOpen ? 'bg-ods-bg' : 'bg-transparent')}
64
71
  >
65
72
  {/* Header */}
66
73
  <div
@@ -347,6 +347,7 @@ export type ContentSourceType =
347
347
  | 'investor_update' // Investor updates
348
348
  | 'onboarding_guide' // Onboarding guides (lives on openframe platform)
349
349
  | 'what_i_shipped' // What I Shipped employee check-ins (lives on people-hub)
350
+ | 'faq' // FAQ Q&A pair (single-page /faqs index; deep-link by category anchor)
350
351
  | 'from_scratch';
351
352
 
352
353
  export type URLInjectionPreference = 'none' | 'in_post' | 'as_comment';