@sarimarcus/content-sites-ui 0.55.3 → 0.56.1

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.
@@ -0,0 +1,506 @@
1
+ ---
2
+ /**
3
+ * ArticlePage — Shared long-form article detail template (SLA-3720).
4
+ * Used across both travel sites (with optional `era`, `ArticleEraPeople` slot, `AffiliateCarouselComponent`,
5
+ * `AmazonProductSection` slot) and articles-only editorial sites (with `ShareButtons`, specialist role badge,
6
+ * controlled topic `tags`, and compact "Desvío" interlude cards).
7
+ */
8
+ import type { ImageMetadata } from 'astro';
9
+ import type { EraDefinition } from '@sarimarcus/content-sites-core/eras';
10
+ import { splitParagraphs, renderInlineMarkdown } from '@sarimarcus/content-sites-core/articles';
11
+ import { slugify, parseMarkdownInline } from '@sarimarcus/content-sites-core/text';
12
+ import { routePath, type SiteRoutes } from '@sarimarcus/content-sites-core/url';
13
+ import Container from '../layout/Container.astro';
14
+ import ContentHero from '../layout/ContentHero.astro';
15
+ import BreadcrumbBand from '../layout/BreadcrumbBand.astro';
16
+ import Breadcrumb from '../seo/Breadcrumb.astro';
17
+ import ArticleMetadata from '../seo/ArticleMetadata.astro';
18
+ import AuthoritativeSources from '../seo/AuthoritativeSources.astro';
19
+ import type { ArticleAuthor, BreadcrumbItem, DomainClassifier, SourceInput } from '../seo/types';
20
+ import TableOfContents from '../composed/TableOfContents.astro';
21
+ import FAQ from '../composed/FAQ.astro';
22
+ import InlineImage from '../composed/InlineImage.astro';
23
+ import RelatedContent from '../composed/RelatedContent.astro';
24
+ import type { RelatedItem } from '../composed/related';
25
+ import Chip from '../primitives/Chip.astro';
26
+ import { trustedHtml } from '../types';
27
+ import { getLabels } from '../internal/labels';
28
+ import ArticleKeyFacts from './ArticleKeyFacts.astro';
29
+ import ArticleTopicPager from './ArticleTopicPager.astro';
30
+ import ShareButtons from './ShareButtons.astro';
31
+ import Interlude from './interludes/Interlude.astro';
32
+ import RelatedCard from './interludes/RelatedCard.astro';
33
+ import { DEFAULT_INTERLUDE_LABELS } from './article-page';
34
+ import type { InterludeData, InterludeLabels } from './interludes/types';
35
+ import type { KeyFact, TopicPagerLink } from './types';
36
+
37
+ export interface ArticlePageResolvedCard {
38
+ href: string;
39
+ eyebrow: string;
40
+ title: string;
41
+ description?: string;
42
+ variant?: 'inline' | 'featured' | 'compact';
43
+ image?: ImageMetadata;
44
+ imageAlt?: string;
45
+ eyebrowClass?: string;
46
+ }
47
+
48
+ export interface ArticlePageTagLink {
49
+ tag: string;
50
+ label: string;
51
+ href: string;
52
+ }
53
+
54
+ export interface ArticlePageSection {
55
+ heading: string;
56
+ body: string;
57
+ subsections?: readonly { heading: string; body: string }[];
58
+ interludes?: readonly any[];
59
+ inlineImages?: readonly { slug: string; alt: string; caption?: string; afterParagraph: number }[];
60
+ affiliateCarousels?: readonly { ids?: number[]; afterParagraph: number; heading?: string }[];
61
+ }
62
+
63
+ export interface ArticlePageData {
64
+ slug: string;
65
+ title: string;
66
+ description: string;
67
+ intro: string;
68
+ imageAlt: string;
69
+ imageTitle?: string;
70
+ author?: string;
71
+ datePublished?: string;
72
+ dateModified?: string;
73
+ category?: string;
74
+ tags?: readonly string[];
75
+ audiences?: readonly string[];
76
+ keyFacts?: readonly { figure: string; label: string; detail: string }[];
77
+ sections: readonly ArticlePageSection[];
78
+ faqs?: readonly { question: string; answer: string }[];
79
+ sources?: readonly SourceInput[];
80
+ }
81
+
82
+ interface Props {
83
+ article: ArticlePageData;
84
+ heroImage?: ImageMetadata;
85
+ inlineImages?: Readonly<Record<string, ImageMetadata>>;
86
+ breadcrumbs: BreadcrumbItem[];
87
+ breadcrumbProps?: {
88
+ separator?: 'chevron' | 'star';
89
+ separatorColorClass?: string;
90
+ compactMobile?: boolean;
91
+ };
92
+ author?: ArticleAuthor;
93
+ era?: EraDefinition;
94
+ eraBasePath?: string;
95
+ timeZone?: string;
96
+ locale?: string;
97
+ basePath?: string;
98
+ routes?: SiteRoutes;
99
+ /** Render ShareButtons below byline and at end of article body (SLA-3718). */
100
+ shareUrl?: string;
101
+ showShareButtons?: boolean;
102
+ /** Enable decorative drop-cap on the lede paragraph when it starts with a letter/quote. */
103
+ dropCap?: boolean;
104
+ /** Emit hidden sr-only audience spans for Pagefind facet filtering. */
105
+ emitAudienceFacets?: boolean;
106
+ /** Eyebrow text on the no-hero fallback header. */
107
+ noHeroEyebrow?: string;
108
+ noHeroEyebrowClass?: string;
109
+ keyFactsAriaLabel?: string;
110
+ tocProps?: {
111
+ miniLinkClass?: string;
112
+ hideMiniPastLastSection?: boolean;
113
+ };
114
+ sectionScrollMarginClass?: string;
115
+ proseClass?: string;
116
+ interludeLabels?: InterludeLabels;
117
+ didYouKnowVariant?: 'ruled' | 'inline';
118
+ didYouKnowLabelClass?: string;
119
+ /** Resolves an entity interlude (`related-card`, `monument-feature`, `article-feature`) into RelatedCard props. */
120
+ resolveEntityInterlude?: (interlude: any) => ArticlePageResolvedCard | null | undefined;
121
+ /** Optional site-specific AffiliateCarousel component for `section.affiliateCarousels`. */
122
+ AffiliateCarouselComponent?: any;
123
+ sourcesProps?: {
124
+ domainLabels?: Record<string, string>;
125
+ domainClass?: DomainClassifier;
126
+ disambiguate?: boolean;
127
+ eyebrowClass?: string;
128
+ };
129
+ topicPager?: {
130
+ topic: { label: string; href: string; count?: number };
131
+ newer?: TopicPagerLink;
132
+ older?: TopicPagerLink;
133
+ } | null;
134
+ tagLinks?: readonly ArticlePageTagLink[];
135
+ relatedItems?: RelatedItem[];
136
+ relatedProps?: {
137
+ title?: string;
138
+ variant?: 'bordered' | 'card' | 'plain';
139
+ layout?: 'grid' | 'carousel';
140
+ columns?: 2 | 3;
141
+ trackingBlock?: string;
142
+ };
143
+ /** Optional "All articles" back-link at the bottom of the page. */
144
+ backLink?: { href: string; label?: string } | null;
145
+ }
146
+
147
+ const {
148
+ article,
149
+ heroImage,
150
+ inlineImages = {},
151
+ breadcrumbs,
152
+ breadcrumbProps = {},
153
+ author,
154
+ era,
155
+ eraBasePath,
156
+ timeZone = 'Europe/Madrid',
157
+ locale,
158
+ basePath = import.meta.env.BASE_URL,
159
+ routes = {},
160
+ shareUrl,
161
+ showShareButtons = false,
162
+ dropCap = false,
163
+ emitAudienceFacets = false,
164
+ noHeroEyebrow,
165
+ noHeroEyebrowClass = 'text-xs font-semibold uppercase tracking-widest text-primary mb-3',
166
+ keyFactsAriaLabel,
167
+ tocProps = {},
168
+ sectionScrollMarginClass = 'scroll-mt-28',
169
+ proseClass = 'prose prose-lg max-w-none prose-headings:font-display prose-a:text-primary prose-a:no-underline hover:prose-a:underline',
170
+ interludeLabels = DEFAULT_INTERLUDE_LABELS,
171
+ didYouKnowVariant,
172
+ didYouKnowLabelClass,
173
+ resolveEntityInterlude,
174
+ AffiliateCarouselComponent,
175
+ sourcesProps = {},
176
+ topicPager = null,
177
+ tagLinks = [],
178
+ relatedItems = [],
179
+ relatedProps = {},
180
+ backLink = null,
181
+ } = Astro.props;
182
+
183
+ const l = getLabels(locale).articlePage;
184
+ const sourcesLen = article.sources?.length ?? 0;
185
+ const md = (text: string) => trustedHtml(renderInlineMarkdown(text, basePath, sourcesLen));
186
+ const introHtml = parseMarkdownInline(article.intro, basePath, sourcesLen);
187
+ const hasDropCap = dropCap && /^["'«“‘]?[A-Za-zÀ-ÖØ-öø-ÿ]/.test(article.intro.trimStart());
188
+
189
+ const tocItems = article.sections.map((s) => ({
190
+ label: s.heading,
191
+ href: `#${slugify(s.heading)}`,
192
+ }));
193
+ const showToc = tocItems.length >= 3;
194
+
195
+ const keyFactsItems: KeyFact[] = (article.keyFacts ?? []).map((f) => ({
196
+ figure: f.figure,
197
+ label: f.label,
198
+ detailHtml: md(f.detail),
199
+ }));
200
+
201
+ const faqItems = (article.faqs ?? []).map((f) => ({
202
+ questionHtml: trustedHtml(parseMarkdownInline(f.question, basePath)),
203
+ answerHtml: trustedHtml(parseMarkdownInline(f.answer, basePath, sourcesLen)),
204
+ }));
205
+
206
+ type BodyBlock =
207
+ | { kind: 'paragraph'; html: string }
208
+ | { kind: 'interlude'; data: InterludeData }
209
+ | { kind: 'entity'; card: ArticlePageResolvedCard }
210
+ | { kind: 'image'; image: { slug: string; alt: string; caption?: string; afterParagraph: number }; meta: ImageMetadata }
211
+ | { kind: 'affiliate-carousel'; carousel: { ids?: number[]; afterParagraph: number; heading?: string } };
212
+
213
+ function buildSectionBlocks(section: ArticlePageSection): BodyBlock[] {
214
+ const paragraphs = splitParagraphs(section.body, basePath, sourcesLen);
215
+ const blocks: BodyBlock[] = [];
216
+ const interludes = section.interludes ?? [];
217
+ const images = section.inlineImages ?? [];
218
+ const carousels = section.affiliateCarousels ?? [];
219
+
220
+ const pushInterlude = (il: any) => {
221
+ if (il.type === 'related-card' || il.type === 'monument-feature' || il.type === 'article-feature') {
222
+ const card = resolveEntityInterlude?.(il);
223
+ if (card) blocks.push({ kind: 'entity', card });
224
+ return;
225
+ }
226
+ blocks.push({ kind: 'interlude', data: il as InterludeData });
227
+ };
228
+
229
+ paragraphs.forEach((html, idx) => {
230
+ blocks.push({ kind: 'paragraph', html });
231
+
232
+ for (const il of interludes) {
233
+ if (il.type !== 'tldr' && 'afterParagraph' in il && il.afterParagraph === idx) {
234
+ pushInterlude(il);
235
+ }
236
+ }
237
+
238
+ for (const img of images) {
239
+ if (img.afterParagraph === idx) {
240
+ const meta = inlineImages[img.slug];
241
+ if (meta) blocks.push({ kind: 'image', image: img, meta });
242
+ }
243
+ }
244
+
245
+ for (const c of carousels) {
246
+ if (c.afterParagraph === idx) {
247
+ blocks.push({ kind: 'affiliate-carousel', carousel: c });
248
+ }
249
+ }
250
+ });
251
+
252
+ for (const il of interludes) {
253
+ if (il.type !== 'tldr' && 'afterParagraph' in il && il.afterParagraph >= paragraphs.length) {
254
+ pushInterlude(il);
255
+ }
256
+ }
257
+
258
+ for (const img of images) {
259
+ if (img.afterParagraph >= paragraphs.length) {
260
+ const meta = inlineImages[img.slug];
261
+ if (meta) blocks.push({ kind: 'image', image: img, meta });
262
+ }
263
+ }
264
+
265
+ for (const c of carousels) {
266
+ if (c.afterParagraph >= paragraphs.length) {
267
+ blocks.push({ kind: 'affiliate-carousel', carousel: c });
268
+ }
269
+ }
270
+
271
+ for (const il of interludes) {
272
+ if (il.type === 'tldr' || ('position' in il && il.position === 'end')) {
273
+ pushInterlude(il);
274
+ }
275
+ }
276
+
277
+ return blocks;
278
+ }
279
+
280
+ const resolvedNoHeroEyebrow = noHeroEyebrow ?? l.articlesLabel;
281
+ const resolvedKeyFactsAria = keyFactsAriaLabel ?? article.title;
282
+ const resolvedRelatedTitle = relatedProps.title ?? l.relatedTitle;
283
+ ---
284
+
285
+ <slot name="head" />
286
+
287
+ <article data-pagefind-body data-pagefind-meta="type:article">
288
+ {emitAudienceFacets && article.audiences?.map((a) => (
289
+ <span class="sr-only" data-pagefind-filter={`audience:${a}`}>{a}</span>
290
+ ))}
291
+
292
+ {heroImage ? (
293
+ <>
294
+ <ContentHero
295
+ title={article.title}
296
+ description={article.description}
297
+ image={heroImage}
298
+ imageAlt={article.imageAlt}
299
+ imageTitle={article.imageTitle}
300
+ overlay="editorial"
301
+ minHeight="medium"
302
+ class="mt-16"
303
+ />
304
+ <BreadcrumbBand class="bg-muted/50 border-b border-border">
305
+ <Breadcrumb items={breadcrumbs} {...breadcrumbProps} />
306
+ </BreadcrumbBand>
307
+ </>
308
+ ) : (
309
+ <>
310
+ <BreadcrumbBand>
311
+ <Breadcrumb items={breadcrumbs} {...breadcrumbProps} />
312
+ </BreadcrumbBand>
313
+ <header class="pt-10 pb-6 border-b border-border">
314
+ <Container size="measure">
315
+ <p class={noHeroEyebrowClass}>{resolvedNoHeroEyebrow}</p>
316
+ <h1 class="text-3xl sm:text-4xl lg:text-5xl font-normal font-display text-foreground leading-tight mb-4">
317
+ {article.title}
318
+ </h1>
319
+ <p class="text-lg text-muted-foreground leading-relaxed">{article.description}</p>
320
+ </Container>
321
+ </header>
322
+ </>
323
+ )}
324
+
325
+ <main>
326
+ <Container size="measure" class="py-10 sm:py-14">
327
+ <ArticleMetadata
328
+ author={author}
329
+ datePublished={article.datePublished}
330
+ dateModified={article.dateModified}
331
+ timeZone={timeZone}
332
+ locale={locale}
333
+ era={era}
334
+ eraBasePath={eraBasePath}
335
+ />
336
+
337
+ {showShareButtons && shareUrl && (
338
+ <div class="mb-6">
339
+ <ShareButtons url={shareUrl} title={article.title} locale={locale} />
340
+ </div>
341
+ )}
342
+
343
+ <slot name="after-byline" />
344
+
345
+ <div
346
+ class="article-lede text-lg sm:text-xl text-foreground/90 leading-relaxed mb-8 font-normal border-l-2 border-primary/40 pl-5"
347
+ data-dropcap={hasDropCap ? '' : undefined}
348
+ set:html={introHtml}
349
+ />
350
+
351
+ <slot name="after-intro" />
352
+
353
+ {keyFactsItems.length >= 3 && (
354
+ <ArticleKeyFacts
355
+ items={keyFactsItems}
356
+ ariaLabel={resolvedKeyFactsAria}
357
+ class="my-8"
358
+ />
359
+ )}
360
+
361
+ {showToc && (
362
+ <div class="mb-10" data-pagefind-ignore>
363
+ <TableOfContents items={tocItems} {...tocProps} />
364
+ </div>
365
+ )}
366
+
367
+ <div class={proseClass}>
368
+ {article.sections.map((section) => {
369
+ const blocks = buildSectionBlocks(section);
370
+ const subParagraphs = (section.subsections ?? []).map((sub) => ({
371
+ heading: sub.heading,
372
+ id: slugify(sub.heading),
373
+ paragraphs: splitParagraphs(sub.body, basePath, sourcesLen),
374
+ }));
375
+ return (
376
+ <section id={slugify(section.heading)} class:list={['mb-10', sectionScrollMarginClass]}>
377
+ <h2 class="text-2xl sm:text-3xl font-normal font-display text-foreground mb-4">
378
+ {section.heading}
379
+ </h2>
380
+ {blocks.map((block) => {
381
+ if (block.kind === 'paragraph') {
382
+ return <div class="text-base text-muted-foreground leading-relaxed mb-4" set:html={block.html} />;
383
+ }
384
+ if (block.kind === 'interlude') {
385
+ return (
386
+ <Interlude
387
+ interlude={block.data}
388
+ renderInline={md}
389
+ labels={interludeLabels}
390
+ author={article.author}
391
+ didYouKnowVariant={didYouKnowVariant}
392
+ didYouKnowLabelClass={didYouKnowLabelClass}
393
+ />
394
+ );
395
+ }
396
+ if (block.kind === 'entity') {
397
+ return <RelatedCard {...block.card} />;
398
+ }
399
+ if (block.kind === 'image') {
400
+ return (
401
+ <div class="not-prose my-8">
402
+ <InlineImage
403
+ src={block.meta}
404
+ alt={block.image.alt}
405
+ captionHtml={block.image.caption ? md(block.image.caption) : undefined}
406
+ size="auto"
407
+ />
408
+ </div>
409
+ );
410
+ }
411
+ if (block.kind === 'affiliate-carousel' && AffiliateCarouselComponent) {
412
+ return (
413
+ <div class="not-prose my-8">
414
+ <AffiliateCarouselComponent
415
+ ids={block.carousel.ids}
416
+ heading={block.carousel.heading}
417
+ />
418
+ </div>
419
+ );
420
+ }
421
+ return null;
422
+ })}
423
+
424
+ {subParagraphs.map((sub) => (
425
+ <div id={sub.id} class:list={['mt-6', sectionScrollMarginClass]}>
426
+ <h3 class="text-xl sm:text-2xl font-normal font-display text-foreground mb-3">
427
+ {sub.heading}
428
+ </h3>
429
+ {sub.paragraphs.map((pHtml) => (
430
+ <div class="text-base text-muted-foreground leading-relaxed mb-3" set:html={pHtml} />
431
+ ))}
432
+ </div>
433
+ ))}
434
+ </section>
435
+ );
436
+ })}
437
+ </div>
438
+
439
+ {faqItems.length > 0 && (
440
+ <div class="mt-12 pt-8 border-t border-border">
441
+ <FAQ items={faqItems} id="faq" locale={locale} />
442
+ </div>
443
+ )}
444
+
445
+ {article.sources && article.sources.length > 0 && (
446
+ <AuthoritativeSources
447
+ sources={article.sources as SourceInput[]}
448
+ lang={locale}
449
+ {...sourcesProps}
450
+ />
451
+ )}
452
+
453
+ {tagLinks.length > 0 && (
454
+ <nav aria-label={l.tagsAriaLabel} class="mt-10 pt-6 border-t border-border flex flex-wrap items-center gap-2" data-pagefind-ignore>
455
+ {tagLinks.map((t) => (
456
+ <Chip href={t.href} size="sm" tone="outlineQuiet">
457
+ #{t.label}
458
+ </Chip>
459
+ ))}
460
+ </nav>
461
+ )}
462
+
463
+ {showShareButtons && shareUrl && (
464
+ <div class="mt-8 pt-6 border-t border-border" data-pagefind-ignore>
465
+ <ShareButtons url={shareUrl} title={article.title} locale={locale} />
466
+ </div>
467
+ )}
468
+
469
+ {topicPager && (
470
+ <ArticleTopicPager
471
+ topic={topicPager.topic}
472
+ newer={topicPager.newer}
473
+ older={topicPager.older}
474
+ locale={locale}
475
+ />
476
+ )}
477
+
478
+ {relatedItems.length > 0 && (
479
+ <div class="mt-12" data-pagefind-ignore>
480
+ <RelatedContent
481
+ title={resolvedRelatedTitle}
482
+ items={relatedItems}
483
+ variant={relatedProps.variant ?? 'bordered'}
484
+ layout={relatedProps.layout ?? 'carousel'}
485
+ columns={relatedProps.columns ?? 2}
486
+ trackingBlock={relatedProps.trackingBlock ?? 'related-content'}
487
+ />
488
+ </div>
489
+ )}
490
+
491
+ <slot name="after-related" />
492
+
493
+ {backLink && (
494
+ <footer class="mt-12 pt-6 border-t border-border">
495
+ <a
496
+ href={backLink.href}
497
+ class="inline-flex items-center gap-2 text-sm font-medium text-primary hover:underline"
498
+ >
499
+ <span aria-hidden="true">&larr;</span>
500
+ <span>{backLink.label ?? l.allArticlesLabel}</span>
501
+ </a>
502
+ </footer>
503
+ )}
504
+ </Container>
505
+ </main>
506
+ </article>
@@ -0,0 +1,88 @@
1
+ ---
2
+ /**
3
+ * ArticleTagPage — a controlled tag hub (/articles/tag/<tag>) inside ArticlesListingPage (SLA-3716).
4
+ * Slots:
5
+ * breadcrumb — the site Breadcrumb.
6
+ * grid — the site's ArticleCardGrid for this tag.
7
+ * pagination — optional pagination.
8
+ */
9
+ import Container from '../layout/Container.astro';
10
+ import Chip from '../primitives/Chip.astro';
11
+ import { getLabels } from '../internal/labels';
12
+ import ArticlesListingPage from './ArticlesListingPage.astro';
13
+ import ArticleCategoryNav from './ArticleCategoryNav.astro';
14
+ import type { ArticleCategoryMeta } from './types';
15
+
16
+ export interface ArticleTagPill {
17
+ tag: string;
18
+ label: string;
19
+ href: string;
20
+ count: number;
21
+ }
22
+
23
+ interface Props {
24
+ eyebrow?: string;
25
+ heading: string;
26
+ lede: string;
27
+ tag: string;
28
+ count: number;
29
+ articles?: readonly { data: { category?: string | null } }[];
30
+ categories?: Readonly<Record<string, ArticleCategoryMeta>>;
31
+ relatedTags?: readonly ArticleTagPill[];
32
+ locale?: string;
33
+ }
34
+
35
+ const {
36
+ eyebrow,
37
+ heading,
38
+ lede,
39
+ tag,
40
+ count,
41
+ articles = [],
42
+ categories,
43
+ relatedTags = [],
44
+ locale,
45
+ } = Astro.props;
46
+ const l = getLabels(locale).articleTagPage;
47
+ const resolvedEyebrow = eyebrow ?? l.eyebrow;
48
+ const countWord = count === 1 ? l.countOne : l.countMany;
49
+ ---
50
+
51
+ <ArticlesListingPage eyebrow={resolvedEyebrow} heading={heading} lede={lede} pagefindBody>
52
+ <slot name="breadcrumb" slot="breadcrumb" />
53
+ <p slot="header-extra" class="mt-4 text-sm text-muted-foreground">
54
+ <span>{count}</span> <span>{countWord}</span>
55
+ </p>
56
+
57
+ <Container>
58
+ {categories && articles.length > 0 && (
59
+ <ArticleCategoryNav articles={articles} categories={categories} class="mb-8" />
60
+ )}
61
+
62
+ {relatedTags.length > 1 && (
63
+ <div class="mb-10 flex flex-wrap items-center gap-2">
64
+ {relatedTags.map((item) => {
65
+ const active = item.tag === tag;
66
+ return (
67
+ <Chip
68
+ href={item.href}
69
+ size="sm"
70
+ tone="outline"
71
+ accent="primary"
72
+ active={active}
73
+ aria-current={active ? 'page' : undefined}
74
+ >
75
+ <span>#{item.label}</span>
76
+ <span class="opacity-70">({item.count})</span>
77
+ </Chip>
78
+ );
79
+ })}
80
+ </div>
81
+ )}
82
+
83
+ <section id="tag-articles">
84
+ <slot name="grid" />
85
+ <slot name="pagination" />
86
+ </section>
87
+ </Container>
88
+ </ArticlesListingPage>