@tansy/theme-halo 0.0.0-stage → 0.1.0

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.
package/render.js ADDED
@@ -0,0 +1,369 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import localFont from "next/font/local";
3
+ import { PostComments, PostMeta, PostTags } from "@tansy/blog/render";
4
+ import { authPath, Menu, pageHref, pickWords, sitePath, StreamField } from "tansy/react";
5
+ import { defineThemeComponents } from "tansy/theme";
6
+ import { Carousel, HeaderSearch, TimeAgo } from "./client";
7
+ import "./theme.css";
8
+ // Served from the site's own origin, as font-src 'self' requires.
9
+ const font = localFont({ src: "./fonts/GeistVF.woff", variable: "--halo-font", weight: "100 900" });
10
+ const text = (value) => (typeof value === "string" ? value : "");
11
+ const ids = (value) => (Array.isArray(value) ? value.filter((id) => typeof id === "number") : typeof value === "number" ? [value] : []);
12
+ const items = (list) => list?.items ?? [];
13
+ const byId = (list) => new Map(items(list).map((record) => [record.id, record]));
14
+ /**
15
+ * The theme's words, under `halo`, so a client part gets only these with `pickWords`. Owners
16
+ * can change any of them per language under Languages → Site text. The blog's own words, such
17
+ * as `blog.minutes`, come from the blog plugin.
18
+ */
19
+ const messages = {
20
+ en: {
21
+ halo: {
22
+ front: "Front page",
23
+ bestOfWeek: "Best of the week",
24
+ recommended: "Recommended",
25
+ latest: "Latest news",
26
+ trending: "Trending now",
27
+ readersChoice: "Readers’ choice",
28
+ readersChoiceBadge: "Readers’ choice",
29
+ thisWeek: "this week",
30
+ popular: "Popular news",
31
+ moreLikeThis: "More like this",
32
+ viewMore: "View more",
33
+ viewAll: "View all",
34
+ readArticle: "Read article",
35
+ noStories: "No stories yet. Publish a post and it shows here.",
36
+ noStoriesHere: "No stories here yet.",
37
+ newer: "Newer stories",
38
+ older: "Older stories",
39
+ pages: "Pages",
40
+ pageOf: "Page {page} of {total}",
41
+ previous: "Previous",
42
+ next: "Next",
43
+ searchLabel: "Search articles",
44
+ searchPlaceholder: "Article name, tag, category…",
45
+ searching: "Searching…",
46
+ searchFailed: "Search isn't working right now. Try again in a moment.",
47
+ found: "{count, plural, one {# article found} other {# articles found}}",
48
+ noResults: "No articles match “{query}”.",
49
+ signIn: "Sign in",
50
+ register: "Register",
51
+ menu: "Main",
52
+ openMenu: "Menu",
53
+ footerMenu: "Footer",
54
+ language: "Language",
55
+ skip: "Skip to content",
56
+ rights: "All rights reserved.",
57
+ },
58
+ },
59
+ ar: {
60
+ halo: {
61
+ front: "الصفحة الأولى",
62
+ bestOfWeek: "الأفضل هذا الأسبوع",
63
+ recommended: "مقترحة لك",
64
+ latest: "آخر الأخبار",
65
+ trending: "الأكثر تداولًا",
66
+ readersChoice: "اختيار القرّاء",
67
+ readersChoiceBadge: "اختيار القرّاء",
68
+ thisWeek: "هذا الأسبوع",
69
+ popular: "الأكثر قراءة",
70
+ moreLikeThis: "مقالات مشابهة",
71
+ viewMore: "عرض المزيد",
72
+ viewAll: "عرض الكل",
73
+ readArticle: "اقرأ المقال",
74
+ noStories: "لا توجد مقالات بعد. انشر مقالًا وسيظهر هنا.",
75
+ noStoriesHere: "لا توجد مقالات هنا بعد.",
76
+ newer: "مقالات أحدث",
77
+ older: "مقالات أقدم",
78
+ pages: "الصفحات",
79
+ pageOf: "الصفحة {page} من {total}",
80
+ previous: "السابق",
81
+ next: "التالي",
82
+ searchLabel: "ابحث في المقالات",
83
+ searchPlaceholder: "اسم المقال، وسم، تصنيف…",
84
+ searching: "جارٍ البحث…",
85
+ searchFailed: "البحث لا يعمل الآن. حاول مجددًا بعد قليل.",
86
+ found: "{count, plural, zero {لا توجد نتائج} one {مقال واحد} two {مقالان} few {# مقالات} many {# مقالًا} other {# مقال}}",
87
+ noResults: "لا توجد مقالات تطابق «{query}».",
88
+ signIn: "تسجيل الدخول",
89
+ register: "إنشاء حساب",
90
+ menu: "القائمة الرئيسية",
91
+ openMenu: "القائمة",
92
+ footerMenu: "روابط التذييل",
93
+ language: "اللغة",
94
+ skip: "انتقل إلى المحتوى",
95
+ rights: "جميع الحقوق محفوظة.",
96
+ },
97
+ },
98
+ };
99
+ /** A site address in the page's language, under the site's path prefix if it has one. */
100
+ const link = (props, path) => sitePath(props.words, path);
101
+ /** From the collection's URL pattern, so links follow whatever the owner sets. */
102
+ const hrefOf = (record, props) => (record && text(record.recordPath) ? link(props, text(record.recordPath)) : undefined);
103
+ /** Where "View more" goes: the blog's own address, when visitors can read it. */
104
+ const blogHref = (props) => hrefOf(items(props.data.blogHome)[0], props);
105
+ const localeOf = (props) => props.words?.locale ?? props.language?.locale ?? "en";
106
+ /* ------------------------------------------------------------------- icons */
107
+ const Arrow = ({ back = false }) => (_jsx("svg", { className: back ? "ha-arrow ha-arrow-back" : "ha-arrow", "aria-hidden": "true", viewBox: "0 0 20 20", width: "16", height: "16", children: _jsx("path", { fill: "none", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round", strokeLinejoin: "round", d: "M4 10h12m-5-5 5 5-5 5" }) }));
108
+ /* ------------------------------------------------------------- story parts */
109
+ function When({ value, props }) {
110
+ const date = text(value);
111
+ if (!props.options.showDates || !date)
112
+ return null;
113
+ const label = props.formatDate(date, "medium");
114
+ return props.options.relativeDates ? _jsx(TimeAgo, { date: date, label: label, locale: localeOf(props) }) : _jsx("time", { dateTime: date, children: label });
115
+ }
116
+ /** Category · time. The category is a link of its own, above the story's link. */
117
+ function Meta({ story, props }) {
118
+ const category = byId(props.data.categories).get(ids(story.categories)[0] ?? -1);
119
+ const dated = props.options.showDates && Boolean(text(story.publishedAt));
120
+ if (!category && !dated)
121
+ return null;
122
+ const href = hrefOf(category, props);
123
+ return (_jsxs("p", { className: "ha-meta", children: [category && (href ? _jsx("a", { className: "ha-category", href: href, children: text(category.name) }) : _jsx("span", { className: "ha-category", children: text(category.name) })), category && dated && _jsx("span", { className: "ha-dot", "aria-hidden": "true" }), _jsx(When, { value: story.publishedAt, props: props })] }));
124
+ }
125
+ /** Its first tags, as #links. */
126
+ function Tags({ story, props, limit = 2 }) {
127
+ const tags = byId(props.data.tags);
128
+ const found = ids(story.tags).map((id) => tags.get(id)).filter((tag) => Boolean(tag)).slice(0, limit);
129
+ if (!found.length)
130
+ return null;
131
+ return (_jsx("ul", { className: "ha-tags", children: found.map((tag) => {
132
+ const href = hrefOf(tag, props);
133
+ return _jsx("li", { children: href ? _jsxs("a", { href: href, children: ["#", text(tag.name)] }) : `#${text(tag.name)}` }, tag.id);
134
+ }) }));
135
+ }
136
+ /** The story's title as a link that covers its whole card, so the card is one stop for the keyboard. */
137
+ function Title({ story, props, as: Tag = "h3", className }) {
138
+ const href = hrefOf(story, props);
139
+ return _jsx(Tag, { className: className, children: href ? _jsx("a", { className: "ha-cover-link", href: href, children: text(story.title) }) : text(story.title) });
140
+ }
141
+ function Picture({ story, props, size, className, eager = false }) {
142
+ const cover = text(story.cover);
143
+ // eslint-disable-next-line @next/next/no-img-element -- an access-checked API address that redirects to a signed URL, which next/image can't optimize
144
+ if (cover)
145
+ return _jsx("img", { className: className, src: props.fileUrl(cover, size), alt: props.fileText(cover).alt, style: { objectPosition: props.fileFocus(cover).objectPosition }, loading: eager ? "eager" : "lazy" });
146
+ return _jsx("span", { className: `${className} ha-blank`, "aria-hidden": "true" });
147
+ }
148
+ function ReadButton({ story, props }) {
149
+ const href = hrefOf(story, props);
150
+ if (!href)
151
+ return null;
152
+ return (_jsxs("a", { className: "ha-read", href: href, children: [props.t("halo.readArticle"), _jsx("span", { className: "ha-read-icon", children: _jsx(Arrow, {}) }), _jsxs("span", { className: "ha-visually-hidden", children: [": ", text(story.title)] })] }));
153
+ }
154
+ /** A caps label with the lavender marker, and "View more" at the other end. */
155
+ function SectionHead({ id, label, more, props }) {
156
+ return (_jsxs("div", { className: "ha-section-head", children: [_jsx("h2", { id: id, className: "ha-label", children: label }), more && _jsxs("a", { className: "ha-more", href: more, children: [props.t("halo.viewMore"), _jsx(Arrow, {})] })] }));
157
+ }
158
+ /** Title and meta at the start, a square thumbnail at the end. */
159
+ function Row({ story, props }) {
160
+ return (_jsxs("article", { className: "ha-row", lang: text(story.locale) || undefined, children: [_jsxs("div", { className: "ha-row-text", children: [_jsx(Meta, { story: story, props: props }), _jsx(Title, { story: story, props: props, className: "ha-row-title" })] }), _jsx(Picture, { story: story, props: props, size: "300x300", className: "ha-row-image" })] }));
161
+ }
162
+ function Rows({ stories, props }) {
163
+ return _jsx("ul", { className: "ha-rows", children: stories.map((story) => _jsx("li", { children: _jsx(Row, { story: story, props: props }) }, story.id)) });
164
+ }
165
+ /** Image, meta, title and tags. */
166
+ function Card({ story, props, eager = false }) {
167
+ return (_jsxs("article", { className: "ha-card", lang: text(story.locale) || undefined, children: [_jsx(Picture, { story: story, props: props, size: "800x0", className: "ha-card-image", eager: eager }), _jsx(Meta, { story: story, props: props }), _jsx(Title, { story: story, props: props, className: "ha-card-title" }), _jsx(Tags, { story: story, props: props })] }));
168
+ }
169
+ /** The cover with a lavender wash rising from the bottom, and the story over it in white. */
170
+ function Feature({ story, props, large = false }) {
171
+ return (_jsxs("article", { className: large ? "ha-feature ha-feature-large" : "ha-feature", lang: text(story.locale) || undefined, children: [_jsx(Picture, { story: story, props: props, size: "800x0", className: "ha-feature-image" }), _jsxs("div", { className: "ha-feature-body", children: [_jsx(Meta, { story: story, props: props }), _jsx(Title, { story: story, props: props, className: "ha-feature-title" }), large && _jsx(Tags, { story: story, props: props })] })] }));
172
+ }
173
+ /* ---------------------------------------------------------------- layout */
174
+ const GlobeIcon = () => (_jsx("svg", { "aria-hidden": "true", viewBox: "0 0 20 20", width: "16", height: "16", children: _jsx("path", { fill: "none", stroke: "currentColor", strokeWidth: "1.5", d: "M10 18a8 8 0 1 0 0-16 8 8 0 0 0 0 16Zm-8-8h16M10 2c2.2 2.2 3.2 5 3.2 8s-1 5.8-3.2 8c-2.2-2.2-3.2-5-3.2-8s1-5.8 3.2-8Z" }) }));
175
+ /**
176
+ * The same page in each language it's published in. In the header it's a menu showing the
177
+ * current language's code; in the small-screen drawer it's a plain list.
178
+ */
179
+ function LanguageSwitcher({ language, t, inline = false }) {
180
+ if (!language)
181
+ return null;
182
+ const available = language.locales.filter((locale) => language.alternates[locale.code]);
183
+ if (available.length < 2)
184
+ return null;
185
+ const list = (_jsx("ul", { className: "ha-languages-list", children: available.map((locale) => (_jsx("li", { children: _jsxs("a", { href: language.alternates[locale.code], hrefLang: locale.code, lang: locale.code, "aria-current": locale.code === language.locale ? "true" : undefined, children: [_jsx("span", { children: locale.label }), _jsx("span", { className: "ha-languages-code", children: locale.code })] }) }, locale.code))) }));
186
+ if (inline) {
187
+ return (_jsxs("nav", { className: "ha-languages ha-languages-inline", "aria-label": t("halo.language"), children: [_jsxs("p", { className: "ha-label", children: [_jsx(GlobeIcon, {}), t("halo.language")] }), list] }));
188
+ }
189
+ return (_jsx("nav", { className: "ha-languages", "aria-label": t("halo.language"), children: _jsxs("details", { className: "ha-languages-menu", children: [_jsxs("summary", { children: [_jsx("span", { className: "ha-languages-current", children: language.locale }), _jsx("span", { className: "ha-chevron", "aria-hidden": "true" })] }), _jsx("div", { className: "ha-languages-panel", children: list })] }) }));
190
+ }
191
+ function Brand({ branding, words }) {
192
+ return (_jsxs("a", { className: "ha-brand", href: link({ words }, "/"), children: [branding.logoUrl ? _jsx("img", { src: branding.logoUrl, alt: "", width: 20, height: 20 }) : _jsx("span", { className: "ha-brand-mark", "aria-hidden": "true" }), _jsx("span", { children: branding.name })] }));
193
+ }
194
+ function AccountLinks({ t }) {
195
+ return (_jsxs("div", { className: "ha-account", children: [_jsx("a", { className: "ha-chip", href: authPath("signin"), children: t("halo.signIn") }), _jsx("a", { className: "ha-chip ha-chip-ink", href: authPath("signup"), children: t("halo.register") })] }));
196
+ }
197
+ function Layout(props) {
198
+ const { branding, globals, options, children, language, t, words } = props;
199
+ const menu = globals["site-menu"]?.items;
200
+ const search = options.search ? _jsx(HeaderSearch, { words: words ? pickWords(words, "halo") : undefined, showDates: options.showDates }) : null;
201
+ return (_jsxs("div", { className: "ha-shell", "data-scheme": options.colorScheme, children: [_jsx("a", { className: "ha-skip", href: "#ha-content", children: t("halo.skip") }), _jsx("header", { className: "ha-header", children: _jsxs("div", { className: "ha-header-inner", children: [_jsx(Brand, { branding: branding, words: words }), _jsx("nav", { className: "ha-nav", "aria-label": t("halo.menu"), children: _jsx(Menu, { items: menu }) }), _jsxs("div", { className: "ha-header-end", children: [_jsx(LanguageSwitcher, { language: language, t: t }), search, options.accountLinks && _jsx(AccountLinks, { t: t })] }), _jsxs("details", { className: "ha-drawer", children: [_jsx("summary", { "aria-label": t("halo.openMenu"), children: _jsx("span", { "aria-hidden": "true" }) }), _jsxs("div", { className: "ha-drawer-panel", children: [search, _jsx("nav", { "aria-label": t("halo.menu"), children: _jsx(Menu, { items: menu }) }), _jsx(LanguageSwitcher, { language: language, t: t, inline: true }), options.accountLinks && _jsx(AccountLinks, { t: t })] })] })] }) }), _jsx("div", { id: "ha-content", className: "ha-content", children: children }), _jsx("footer", { className: "ha-footer", children: _jsxs("div", { className: "ha-footer-inner", children: [_jsxs("div", { children: [_jsx(Brand, { branding: branding, words: words }), options.tagline && _jsx("p", { className: "ha-footer-tagline", children: options.tagline })] }), _jsx("nav", { className: "ha-footer-nav", "aria-label": t("halo.footerMenu"), children: _jsx(Menu, { items: menu }) }), _jsxs("p", { className: "ha-footer-legal", children: ["\u00A9 ", new Date().getFullYear(), " ", branding.name, ". ", t("halo.rights")] })] }) })] }));
202
+ }
203
+ /* ------------------------------------------------------------- front page */
204
+ /**
205
+ * Hands out stories to the front page's sections, most important first. A section an editor
206
+ * filled shows their picks in their order. Otherwise it takes stories no earlier section
207
+ * showed, and, where `reuse` allows, tops up with ones that did, so a young site's page isn't
208
+ * mostly empty.
209
+ */
210
+ function allocator() {
211
+ const used = new Set();
212
+ return (picks, order, pools, count, reuse = false) => {
213
+ if (picks.length) {
214
+ const sorted = [...picks].sort((a, b) => order.indexOf(a.id) - order.indexOf(b.id)).slice(0, count);
215
+ for (const story of sorted)
216
+ used.add(story.id);
217
+ return sorted;
218
+ }
219
+ const chosen = [];
220
+ const seen = new Set();
221
+ const add = (story) => {
222
+ if (chosen.length >= count || seen.has(story.id))
223
+ return;
224
+ seen.add(story.id);
225
+ chosen.push(story);
226
+ };
227
+ for (const pool of pools)
228
+ for (const story of pool)
229
+ if (!used.has(story.id))
230
+ add(story);
231
+ if (reuse)
232
+ for (const pool of pools)
233
+ for (const story of pool)
234
+ add(story);
235
+ for (const story of chosen)
236
+ used.add(story.id);
237
+ return chosen;
238
+ };
239
+ }
240
+ function frontStories({ data, record }) {
241
+ const take = allocator();
242
+ const featured = items(data.featured);
243
+ const recent = items(data.recent);
244
+ const order = (field) => ids(record?.[field]);
245
+ // Allocated in this order so the newest stories reach "Latest" before the other lists take them.
246
+ const lead = take(items(data.pickLead), order("lead"), [featured, recent], 1)[0];
247
+ const spotlight = take(items(data.pickSpotlight), order("spotlight"), [featured, recent], 1)[0];
248
+ const latest = take([], [], [recent], 4);
249
+ const recommended = take(items(data.pickRecommended), order("recommended"), [recent], 5);
250
+ const strip = take([], [], [featured, recent], 3);
251
+ const trending = take(items(data.pickTrending), order("trending"), [recent], 7, true);
252
+ const readers = take(items(data.pickReaders), order("readersChoice"), [featured, recent], 9, true);
253
+ const popular = take(items(data.pickPopular), order("popular"), [recent], 10, true);
254
+ return { lead, spotlight, latest, recommended, strip, trending, readers, popular };
255
+ }
256
+ /** The halo itself: CSS only, so it costs no request and follows the accent. */
257
+ const Halo = ({ className = "ha-halo" }) => _jsx("span", { className: className, "aria-hidden": "true", children: _jsx("span", {}) });
258
+ function LeadSection({ lead, strip, recommended, props }) {
259
+ const { t } = props;
260
+ const [first, ...rest] = recommended;
261
+ return (_jsxs("section", { className: "ha-lead-wrap", "aria-labelledby": "ha-lead-label", children: [_jsxs("div", { className: "ha-lead", children: [_jsx(Halo, {}), _jsxs("div", { className: "ha-lead-main", children: [_jsx("p", { id: "ha-lead-label", className: "ha-label", children: t("halo.bestOfWeek") }), _jsx(Meta, { story: lead, props: props }), _jsx(Title, { story: lead, props: props, as: "h2", className: "ha-display" }), _jsx(Tags, { story: lead, props: props }), _jsx(ReadButton, { story: lead, props: props })] }), strip.length > 0 && (_jsx("ul", { className: "ha-strip", children: strip.map((story) => (_jsx("li", { children: _jsxs("article", { className: "ha-strip-item", children: [_jsx(Meta, { story: story, props: props }), _jsx(Title, { story: story, props: props, className: "ha-strip-title" })] }) }, story.id))) }))] }), first && (_jsxs("aside", { className: "ha-panel ha-recommended", "aria-labelledby": "ha-recommended", children: [_jsxs("div", { className: "ha-section-head ha-section-head-plain", children: [_jsx("h2", { id: "ha-recommended", className: "ha-panel-title", children: t("halo.recommended") }), blogHref(props) && _jsxs("a", { className: "ha-more", href: blogHref(props), children: [t("halo.viewAll"), _jsx(Arrow, {})] })] }), _jsx(Feature, { story: first, props: props }), rest.length > 0 && _jsx(Rows, { stories: rest, props: props })] }))] }));
262
+ }
263
+ function SpotlightSection({ spotlight, latest, props }) {
264
+ const { t } = props;
265
+ if (!spotlight && !latest.length)
266
+ return null;
267
+ return (_jsxs("section", { className: "ha-spotlight-wrap", children: [latest.length > 0 && (_jsxs("div", { className: "ha-panel ha-latest", "aria-labelledby": "ha-latest", children: [_jsx(SectionHead, { id: "ha-latest", label: t("halo.latest"), more: blogHref(props), props: props }), _jsx(Rows, { stories: latest, props: props })] })), spotlight && (_jsxs("article", { className: "ha-spotlight", lang: text(spotlight.locale) || undefined, children: [_jsxs("div", { className: "ha-spotlight-head", children: [_jsx(Meta, { story: spotlight, props: props }), _jsx(Title, { story: spotlight, props: props, as: "h2", className: "ha-headline" }), _jsx(Tags, { story: spotlight, props: props })] }), _jsxs("div", { className: "ha-spotlight-side", children: [text(spotlight.excerpt) && _jsx("p", { className: "ha-excerpt", children: text(spotlight.excerpt) }), _jsx(ReadButton, { story: spotlight, props: props })] }), _jsxs("a", { className: "ha-badge", href: "#ha-readers", children: [_jsx(Halo, { className: "ha-badge-halo" }), _jsx("span", { children: t("halo.readersChoiceBadge") }), _jsx("small", { children: t("halo.thisWeek") })] })] }))] }));
268
+ }
269
+ function TrendingSection({ stories, props }) {
270
+ const [first, ...grid] = stories;
271
+ if (!first)
272
+ return null;
273
+ const { t } = props;
274
+ return (_jsxs("section", { className: "ha-trending", "aria-labelledby": "ha-trending", children: [_jsxs("div", { className: "ha-trending-lead", children: [_jsx(SectionHead, { id: "ha-trending", label: t("halo.trending"), more: blogHref(props), props: props }), _jsxs("article", { className: "ha-trending-story", lang: text(first.locale) || undefined, children: [_jsx(Meta, { story: first, props: props }), _jsx(Title, { story: first, props: props, className: "ha-headline" }), _jsx(Tags, { story: first, props: props }), _jsx(ReadButton, { story: first, props: props })] }), _jsx(Picture, { story: first, props: props, size: "800x0", className: "ha-trending-image" })] }), grid.length > 0 && _jsx("ul", { className: "ha-grid", children: grid.map((story) => _jsx("li", { children: _jsx(Card, { story: story, props: props }) }, story.id)) })] }));
275
+ }
276
+ function ReadersSection({ stories, props }) {
277
+ const [first, ...rest] = stories;
278
+ if (!first)
279
+ return null;
280
+ return (_jsxs("section", { className: "ha-section", "aria-labelledby": "ha-readers", children: [_jsx(SectionHead, { id: "ha-readers", label: props.t("halo.readersChoice"), more: blogHref(props), props: props }), _jsxs("div", { className: "ha-readers", children: [_jsx(Feature, { story: first, props: props, large: true }), rest.length > 0 && _jsx(Rows, { stories: rest, props: props })] })] }));
281
+ }
282
+ function PopularSection({ stories, props }) {
283
+ if (!stories.length)
284
+ return null;
285
+ const { t } = props;
286
+ return (_jsxs("section", { className: "ha-section", "aria-labelledby": "ha-popular", children: [_jsx(SectionHead, { id: "ha-popular", label: t("halo.popular"), more: blogHref(props), props: props }), _jsx(Carousel, { previous: t("halo.previous"), next: t("halo.next"), label: t("halo.popular"), children: _jsx("ul", { className: "ha-carousel-list", children: stories.map((story) => _jsx("li", { children: _jsx(Card, { story: story, props: props }) }, story.id)) }) })] }));
287
+ }
288
+ /**
289
+ * The home page: at the site's root, from the Front page record when an editor made one, or
290
+ * from featured and recent posts when not.
291
+ */
292
+ function Front(props) {
293
+ const { record, branding, t } = props;
294
+ const { lead, spotlight, latest, recommended, strip, trending, readers, popular } = frontStories(props);
295
+ return (_jsxs("main", { className: "ha-page", children: [_jsx("h1", { className: "ha-visually-hidden", children: text(record?.title) || branding.name }), lead ? (_jsxs(_Fragment, { children: [_jsx(LeadSection, { lead: lead, strip: strip, recommended: recommended, props: props }), _jsx(SpotlightSection, { spotlight: spotlight, latest: latest, props: props }), _jsx(TrendingSection, { stories: trending, props: props }), _jsx(ReadersSection, { stories: readers, props: props }), _jsx(PopularSection, { stories: popular, props: props })] })) : _jsx("p", { className: "ha-panel ha-empty", children: t("halo.noStories") })] }));
296
+ }
297
+ /* --------------------------------------------------------------- archives */
298
+ /** Arrow buttons for a paged list. An end it can't go past shows a quiet, disabled circle. */
299
+ function PageArrows({ list, props }) {
300
+ if (!list || list.totalPages <= 1)
301
+ return null;
302
+ const { page, totalPages } = list;
303
+ const at = link(props, props.path);
304
+ const { t } = props;
305
+ return (_jsxs("nav", { className: "ha-page-arrows", "aria-label": t("halo.pages"), children: [page > 1 ? _jsx("a", { className: "ha-round", rel: "prev", href: pageHref(at, page - 1), "aria-label": t("halo.newer"), children: _jsx(Arrow, { back: true }) }) : _jsx("span", { className: "ha-round", "aria-hidden": "true", children: _jsx(Arrow, { back: true }) }), _jsx("span", { className: "ha-visually-hidden", "aria-current": "page", children: t("halo.pageOf", { page, total: totalPages }) }), page < totalPages ? _jsx("a", { className: "ha-round ha-round-ink", rel: "next", href: pageHref(at, page + 1), "aria-label": t("halo.older"), children: _jsx(Arrow, {}) }) : _jsx("span", { className: "ha-round ha-round-ink", "aria-hidden": "true", children: _jsx(Arrow, {}) })] }));
306
+ }
307
+ /**
308
+ * The blog's home, a category or a tag: the newest story of the page leads beside a grid of
309
+ * the next six, with arrows to older pages.
310
+ */
311
+ function Archive({ kicker, heading, intro, ...props }) {
312
+ const posts = items(props.data.posts);
313
+ const [first, ...grid] = posts;
314
+ return (_jsx("main", { className: "ha-page", children: _jsxs("section", { className: "ha-trending ha-archive", "aria-labelledby": "ha-archive", children: [_jsxs("div", { className: "ha-trending-lead", children: [_jsx("p", { className: "ha-label", children: kicker }), _jsx("h1", { id: "ha-archive", className: "ha-archive-title", children: heading }), intro, first ? (_jsxs("article", { className: "ha-trending-story", lang: text(first.locale) || undefined, children: [_jsx(Meta, { story: first, props: props }), _jsx(Title, { story: first, props: props, as: "h2", className: "ha-headline" }), _jsx(Tags, { story: first, props: props }), _jsx(ReadButton, { story: first, props: props })] })) : _jsx("p", { className: "ha-empty", children: props.t("halo.noStoriesHere") }), first && _jsx(Picture, { story: first, props: props, size: "800x0", className: "ha-trending-image", eager: true })] }), grid.length > 0 && (_jsxs("div", { className: "ha-archive-grid", children: [_jsx("ul", { className: "ha-grid", children: grid.map((story, index) => _jsx("li", { children: _jsx(Card, { story: story, props: props, eager: index < 3 }) }, story.id)) }), _jsx(PageArrows, { list: props.data.posts, props: props })] })), !grid.length && _jsx(PageArrows, { list: props.data.posts, props: props })] }) }));
315
+ }
316
+ function BlogHome(props) {
317
+ const { record, stream, t } = props;
318
+ const intro = Array.isArray(record?.intro) && record.intro.length > 0 ? _jsx("div", { className: "ha-archive-intro", children: _jsx(StreamField, { blocks: record.intro, ...stream }) }) : undefined;
319
+ return _jsx(Archive, { ...props, kicker: t("halo.latest"), heading: text(record?.title) || t("halo.latest"), intro: intro });
320
+ }
321
+ function Taxonomy({ kind, ...props }) {
322
+ const { record, t } = props;
323
+ if (!record)
324
+ return null;
325
+ const intro = text(record.description) ? _jsx("p", { className: "ha-archive-intro", children: text(record.description) }) : undefined;
326
+ return _jsx(Archive, { ...props, kicker: t(kind === "category" ? "blog.category" : "blog.tag"), heading: kind === "tag" ? `#${text(record.name)}` : text(record.name), intro: intro });
327
+ }
328
+ const Category = (props) => _jsx(Taxonomy, { ...props, kind: "category" });
329
+ const Tag = (props) => _jsx(Taxonomy, { ...props, kind: "tag" });
330
+ /* ------------------------------------------------------------------ posts */
331
+ /**
332
+ * A post. Byline, tags and comments are the blog plugin's parts, fed the plugin's lists
333
+ * through `data`, so they behave exactly as on its own page.
334
+ */
335
+ function Post(props) {
336
+ const { record, data, stream, fileUrl, fileText, fileFocus, t, words } = props;
337
+ if (!record)
338
+ return null;
339
+ const side = items(data.sideStories);
340
+ const more = (items(data.moreStories).length ? items(data.moreStories) : side).slice(0, 4);
341
+ const cover = text(record.cover);
342
+ return (_jsxs("main", { className: "ha-page", children: [_jsxs("div", { className: "ha-post", children: [_jsxs("article", { className: "ha-panel ha-article", children: [_jsxs("header", { className: "ha-article-head", children: [_jsx(Meta, { story: record, props: props }), _jsx("h1", { className: "ha-headline ha-article-title", children: text(record.title) }), text(record.excerpt) && _jsx("p", { className: "ha-lead-text", children: text(record.excerpt) }), props.options.showDates && _jsx(PostMeta, { post: record, data: data, words: words })] }), cover && _jsx("figure", { className: "ha-article-cover", children: _jsx("img", { src: fileUrl(cover, "800x0"), alt: fileText(cover).alt, style: { objectPosition: fileFocus(cover).objectPosition } }) }), _jsxs("div", { className: "ha-prose", children: [_jsx(StreamField, { blocks: record.body, ...stream }), _jsx(PostTags, { post: record, data: data, words: words })] }), _jsx("div", { className: "ha-comments", children: _jsx(PostComments, { post: record, data: data, words: words }) })] }), side.length > 0 && (_jsxs("aside", { className: "ha-panel ha-recommended ha-post-aside", "aria-labelledby": "ha-side", children: [_jsxs("div", { className: "ha-section-head ha-section-head-plain", children: [_jsx("h2", { id: "ha-side", className: "ha-panel-title", children: t("halo.recommended") }), blogHref(props) && _jsxs("a", { className: "ha-more", href: blogHref(props), children: [t("halo.viewAll"), _jsx(Arrow, {})] })] }), _jsx(Rows, { stories: side, props: props })] }))] }), more.length > 0 && (_jsxs("section", { className: "ha-section", "aria-labelledby": "ha-more-like", children: [_jsx(SectionHead, { id: "ha-more-like", label: t("halo.moreLikeThis"), props: props }), _jsx("ul", { className: "ha-grid ha-grid-four", children: more.map((story) => _jsx("li", { children: _jsx(Card, { story: story, props: props }) }, story.id)) })] }))] }));
343
+ }
344
+ /** Any other page, such as About. */
345
+ function Page({ record, stream }) {
346
+ if (!record)
347
+ return null;
348
+ return (_jsx("main", { className: "ha-page", children: _jsxs("article", { className: "ha-panel ha-article ha-article-solo", children: [_jsx("header", { className: "ha-article-head", children: _jsx("h1", { className: "ha-headline ha-article-title", children: text(record.title) }) }), _jsx("div", { className: "ha-prose", children: _jsx(StreamField, { blocks: record.body, ...stream }) })] }) }));
349
+ }
350
+ /**
351
+ * Categories and tags have a name rather than a title, and posts an excerpt rather than a summary.
352
+ * Only fills what the CMS's defaults (seo_title, title, seo_description, summary) would leave empty.
353
+ */
354
+ function metadata({ record, branding }) {
355
+ if (!record)
356
+ return {};
357
+ return {
358
+ title: !text(record.seo_title) && !text(record.title) ? text(record.name) || (record.lead !== undefined ? branding.name : undefined) : undefined,
359
+ description: !text(record.seo_description) && !text(record.summary) ? text(record.excerpt) || text(record.description) || undefined : undefined,
360
+ };
361
+ }
362
+ export default defineThemeComponents({
363
+ // Blocks come from the blog plugin and are restyled in theme.css.
364
+ templates: { home: Front, "halo-front": Front, "blog-home": BlogHome, "blog-posts": Post, "blog-categories": Category, "blog-tags": Tag, default: Page },
365
+ layouts: { default: Layout },
366
+ metadata,
367
+ fontClassName: font.variable,
368
+ messages,
369
+ });
package/schema.json ADDED
@@ -0,0 +1,110 @@
1
+ {
2
+ "version": 1,
3
+ "collections": [
4
+ {
5
+ "slug": "site-menu",
6
+ "name": "Menu",
7
+ "description": "Links shown at the top of every page.",
8
+ "type": "singleton",
9
+ "urlPattern": null,
10
+ "rules": {
11
+ "listRule": "",
12
+ "viewRule": "",
13
+ "createRule": null,
14
+ "updateRule": null,
15
+ "deleteRule": null
16
+ },
17
+ "fields": [
18
+ {
19
+ "name": "items",
20
+ "type": "stream",
21
+ "config": {
22
+ "allowedBlocks": [
23
+ "menu_item"
24
+ ]
25
+ }
26
+ }
27
+ ]
28
+ },
29
+ {
30
+ "slug": "halo-front",
31
+ "name": "Front page",
32
+ "description": "The stories the home page leads with. Any section left empty is filled with featured and recent posts.",
33
+ "type": "singleton",
34
+ "urlPattern": "/",
35
+ "rules": {
36
+ "listRule": "",
37
+ "viewRule": "",
38
+ "createRule": null,
39
+ "updateRule": null,
40
+ "deleteRule": null
41
+ },
42
+ "fields": [
43
+ {
44
+ "name": "title",
45
+ "type": "text",
46
+ "config": {
47
+ "maxLength": 120
48
+ }
49
+ },
50
+ {
51
+ "name": "lead",
52
+ "type": "reference",
53
+ "config": {
54
+ "collection": "blog-posts",
55
+ "displayField": "title"
56
+ }
57
+ },
58
+ {
59
+ "name": "recommended",
60
+ "type": "reference",
61
+ "config": {
62
+ "collection": "blog-posts",
63
+ "displayField": "title",
64
+ "allowMultiple": true,
65
+ "maxSelect": 5
66
+ }
67
+ },
68
+ {
69
+ "name": "spotlight",
70
+ "type": "reference",
71
+ "config": {
72
+ "collection": "blog-posts",
73
+ "displayField": "title"
74
+ }
75
+ },
76
+ {
77
+ "name": "trending",
78
+ "type": "reference",
79
+ "config": {
80
+ "collection": "blog-posts",
81
+ "displayField": "title",
82
+ "allowMultiple": true,
83
+ "maxSelect": 7
84
+ }
85
+ },
86
+ {
87
+ "name": "readersChoice",
88
+ "type": "reference",
89
+ "config": {
90
+ "collection": "blog-posts",
91
+ "displayField": "title",
92
+ "allowMultiple": true,
93
+ "maxSelect": 9
94
+ }
95
+ },
96
+ {
97
+ "name": "popular",
98
+ "type": "reference",
99
+ "config": {
100
+ "collection": "blog-posts",
101
+ "displayField": "title",
102
+ "allowMultiple": true,
103
+ "maxSelect": 10
104
+ }
105
+ }
106
+ ]
107
+ }
108
+ ],
109
+ "blocks": []
110
+ }