@tansy/blog 0.0.0-stage → 0.1.2

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/messages.js ADDED
@@ -0,0 +1,264 @@
1
+ /** The blog's dashboard words, read as `t("ext.blog.<key>")`, and its collections' names. */
2
+ export const messages = {
3
+ en: {
4
+ section: "Blog",
5
+ pages: { "blog/comments": "Comments to review" },
6
+ collections: { "blog-comments": "All comments", "blog-home": "Blog home page" },
7
+ widgets: { "blog-overview": "Blog" },
8
+ actions: { "blog-approve": "Approve", "blog-spam": "Mark as spam" },
9
+ categories: { Text: "Text", Media: "Media" },
10
+ settings: {
11
+ comments: { label: "Comments", options: { moderated: "Held for review", open: "Shown straight away", off: "Off" } },
12
+ notify: { label: "Email for comments to review", description: "Who to tell when a comment is waiting. Leave empty for nobody." },
13
+ feedItems: { label: "Posts in feeds", description: "How many of the latest posts the RSS and Atom feeds list." },
14
+ },
15
+ queue: {
16
+ intro: "Comments waiting for review, oldest first. Approving or marking as spam needs permission to update records in Comments.",
17
+ cantRead: "You can't read Comments. Ask an administrator for permission to list them.",
18
+ empty: "Nothing is waiting for review.",
19
+ on: "{name} on {post}",
20
+ aPost: "a post",
21
+ showing: "Showing the oldest {shown} of {total}.",
22
+ },
23
+ overview: {
24
+ pending: "{count, plural, one {# comment waiting for review} other {# comments waiting for review}}",
25
+ drafts: "{count, plural, one {# draft post} other {# draft posts}}",
26
+ published: "{count, plural, one {# published post} other {# published posts}}",
27
+ unknown: "— {label}",
28
+ pendingLabel: "comments waiting for review",
29
+ draftsLabel: "draft posts",
30
+ publishedLabel: "published posts",
31
+ },
32
+ moderate: {
33
+ approve: "Approve",
34
+ spam: "Spam",
35
+ approved: "Approved",
36
+ markedSpam: "Marked as spam",
37
+ failed: "{count, plural, one {One comment couldn't be changed.} other {# comments couldn't be changed.}} Changing comments needs permission to update records in Comments.",
38
+ },
39
+ editors: {
40
+ startWriting: "Start writing…",
41
+ quote: "Write a quote…",
42
+ source: "Who said it",
43
+ note: "Write a note…",
44
+ image: "Image",
45
+ caption: "Add a caption",
46
+ alt: "Alt text: what the image shows, for people who can't see it",
47
+ video: "Video",
48
+ pasteVideo: "Paste a YouTube or Vimeo link.",
49
+ code: "Paste or write code",
50
+ language: "Language, such as ts",
51
+ },
52
+ },
53
+ ar: {
54
+ section: "المدونة",
55
+ pages: { "blog/comments": "تعليقات بانتظار المراجعة" },
56
+ collections: { "blog-comments": "كل التعليقات", "blog-home": "الصفحة الرئيسية للمدونة" },
57
+ widgets: { "blog-overview": "المدونة" },
58
+ actions: { "blog-approve": "موافقة", "blog-spam": "وسم كرسالة مزعجة" },
59
+ categories: { Text: "نص", Media: "وسائط" },
60
+ settings: {
61
+ comments: { label: "التعليقات", options: { moderated: "تُحجز للمراجعة", open: "تظهر فورًا", off: "معطّلة" } },
62
+ notify: { label: "بريد التعليقات التي تنتظر المراجعة", description: "من يُبلَّغ حين ينتظر تعليق المراجعة. اتركه فارغًا لعدم إبلاغ أحد." },
63
+ feedItems: { label: "عدد المقالات في الخلاصات", description: "كم مقالًا من الأحدث تعرضه خلاصتا RSS وAtom." },
64
+ },
65
+ queue: {
66
+ intro: "تعليقات تنتظر المراجعة، الأقدم أولًا. تتطلب الموافقة أو الوسم كرسالة مزعجة صلاحية تحديث السجلات في التعليقات.",
67
+ cantRead: "لا يمكنك قراءة التعليقات. اطلب من المسؤول صلاحية عرضها.",
68
+ empty: "لا شيء ينتظر المراجعة.",
69
+ on: "{name} على {post}",
70
+ aPost: "مقال",
71
+ showing: "يُعرض أقدم {shown} من {total}.",
72
+ },
73
+ overview: {
74
+ pending: "{count, plural, zero {لا تعليقات تنتظر المراجعة} one {تعليق واحد ينتظر المراجعة} two {تعليقان ينتظران المراجعة} few {# تعليقات تنتظر المراجعة} many {# تعليقًا ينتظر المراجعة} other {# تعليق ينتظر المراجعة}}",
75
+ drafts: "{count, plural, zero {لا مسودات} one {مسودة واحدة} two {مسودتان} few {# مسودات} many {# مسودة} other {# مسودة}}",
76
+ published: "{count, plural, zero {لا مقالات منشورة} one {مقال منشور واحد} two {مقالان منشوران} few {# مقالات منشورة} many {# مقالًا منشورًا} other {# مقال منشور}}",
77
+ unknown: "— {label}",
78
+ pendingLabel: "تعليقات تنتظر المراجعة",
79
+ draftsLabel: "مسودات",
80
+ publishedLabel: "مقالات منشورة",
81
+ },
82
+ moderate: {
83
+ approve: "موافقة",
84
+ spam: "مزعج",
85
+ approved: "تمت الموافقة",
86
+ markedSpam: "وُسم كرسالة مزعجة",
87
+ failed: "{count, plural, one {تعذّر تغيير تعليق واحد.} two {تعذّر تغيير تعليقين.} few {تعذّر تغيير # تعليقات.} many {تعذّر تغيير # تعليقًا.} other {تعذّر تغيير # تعليق.}} يتطلب تغيير التعليقات صلاحية تحديث السجلات في التعليقات.",
88
+ },
89
+ editors: {
90
+ startWriting: "ابدأ الكتابة…",
91
+ quote: "اكتب اقتباسًا…",
92
+ source: "قائله",
93
+ note: "اكتب ملاحظة…",
94
+ image: "صورة",
95
+ caption: "أضف تعليقًا توضيحيًا",
96
+ alt: "النص البديل: ما تُظهره الصورة، لمن لا يستطيع رؤيتها",
97
+ video: "فيديو",
98
+ pasteVideo: "الصق رابطًا من YouTube أو Vimeo.",
99
+ code: "الصق رمزًا برمجيًا أو اكتبه",
100
+ language: "اللغة، مثل ts",
101
+ },
102
+ },
103
+ };
104
+ /** The collections' names in other interface languages. Added by a migration, so names an owner set stay. */
105
+ export const COLLECTION_LABELS = {
106
+ "blog-categories": { ar: "التصنيفات" },
107
+ "blog-tags": { ar: "الوسوم" },
108
+ "blog-posts": { ar: "المقالات" },
109
+ "blog-comments": { ar: "التعليقات" },
110
+ "blog-home": { ar: "رئيسية المدونة" },
111
+ };
112
+ /** Fields' words in other interface languages, by collection. Added by a migration, so words an owner set stay. */
113
+ export const FIELD_LABELS = {
114
+ "blog-categories": {
115
+ slug: {
116
+ labels: {
117
+ ar: "الاسم اللطيف"
118
+ },
119
+ descriptions: {
120
+ ar: "يظهر في العنوان. أحرف لاتينية صغيرة وأرقام وشرطات. يُملأ من العنوان إن تُرك فارغًا."
121
+ }
122
+ },
123
+ name: {
124
+ labels: {
125
+ ar: "الاسم"
126
+ }
127
+ },
128
+ description: {
129
+ labels: {
130
+ ar: "الوصف"
131
+ }
132
+ },
133
+ parent: {
134
+ labels: {
135
+ ar: "التصنيف الأب"
136
+ }
137
+ }
138
+ },
139
+ "blog-tags": {
140
+ slug: {
141
+ labels: {
142
+ ar: "الاسم اللطيف"
143
+ },
144
+ descriptions: {
145
+ ar: "يظهر في العنوان. أحرف لاتينية صغيرة وأرقام وشرطات. يُملأ من العنوان إن تُرك فارغًا."
146
+ }
147
+ },
148
+ name: {
149
+ labels: {
150
+ ar: "الاسم"
151
+ }
152
+ }
153
+ },
154
+ "blog-posts": {
155
+ title: {
156
+ labels: {
157
+ ar: "العنوان"
158
+ }
159
+ },
160
+ slug: {
161
+ labels: {
162
+ ar: "الاسم اللطيف"
163
+ },
164
+ descriptions: {
165
+ ar: "يظهر في العنوان. أحرف لاتينية صغيرة وأرقام وشرطات. يُملأ من العنوان إن تُرك فارغًا."
166
+ }
167
+ },
168
+ excerpt: {
169
+ labels: {
170
+ ar: "المقتطف"
171
+ }
172
+ },
173
+ cover: {
174
+ labels: {
175
+ ar: "صورة الغلاف"
176
+ }
177
+ },
178
+ body: {
179
+ labels: {
180
+ ar: "المحتوى"
181
+ }
182
+ },
183
+ byline: {
184
+ labels: {
185
+ ar: "الكاتب"
186
+ }
187
+ },
188
+ categories: {
189
+ labels: {
190
+ ar: "التصنيفات"
191
+ }
192
+ },
193
+ tags: {
194
+ labels: {
195
+ ar: "الوسوم"
196
+ }
197
+ },
198
+ featured: {
199
+ labels: {
200
+ ar: "مميّزة"
201
+ }
202
+ },
203
+ allowComments: {
204
+ labels: {
205
+ ar: "السماح بالتعليقات"
206
+ }
207
+ },
208
+ readingMinutes: {
209
+ labels: {
210
+ ar: "مدة القراءة (دقائق)"
211
+ }
212
+ }
213
+ },
214
+ "blog-comments": {
215
+ post: {
216
+ labels: {
217
+ ar: "المقالة"
218
+ }
219
+ },
220
+ parent: {
221
+ labels: {
222
+ ar: "ردًا على"
223
+ }
224
+ },
225
+ name: {
226
+ labels: {
227
+ ar: "الاسم"
228
+ }
229
+ },
230
+ body: {
231
+ labels: {
232
+ ar: "التعليق"
233
+ }
234
+ },
235
+ state: {
236
+ labels: {
237
+ ar: "الحالة"
238
+ },
239
+ options: {
240
+ pending: {
241
+ ar: "بانتظار المراجعة"
242
+ },
243
+ approved: {
244
+ ar: "مقبول"
245
+ },
246
+ spam: {
247
+ ar: "مزعج"
248
+ }
249
+ }
250
+ }
251
+ },
252
+ "blog-home": {
253
+ title: {
254
+ labels: {
255
+ ar: "العنوان"
256
+ }
257
+ },
258
+ intro: {
259
+ labels: {
260
+ ar: "المقدمة"
261
+ }
262
+ }
263
+ }
264
+ };
package/moderate.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ type T = (key: string, values?: Record<string, string | number>) => string;
2
+ export type CommentState = "approved" | "spam" | "pending";
3
+ /** Sets each comment's state through the records API, which checks the caller's own permission on Comments. */
4
+ export declare function setCommentState(ids: number[], state: CommentState, t: T): Promise<void>;
5
+ export declare function ModerateButtons({ id }: {
6
+ id: number;
7
+ }): import("react").JSX.Element;
8
+ export {};
package/moderate.js ADDED
@@ -0,0 +1,36 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useState } from "react";
4
+ import { apiPath, Button, useT } from "tansy/admin";
5
+ /** Sets each comment's state through the records API, which checks the caller's own permission on Comments. */
6
+ export async function setCommentState(ids, state, t) {
7
+ const failed = [];
8
+ for (const id of ids) {
9
+ const response = await fetch(apiPath(`/collections/blog-comments/records/${id}`), {
10
+ method: "PATCH",
11
+ headers: { "content-type": "application/json" },
12
+ body: JSON.stringify({ state }),
13
+ });
14
+ if (!response.ok)
15
+ failed.push(id);
16
+ }
17
+ if (failed.length)
18
+ window.alert(t("ext.blog.moderate.failed", { count: failed.length }));
19
+ }
20
+ export function ModerateButtons({ id }) {
21
+ const { t } = useT();
22
+ const [done, setDone] = useState(null);
23
+ const [busy, setBusy] = useState(false);
24
+ if (done)
25
+ return _jsx("span", { className: "cms-faded", children: done === "approved" ? t("ext.blog.moderate.approved") : t("ext.blog.moderate.markedSpam") });
26
+ const set = async (state) => {
27
+ setBusy(true);
28
+ await setCommentState([id], state, t);
29
+ // Shown as done only if it stuck: the page reloads its list on the next visit either way.
30
+ const check = await fetch(apiPath(`/collections/blog-comments/records/${id}?fields=state`)).then((r) => (r.ok ? r.json() : null)).catch(() => null);
31
+ setBusy(false);
32
+ if (check?.state === state)
33
+ setDone(state);
34
+ };
35
+ return (_jsxs("span", { className: "cms-flex cms-gap-2", children: [_jsx(Button, { variant: "primary", loading: busy, onClick: () => set("approved"), children: t("ext.blog.moderate.approve") }), _jsx(Button, { variant: "secondary", disabled: busy, onClick: () => set("spam"), children: t("ext.blog.moderate.spam") })] }));
36
+ }
package/package.json CHANGED
@@ -1,6 +1,46 @@
1
1
  {
2
2
  "name": "@tansy/blog",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.2",
4
+ "description": "Turns tansy into a blog: posts, categories, tags, authors, comments and feeds.",
5
+ "keywords": [
6
+ "tansy",
7
+ "tansy-plugin",
8
+ "cms",
9
+ "nextjs"
10
+ ],
11
+ "license": "MIT",
12
+ "author": "Mohamed Salah <mohamedsalahsebai@gmail.com>",
13
+ "homepage": "https://github.com/mhmdsalahsebai/tansy",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/mhmdsalahsebai/tansy.git",
17
+ "directory": "plugins/blog"
18
+ },
19
+ "bugs": "https://github.com/mhmdsalahsebai/tansy/issues",
20
+ "exports": {
21
+ ".": {
22
+ "types": "./index.d.ts",
23
+ "default": "./index.js"
24
+ },
25
+ "./admin": {
26
+ "types": "./admin.d.ts",
27
+ "default": "./admin.js"
28
+ },
29
+ "./client": {
30
+ "types": "./client.d.ts",
31
+ "default": "./client.js"
32
+ },
33
+ "./render": {
34
+ "types": "./render.d.ts",
35
+ "default": "./render.js"
36
+ }
37
+ },
38
+ "peerDependencies": {
39
+ "next": "^16.4.6",
40
+ "react": "^19.3.0",
41
+ "tansy": "^0.1.1"
42
+ },
43
+ "dependencies": {
44
+ "zod": "^4.6.7"
45
+ }
46
+ }
package/render.d.ts ADDED
@@ -0,0 +1,61 @@
1
+ import { type SiteWords } from "tansy/react";
2
+ import type { SiteRecord, TemplateProps } from "tansy/theme";
3
+ import { type CommentsHeadings } from "./comments";
4
+ import { type HeadingLevel } from "./text";
5
+ import "./blog.css";
6
+ /**
7
+ * The parts of the blog's pages, for a theme that designs its own. Give them the template's
8
+ * `record`, `data` and `words`: a theme's template for a blog collection gets the same lists as the
9
+ * plugin's own, so each part finds what it needs there.
10
+ *
11
+ * import { PostMeta, MorePosts, PostComments } from "@tansy/blog/render";
12
+ *
13
+ * Parts carry no outer margin or border; the template places them. The plugin's own pages do
14
+ * that inside `.bl-main`, so a theme that embeds a part gets only its inner spacing and styles
15
+ * it with the part's `bl-` classes, each a single class it can override with one of its own.
16
+ * Parts that title themselves take `heading` and `headingLevel`, so the theme sets the outline.
17
+ */
18
+ type PartProps = {
19
+ post: SiteRecord;
20
+ data: TemplateProps["data"];
21
+ words?: SiteWords;
22
+ };
23
+ /** Byline, date and reading time. */
24
+ export declare function PostMeta({ post, words }: PartProps): import("react").JSX.Element;
25
+ /**
26
+ * Posts as a list of titles, meta and excerpts, with featured posts marked.
27
+ * `headingLevel` (2 to 6, default 2) is the level of each post's title.
28
+ */
29
+ export declare function PostList({ posts, data, empty, words, headingLevel }: {
30
+ posts: SiteRecord[];
31
+ data: TemplateProps["data"];
32
+ empty: string;
33
+ words?: SiteWords;
34
+ headingLevel?: HeadingLevel;
35
+ }): import("react").JSX.Element;
36
+ /** The post's categories, as links. */
37
+ export declare function PostCategories({ post, data, words }: PartProps): import("react").JSX.Element | null;
38
+ /** The post's tags, as links. */
39
+ export declare function PostTags({ post, data, words }: PartProps): import("react").JSX.Element | null;
40
+ /** How a part that titles itself is titled. */
41
+ type Headed = {
42
+ /** A string replaces the default heading; `false` shows none, and the section keeps the default as its `aria-label`. */
43
+ heading?: string | false;
44
+ /** The heading's level, 2 to 6, default 2. */
45
+ headingLevel?: HeadingLevel;
46
+ };
47
+ /**
48
+ * Up to three posts sharing a tag with this one, or the latest when none do, under "More posts"
49
+ * or `heading`. Given a `headingLevel`, the post titles are one level below it; without one they
50
+ * are h2, as they have always been.
51
+ */
52
+ export declare function MorePosts({ post, data, words, heading, headingLevel }: PartProps & Headed): import("react").JSX.Element | null;
53
+ /**
54
+ * Approved comments and the form, unless the post has comments turned off. Shows replies one level deep.
55
+ * `heading` replaces "Comments" or, as `false`, hides it while the section keeps "Comments" as its
56
+ * `aria-label`; `formHeading` does the same for "Leave a comment"; `headingLevel` (2 to 6, default 2)
57
+ * sets the section heading's level, with the form heading one below.
58
+ */
59
+ export declare function PostComments({ post, data, words, heading, formHeading, headingLevel }: PartProps & CommentsHeadings): import("react").JSX.Element | null;
60
+ declare const _default: import("tansy/react").Renderers;
61
+ export default _default;
package/render.js ADDED
@@ -0,0 +1,140 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useId } from "react";
3
+ import { apiPath, defineRenderers, pickWords, Pager, sitePath, RichText, StreamField } from "tansy/react";
4
+ import { Comments } from "./comments";
5
+ import { blogWords, siteMessages } from "./site-messages";
6
+ import { Heading } from "./heading";
7
+ import { embedUrl } from "./text";
8
+ import "./blog.css";
9
+ const text = (value) => (typeof value === "string" ? value : "");
10
+ const ids = (value) => (Array.isArray(value) ? value.filter((id) => typeof id === "number") : typeof value === "number" ? [value] : []);
11
+ const items = (list) => list?.items ?? [];
12
+ const fileHref = (id, thumb) => apiPath(`/files/${encodeURIComponent(id)}${thumb ? `?thumb=${thumb}` : ""}`);
13
+ /** Records of a lookup list, by id, so links follow each collection's URL pattern. */
14
+ const byId = (list) => new Map(items(list).map((record) => [record.id, record]));
15
+ /** A link to a record in the page's language. */
16
+ function Linked({ record, label, words }) {
17
+ if (!record)
18
+ return null;
19
+ const href = text(record.recordPath) && sitePath(words, text(record.recordPath));
20
+ return href ? _jsx("a", { href: href, children: text(label) }) : _jsx("span", { children: text(label) });
21
+ }
22
+ /** Byline, date and reading time. */
23
+ export function PostMeta({ post, words }) {
24
+ const { t, formatDate } = blogWords(words);
25
+ const date = text(post.publishedAt);
26
+ const minutes = typeof post.readingMinutes === "number" ? post.readingMinutes : null;
27
+ const byline = text(post.byline);
28
+ return (_jsxs("p", { className: "bl-meta", children: [byline && _jsxs(_Fragment, { children: [_jsx("span", { className: "bl-byline", children: byline }), _jsx("span", { "aria-hidden": true, children: " \u00B7 " })] }), date && _jsx("time", { dateTime: date, children: formatDate(date, "long") }), minutes !== null && _jsxs(_Fragment, { children: [_jsx("span", { "aria-hidden": true, children: " \u00B7 " }), t("blog.minutes", { count: minutes })] })] }));
29
+ }
30
+ /**
31
+ * Posts as a list of titles, meta and excerpts, with featured posts marked.
32
+ * `headingLevel` (2 to 6, default 2) is the level of each post's title.
33
+ */
34
+ export function PostList({ posts, data, empty, words, headingLevel = 2 }) {
35
+ if (!posts.length)
36
+ return _jsx("p", { className: "bl-muted", children: empty });
37
+ return (_jsx("ul", { className: "bl-list", children: posts.map((post) => (_jsxs("li", { className: post.featured === true ? "bl-item bl-featured" : "bl-item", children: [_jsx(Heading, { level: headingLevel, className: "bl-item-title", children: _jsx(Linked, { record: post, label: post.title, words: words }) }), _jsx(PostMeta, { post: post, data: data, words: words }), text(post.excerpt) && _jsx("p", { children: text(post.excerpt) })] }, post.id))) }));
38
+ }
39
+ /** The post's categories, as links. */
40
+ export function PostCategories({ post, data, words }) {
41
+ const categories = byId(data.categories);
42
+ if (!ids(post.categories).length)
43
+ return null;
44
+ return _jsx("p", { className: "bl-kicker", children: ids(post.categories).map((id) => _jsx(Linked, { record: categories.get(id), label: categories.get(id)?.name, words: words }, id)) });
45
+ }
46
+ /** The post's tags, as links. */
47
+ export function PostTags({ post, data, words }) {
48
+ const tags = byId(data.tags);
49
+ if (!ids(post.tags).length)
50
+ return null;
51
+ return _jsx("ul", { className: "bl-tags", "aria-label": blogWords(words).t("blog.tags"), children: ids(post.tags).map((id) => _jsx("li", { children: _jsx(Linked, { record: tags.get(id), label: tags.get(id)?.name, words: words }) }, id)) });
52
+ }
53
+ /**
54
+ * Up to three posts sharing a tag with this one, or the latest when none do, under "More posts"
55
+ * or `heading`. Given a `headingLevel`, the post titles are one level below it; without one they
56
+ * are h2, as they have always been.
57
+ */
58
+ export function MorePosts({ post, data, words, heading, headingLevel }) {
59
+ const titleId = useId();
60
+ const related = items(data.related);
61
+ const more = (related.length ? related : items(data.recent)).filter((other) => other.id !== post.id).slice(0, 3);
62
+ if (!more.length)
63
+ return null;
64
+ const fallback = blogWords(words).t("blog.morePosts");
65
+ const title = heading ?? fallback;
66
+ return (_jsxs("section", { className: "bl-more", ...(title === false ? { "aria-label": fallback } : { "aria-labelledby": titleId }), children: [title !== false && _jsx(Heading, { level: headingLevel, id: titleId, className: "bl-more-title", children: title }), _jsx(PostList, { posts: more, data: data, empty: "", words: words, headingLevel: headingLevel ? Math.min(6, headingLevel + 1) : 2 })] }));
67
+ }
68
+ /**
69
+ * Approved comments and the form, unless the post has comments turned off. Shows replies one level deep.
70
+ * `heading` replaces "Comments" or, as `false`, hides it while the section keeps "Comments" as its
71
+ * `aria-label`; `formHeading` does the same for "Leave a comment"; `headingLevel` (2 to 6, default 2)
72
+ * sets the section heading's level, with the form heading one below.
73
+ */
74
+ export function PostComments({ post, data, words, heading, formHeading, headingLevel }) {
75
+ if (post.allowComments === false)
76
+ return null;
77
+ return _jsx(Comments, { postId: post.id, initial: items(data.comments), words: words ? pickWords(words, "blog") : undefined, heading: heading, formHeading: formHeading, headingLevel: headingLevel });
78
+ }
79
+ function Home({ record, data, stream, path, words, t }) {
80
+ const posts = items(data.posts);
81
+ // Featured posts go first, keeping the newest-first order within each group.
82
+ const ordered = [...posts.filter((post) => post.featured === true), ...posts.filter((post) => post.featured !== true)];
83
+ return (_jsxs("main", { className: "bl-main", children: [_jsx("h1", { children: text(record?.title) || t("blog.home") }), Array.isArray(record?.intro) && (data.posts?.page ?? 1) === 1 && _jsx("div", { className: "bl-body", children: _jsx(StreamField, { blocks: record.intro, ...stream }) }), _jsx(PostList, { posts: ordered, data: data, empty: t("blog.noPosts"), words: words }), _jsx(Pager, { list: data.posts, path: path, previous: t("blog.newerPosts"), next: t("blog.olderPosts"), className: "bl-pager", words: words })] }));
84
+ }
85
+ function Post({ record, data, stream, fileUrl, fileText, words }) {
86
+ if (!record)
87
+ return null;
88
+ return (_jsxs("main", { className: "bl-main", children: [_jsxs("article", { children: [_jsx(PostCategories, { post: record, data: data, words: words }), _jsx("h1", { children: text(record.title) }), _jsx(PostMeta, { post: record, data: data, words: words }), text(record.cover) && _jsx("img", { className: "bl-cover", src: fileUrl(text(record.cover), "800x0"), alt: fileText(text(record.cover)).alt }), _jsx("div", { className: "bl-body", children: _jsx(StreamField, { blocks: record.body, ...stream }) }), _jsx(PostTags, { post: record, data: data, words: words })] }), _jsx(MorePosts, { post: record, data: data, words: words }), _jsx(PostComments, { post: record, data: data, words: words })] }));
89
+ }
90
+ function Archive({ record, data, path, heading, words, t }) {
91
+ if (!record)
92
+ return null;
93
+ return (_jsxs("main", { className: "bl-main", children: [_jsx("p", { className: "bl-kicker", children: heading }), _jsx("h1", { children: text(record.name) }), text(record.description) && _jsx("p", { children: text(record.description) }), record.bio !== undefined && record.bio !== null && _jsx("div", { className: "bl-body", children: _jsx(RichText, { doc: record.bio }) }), _jsx(PostList, { posts: items(data.posts), data: data, empty: t("blog.noPostsHere"), words: words }), _jsx(Pager, { list: data.posts, path: path, previous: t("blog.newerPosts"), next: t("blog.olderPosts"), className: "bl-pager", words: words })] }));
94
+ }
95
+ const Category = (props) => _jsx(Archive, { ...props, heading: props.t("blog.category") });
96
+ const Tag = (props) => _jsx(Archive, { ...props, heading: props.t("blog.tag") });
97
+ const TextBlock = ({ value }) => _jsx(RichText, { doc: value.body });
98
+ function Quote({ value }) {
99
+ return (_jsxs("blockquote", { className: "bl-quote", children: [_jsx("p", { children: text(value.text) }), text(value.source) && _jsx("cite", { children: text(value.source) })] }));
100
+ }
101
+ function Callout({ value }) {
102
+ const tone = ["info", "tip", "warning"].includes(text(value.tone)) ? text(value.tone) : "info";
103
+ return _jsx("aside", { className: `bl-callout bl-callout-${tone}`, role: "note", children: _jsx(RichText, { doc: value.body }) });
104
+ }
105
+ function Image({ value }) {
106
+ if (!text(value.image))
107
+ return null;
108
+ return (_jsxs("figure", { className: "bl-figure", children: [_jsx("img", { src: fileHref(text(value.image), "800x0"), alt: text(value.alt), loading: "lazy" }), text(value.caption) && _jsx("figcaption", { children: text(value.caption) })] }));
109
+ }
110
+ function Embed({ value, words }) {
111
+ const url = text(value.url);
112
+ const src = embedUrl(url);
113
+ return (_jsxs("figure", { className: "bl-figure", children: [src
114
+ ? _jsx("div", { className: "bl-embed", children: _jsx("iframe", { src: src, title: text(value.caption) || blogWords(words).t("blog.video"), loading: "lazy", allow: "encrypted-media; picture-in-picture; fullscreen", referrerPolicy: "strict-origin-when-cross-origin", sandbox: "allow-scripts allow-same-origin allow-presentation" }) })
115
+ : _jsx("a", { href: url.startsWith("https://") ? url : undefined, rel: "noopener noreferrer", children: url }), text(value.caption) && _jsx("figcaption", { children: text(value.caption) })] }));
116
+ }
117
+ function Code({ value }) {
118
+ const language = text(value.language).replace(/[^a-z0-9+#-]/gi, "");
119
+ return _jsx("pre", { className: "bl-code", children: _jsx("code", { "data-language": language || undefined, children: text(value.code) }) });
120
+ }
121
+ const LOOKUP = { perPage: 200, fields: "id,name", urls: "1" };
122
+ const LISTED = { collection: "blog-posts", sort: "-publishedAt", fields: "id,title,excerpt,publishedAt,readingMinutes,byline,featured", urls: "1" };
123
+ const PAGE = 20;
124
+ export default defineRenderers({
125
+ messages: siteMessages,
126
+ blocks: { blog_text: TextBlock, blog_quote: Quote, blog_callout: Callout, blog_image: Image, blog_embed: Embed, blog_code: Code },
127
+ templates: { "blog-home": Home, "blog-posts": Post, "blog-categories": Category, "blog-tags": Tag },
128
+ queries: {
129
+ "blog-home": { posts: { ...LISTED, perPage: PAGE, paged: true } },
130
+ "blog-posts": {
131
+ related: { ...LISTED, filter: "tags ?= @record.tags && id != @record.id", perPage: 3 },
132
+ recent: { ...LISTED, perPage: 4 },
133
+ categories: { collection: "blog-categories", ...LOOKUP },
134
+ tags: { collection: "blog-tags", ...LOOKUP },
135
+ comments: { collection: "blog-comments", filter: "post = @record.id", sort: "createdAt", perPage: 200, fields: "id,name,body,parent,createdAt" },
136
+ },
137
+ "blog-categories": { posts: { ...LISTED, filter: "categories ?= @record.id", perPage: PAGE, paged: true } },
138
+ "blog-tags": { posts: { ...LISTED, filter: "tags ?= @record.id", perPage: PAGE, paged: true } },
139
+ },
140
+ });