@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/schema.d.ts ADDED
@@ -0,0 +1,313 @@
1
+ import type { PluginRole } from "tansy/plugin";
2
+ /** The collections the blog creates on first install. Owners can change all of it afterwards. */
3
+ export declare const COLLECTIONS: readonly ["blog-categories", "blog-tags", "blog-posts", "blog-comments", "blog-home"];
4
+ /** Blocks a post's body allows when it's created. Owners can add their own. */
5
+ export declare const BODY_BLOCKS: string[];
6
+ /** Who writes and who runs the blog. Created once, then owners change them under Roles like any other. */
7
+ export declare function blogRoles(): PluginRole[];
8
+ /** The name shown on a post. Filled from the writer's account, and only editors can change it. */
9
+ export declare const BYLINE_FIELD: {
10
+ name: string;
11
+ type: string;
12
+ config: {
13
+ maxLength: number;
14
+ };
15
+ };
16
+ /** A field the plugin's code reads or writes, by collection: the contract Extensions checks. */
17
+ export declare const CONTRACT: {
18
+ "blog-posts": {
19
+ slug: string;
20
+ title: string;
21
+ excerpt: string;
22
+ body: string;
23
+ byline: string;
24
+ categories: string;
25
+ tags: string;
26
+ allowComments: string;
27
+ readingMinutes: string;
28
+ };
29
+ "blog-categories": {
30
+ slug: string;
31
+ name: string;
32
+ };
33
+ "blog-tags": {
34
+ slug: string;
35
+ name: string;
36
+ };
37
+ "blog-comments": {
38
+ post: string;
39
+ parent: string;
40
+ name: string;
41
+ body: string;
42
+ state: string;
43
+ };
44
+ };
45
+ export declare function blogSchema(basePath: string): {
46
+ version: number;
47
+ collections: ({
48
+ slug: string;
49
+ name: string;
50
+ description: string;
51
+ urlPattern: string;
52
+ rules: {
53
+ listRule: string;
54
+ viewRule: string;
55
+ createRule: null;
56
+ updateRule: null;
57
+ deleteRule: null;
58
+ };
59
+ fields: ({
60
+ name: string;
61
+ type: string;
62
+ config: {
63
+ unique: boolean;
64
+ maxLength: number;
65
+ pattern: string;
66
+ patternError: string;
67
+ };
68
+ } | {
69
+ name: string;
70
+ type: string;
71
+ config: {
72
+ required: boolean;
73
+ maxLength: number;
74
+ multiline?: undefined;
75
+ collection?: undefined;
76
+ displayField?: undefined;
77
+ };
78
+ } | {
79
+ name: string;
80
+ type: string;
81
+ config: {
82
+ multiline: boolean;
83
+ maxLength: number;
84
+ required?: undefined;
85
+ collection?: undefined;
86
+ displayField?: undefined;
87
+ };
88
+ } | {
89
+ name: string;
90
+ type: string;
91
+ config: {
92
+ collection: string;
93
+ displayField: string;
94
+ required?: undefined;
95
+ maxLength?: undefined;
96
+ multiline?: undefined;
97
+ };
98
+ })[];
99
+ type?: undefined;
100
+ } | {
101
+ slug: string;
102
+ name: string;
103
+ description: string;
104
+ urlPattern: string;
105
+ rules: {
106
+ listRule: string;
107
+ viewRule: string;
108
+ createRule: null;
109
+ updateRule: null;
110
+ deleteRule: null;
111
+ };
112
+ fields: ({
113
+ name: string;
114
+ type: string;
115
+ config: {
116
+ maxLength: number;
117
+ };
118
+ } | {
119
+ name: string;
120
+ type: string;
121
+ config: {
122
+ required: boolean;
123
+ maxLength: number;
124
+ searchable: boolean;
125
+ multiline?: undefined;
126
+ allowedBlocks?: undefined;
127
+ collection?: undefined;
128
+ displayField?: undefined;
129
+ allowMultiple?: undefined;
130
+ defaultValue?: undefined;
131
+ };
132
+ } | {
133
+ name: string;
134
+ type: string;
135
+ config: {
136
+ multiline: boolean;
137
+ maxLength: number;
138
+ searchable: boolean;
139
+ required?: undefined;
140
+ allowedBlocks?: undefined;
141
+ collection?: undefined;
142
+ displayField?: undefined;
143
+ allowMultiple?: undefined;
144
+ defaultValue?: undefined;
145
+ };
146
+ } | {
147
+ name: string;
148
+ type: string;
149
+ config: {
150
+ required?: undefined;
151
+ maxLength?: undefined;
152
+ searchable?: undefined;
153
+ multiline?: undefined;
154
+ allowedBlocks?: undefined;
155
+ collection?: undefined;
156
+ displayField?: undefined;
157
+ allowMultiple?: undefined;
158
+ defaultValue?: undefined;
159
+ };
160
+ } | {
161
+ name: string;
162
+ type: string;
163
+ config: {
164
+ allowedBlocks: string[];
165
+ required?: undefined;
166
+ maxLength?: undefined;
167
+ searchable?: undefined;
168
+ multiline?: undefined;
169
+ collection?: undefined;
170
+ displayField?: undefined;
171
+ allowMultiple?: undefined;
172
+ defaultValue?: undefined;
173
+ };
174
+ } | {
175
+ name: string;
176
+ type: string;
177
+ config: {
178
+ collection: string;
179
+ displayField: string;
180
+ allowMultiple: boolean;
181
+ required?: undefined;
182
+ maxLength?: undefined;
183
+ searchable?: undefined;
184
+ multiline?: undefined;
185
+ allowedBlocks?: undefined;
186
+ defaultValue?: undefined;
187
+ };
188
+ } | {
189
+ name: string;
190
+ type: string;
191
+ config: {
192
+ defaultValue: boolean;
193
+ required?: undefined;
194
+ maxLength?: undefined;
195
+ searchable?: undefined;
196
+ multiline?: undefined;
197
+ allowedBlocks?: undefined;
198
+ collection?: undefined;
199
+ displayField?: undefined;
200
+ allowMultiple?: undefined;
201
+ };
202
+ })[];
203
+ type?: undefined;
204
+ } | {
205
+ slug: string;
206
+ name: string;
207
+ description: string;
208
+ urlPattern: null;
209
+ rules: {
210
+ listRule: string;
211
+ viewRule: string;
212
+ createRule: string;
213
+ updateRule: null;
214
+ deleteRule: string;
215
+ };
216
+ fields: ({
217
+ name: string;
218
+ type: string;
219
+ config: {
220
+ collection: string;
221
+ displayField: string;
222
+ required: boolean;
223
+ maxLength?: undefined;
224
+ multiline?: undefined;
225
+ options?: undefined;
226
+ defaultValue?: undefined;
227
+ };
228
+ } | {
229
+ name: string;
230
+ type: string;
231
+ config: {
232
+ collection: string;
233
+ displayField: string;
234
+ required?: undefined;
235
+ maxLength?: undefined;
236
+ multiline?: undefined;
237
+ options?: undefined;
238
+ defaultValue?: undefined;
239
+ };
240
+ } | {
241
+ name: string;
242
+ type: string;
243
+ config: {
244
+ required: boolean;
245
+ maxLength: number;
246
+ collection?: undefined;
247
+ displayField?: undefined;
248
+ multiline?: undefined;
249
+ options?: undefined;
250
+ defaultValue?: undefined;
251
+ };
252
+ } | {
253
+ name: string;
254
+ type: string;
255
+ config: {
256
+ required: boolean;
257
+ multiline: boolean;
258
+ maxLength: number;
259
+ collection?: undefined;
260
+ displayField?: undefined;
261
+ options?: undefined;
262
+ defaultValue?: undefined;
263
+ };
264
+ } | {
265
+ name: string;
266
+ type: string;
267
+ config: {
268
+ options: {
269
+ label: string;
270
+ value: string;
271
+ }[];
272
+ defaultValue: string;
273
+ collection?: undefined;
274
+ displayField?: undefined;
275
+ required?: undefined;
276
+ maxLength?: undefined;
277
+ multiline?: undefined;
278
+ };
279
+ })[];
280
+ type?: undefined;
281
+ } | {
282
+ slug: string;
283
+ name: string;
284
+ description: string;
285
+ type: string;
286
+ urlPattern: string;
287
+ rules: {
288
+ listRule: string;
289
+ viewRule: string;
290
+ createRule: null;
291
+ updateRule: null;
292
+ deleteRule: null;
293
+ };
294
+ fields: ({
295
+ name: string;
296
+ type: string;
297
+ config: {
298
+ required: boolean;
299
+ maxLength: number;
300
+ allowedBlocks?: undefined;
301
+ };
302
+ } | {
303
+ name: string;
304
+ type: string;
305
+ config: {
306
+ allowedBlocks: string[];
307
+ required?: undefined;
308
+ maxLength?: undefined;
309
+ };
310
+ })[];
311
+ })[];
312
+ blocks: never[];
313
+ };
package/schema.js ADDED
@@ -0,0 +1,119 @@
1
+ /** The collections the blog creates on first install. Owners can change all of it afterwards. */
2
+ export const COLLECTIONS = ["blog-categories", "blog-tags", "blog-posts", "blog-comments", "blog-home"];
3
+ /** Blocks a post's body allows when it's created. Owners can add their own. */
4
+ export const BODY_BLOCKS = ["blog_text", "blog_image", "blog_quote", "blog_code", "blog_embed", "blog_callout"];
5
+ /** Who writes and who runs the blog. Created once, then owners change them under Roles like any other. */
6
+ export function blogRoles() {
7
+ const writing = ["dashboard:access", "collection:read", "file:list", "file:read", "file:create"];
8
+ return [
9
+ {
10
+ name: "blog-author",
11
+ label: "Blog author",
12
+ description: "Writes posts, and edits and deletes only their own. Their byline is their name.",
13
+ permissions: writing,
14
+ records: { "blog-posts": ["create", "list:own", "read:own", "update:own", "delete:own"] },
15
+ },
16
+ {
17
+ name: "blog-editor",
18
+ label: "Blog editor",
19
+ description: "Edits every post, category and tag, writes any byline, and moderates comments.",
20
+ permissions: [...writing, "file:delete", "ext.blog:moderate", "ext.blog:credit"],
21
+ records: Object.fromEntries(COLLECTIONS.map((slug) => [slug, ["list", "read", "create", "update", "delete"]])),
22
+ },
23
+ ];
24
+ }
25
+ /** Filled from the title or name when left empty, so it isn't required. */
26
+ const SLUG_FIELD = {
27
+ name: "slug",
28
+ type: "text",
29
+ config: { unique: true, maxLength: 80, pattern: "^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$", patternError: "Use lowercase letters, numbers and hyphens, starting and ending with a letter or number." },
30
+ };
31
+ /** The name shown on a post. Filled from the writer's account, and only editors can change it. */
32
+ export const BYLINE_FIELD = { name: "byline", type: "text", config: { maxLength: 120 } };
33
+ const PUBLIC = { listRule: "", viewRule: "", createRule: null, updateRule: null, deleteRule: null };
34
+ /** A field the plugin's code reads or writes, by collection: the contract Extensions checks. */
35
+ export const CONTRACT = {
36
+ "blog-posts": { slug: "text", title: "text", excerpt: "text", body: "stream", byline: "text", categories: "reference", tags: "reference", allowComments: "boolean", readingMinutes: "number" },
37
+ "blog-categories": { slug: "text", name: "text" },
38
+ "blog-tags": { slug: "text", name: "text" },
39
+ "blog-comments": { post: "reference", parent: "reference", name: "text", body: "text", state: "radio" },
40
+ };
41
+ export function blogSchema(basePath) {
42
+ return {
43
+ version: 1,
44
+ collections: [
45
+ {
46
+ slug: "blog-categories",
47
+ name: "Categories",
48
+ description: "Broad topics. A category can sit inside another.",
49
+ urlPattern: `${basePath}/category/:slug`,
50
+ rules: PUBLIC,
51
+ fields: [
52
+ SLUG_FIELD,
53
+ { name: "name", type: "text", config: { required: true, maxLength: 120 } },
54
+ { name: "description", type: "text", config: { multiline: true, maxLength: 1000 } },
55
+ { name: "parent", type: "reference", config: { collection: "blog-categories", displayField: "name" } },
56
+ ],
57
+ },
58
+ {
59
+ slug: "blog-tags",
60
+ name: "Tags",
61
+ description: "Narrow topics, many to a post.",
62
+ urlPattern: `${basePath}/tag/:slug`,
63
+ rules: PUBLIC,
64
+ fields: [
65
+ SLUG_FIELD,
66
+ { name: "name", type: "text", config: { required: true, maxLength: 120 } },
67
+ ],
68
+ },
69
+ {
70
+ slug: "blog-posts",
71
+ name: "Posts",
72
+ description: "Articles. A slug, excerpt and reading time are filled in when left empty.",
73
+ urlPattern: `${basePath}/:slug`,
74
+ rules: { listRule: 'status = "published"', viewRule: 'status = "published"', createRule: null, updateRule: null, deleteRule: null },
75
+ fields: [
76
+ { name: "title", type: "text", config: { required: true, maxLength: 200, searchable: true } },
77
+ SLUG_FIELD,
78
+ { name: "excerpt", type: "text", config: { multiline: true, maxLength: 500, searchable: true } },
79
+ { name: "cover", type: "image", config: {} },
80
+ { name: "body", type: "stream", config: { allowedBlocks: BODY_BLOCKS } },
81
+ BYLINE_FIELD,
82
+ { name: "categories", type: "reference", config: { collection: "blog-categories", displayField: "name", allowMultiple: true } },
83
+ { name: "tags", type: "reference", config: { collection: "blog-tags", displayField: "name", allowMultiple: true } },
84
+ { name: "featured", type: "boolean", config: {} },
85
+ { name: "allowComments", type: "boolean", config: { defaultValue: true } },
86
+ { name: "readingMinutes", type: "number", config: {} },
87
+ ],
88
+ },
89
+ {
90
+ slug: "blog-comments",
91
+ name: "Comments",
92
+ description: "Readers' comments. New ones wait for approval unless comments are open.",
93
+ urlPattern: null,
94
+ // Commenters also see their own comments while they wait, so a new comment doesn't seem to vanish.
95
+ rules: { listRule: 'state = "approved" || (@request.auth.id != "" && createdById = @request.auth.id)', viewRule: 'state = "approved" || (@request.auth.id != "" && createdById = @request.auth.id)', createRule: '@request.auth.id != ""', updateRule: null, deleteRule: '@request.auth.id != "" && createdById = @request.auth.id' },
96
+ fields: [
97
+ { name: "post", type: "reference", config: { collection: "blog-posts", displayField: "title", required: true } },
98
+ { name: "parent", type: "reference", config: { collection: "blog-comments", displayField: "name" } },
99
+ { name: "name", type: "text", config: { required: true, maxLength: 80 } },
100
+ { name: "body", type: "text", config: { required: true, multiline: true, maxLength: 5000 } },
101
+ { name: "state", type: "radio", config: { options: [{ label: "Waiting for review", value: "pending" }, { label: "Approved", value: "approved" }, { label: "Spam", value: "spam" }], defaultValue: "pending" } },
102
+ ],
103
+ },
104
+ {
105
+ slug: "blog-home",
106
+ name: "Blog home",
107
+ description: "The heading and introduction of the blog's front page.",
108
+ type: "singleton",
109
+ urlPattern: basePath,
110
+ rules: PUBLIC,
111
+ fields: [
112
+ { name: "title", type: "text", config: { required: true, maxLength: 120 } },
113
+ { name: "intro", type: "stream", config: { allowedBlocks: BODY_BLOCKS } },
114
+ ],
115
+ },
116
+ ],
117
+ blocks: [],
118
+ };
119
+ }
@@ -0,0 +1,64 @@
1
+ import { type SiteWords } from "tansy/react";
2
+ /** What visitors read on the blog's pages, read as `t("blog.<key>")`. Themes and owners can word any of it differently. */
3
+ export declare const siteMessages: {
4
+ en: {
5
+ blog: {
6
+ home: string;
7
+ noPosts: string;
8
+ noPostsHere: string;
9
+ newerPosts: string;
10
+ olderPosts: string;
11
+ minutes: string;
12
+ tags: string;
13
+ morePosts: string;
14
+ category: string;
15
+ tag: string;
16
+ video: string;
17
+ comments: string;
18
+ noComments: string;
19
+ leaveComment: string;
20
+ name: string;
21
+ comment: string;
22
+ reply: string;
23
+ postComment: string;
24
+ postReply: string;
25
+ posting: string;
26
+ cancel: string;
27
+ waiting: string;
28
+ signIn: string;
29
+ failed: string;
30
+ offline: string;
31
+ };
32
+ };
33
+ ar: {
34
+ blog: {
35
+ home: string;
36
+ noPosts: string;
37
+ noPostsHere: string;
38
+ newerPosts: string;
39
+ olderPosts: string;
40
+ minutes: string;
41
+ tags: string;
42
+ morePosts: string;
43
+ category: string;
44
+ tag: string;
45
+ video: string;
46
+ comments: string;
47
+ noComments: string;
48
+ leaveComment: string;
49
+ name: string;
50
+ comment: string;
51
+ reply: string;
52
+ postComment: string;
53
+ postReply: string;
54
+ posting: string;
55
+ cancel: string;
56
+ waiting: string;
57
+ signIn: string;
58
+ failed: string;
59
+ offline: string;
60
+ };
61
+ };
62
+ };
63
+ /** The blog's words in the page's language, or in English where a theme passes none. */
64
+ export declare const blogWords: (words: SiteWords | undefined) => import("tansy/plugin").Formatters;
@@ -0,0 +1,65 @@
1
+ import { siteWords } from "tansy/react";
2
+ /** What visitors read on the blog's pages, read as `t("blog.<key>")`. Themes and owners can word any of it differently. */
3
+ export const siteMessages = {
4
+ en: {
5
+ blog: {
6
+ home: "Blog",
7
+ noPosts: "No posts yet.",
8
+ noPostsHere: "No posts here yet.",
9
+ newerPosts: "Newer posts",
10
+ olderPosts: "Older posts",
11
+ minutes: "{count, plural, one {# min read} other {# min read}}",
12
+ tags: "Tags",
13
+ morePosts: "More posts",
14
+ category: "Category",
15
+ tag: "Tag",
16
+ video: "Video",
17
+ comments: "Comments",
18
+ noComments: "No comments yet.",
19
+ leaveComment: "Leave a comment",
20
+ name: "Name",
21
+ comment: "Comment",
22
+ reply: "Reply",
23
+ postComment: "Post comment",
24
+ postReply: "Post reply",
25
+ posting: "Posting…",
26
+ cancel: "Cancel",
27
+ waiting: "Waiting for review",
28
+ signIn: "Sign in to comment.",
29
+ failed: "Your comment couldn't be posted. Try again.",
30
+ offline: "Your comment couldn't be posted. Check your connection and try again.",
31
+ },
32
+ },
33
+ ar: {
34
+ blog: {
35
+ home: "المدونة",
36
+ noPosts: "لا توجد مقالات بعد.",
37
+ noPostsHere: "لا توجد مقالات هنا بعد.",
38
+ newerPosts: "مقالات أحدث",
39
+ olderPosts: "مقالات أقدم",
40
+ minutes: "{count, plural, zero {أقل من دقيقة قراءة} one {دقيقة قراءة} two {دقيقتا قراءة} few {# دقائق قراءة} many {# دقيقة قراءة} other {# دقيقة قراءة}}",
41
+ tags: "الوسوم",
42
+ morePosts: "مقالات أخرى",
43
+ category: "تصنيف",
44
+ tag: "وسم",
45
+ video: "فيديو",
46
+ comments: "التعليقات",
47
+ noComments: "لا توجد تعليقات بعد.",
48
+ leaveComment: "اترك تعليقًا",
49
+ name: "الاسم",
50
+ comment: "التعليق",
51
+ reply: "رد",
52
+ postComment: "نشر التعليق",
53
+ postReply: "نشر الرد",
54
+ posting: "جارٍ النشر…",
55
+ cancel: "إلغاء",
56
+ waiting: "بانتظار المراجعة",
57
+ signIn: "سجّل الدخول لتعلّق.",
58
+ failed: "تعذّر نشر تعليقك. حاول مجددًا.",
59
+ offline: "تعذّر نشر تعليقك. تحقق من اتصالك وحاول مجددًا.",
60
+ },
61
+ },
62
+ };
63
+ const ENGLISH = { locale: "en", messages: siteMessages.en };
64
+ /** The blog's words in the page's language, or in English where a theme passes none. */
65
+ export const blogWords = (words) => siteWords(words ?? ENGLISH);
package/text.d.ts ADDED
@@ -0,0 +1,32 @@
1
+ /** Pure helpers, shared by the server half and the render module. No imports, so both can use them. */
2
+ export declare const SLUG: RegExp;
3
+ /** Lowercase letters, digits and single hyphens, from any title. */
4
+ export declare function slugify(text: string): string;
5
+ /** The prose in a post's blocks, in order. Code and embeds aren't prose. */
6
+ export declare function blockParagraphs(blocks: unknown): string[];
7
+ export declare const WORDS_PER_MINUTE = 220;
8
+ export declare function readingMinutes(blocks: unknown): number;
9
+ /** The first paragraph, cut at a word boundary. */
10
+ export declare function excerptOf(blocks: unknown, max?: number): string;
11
+ /** Only YouTube and Vimeo, as the plugin's frame-src lists only them. Anything else stays a link. */
12
+ export declare function embedUrl(url: string): string | null;
13
+ export declare const escapeXml: (text: string) => string;
14
+ export interface FeedItem {
15
+ title: string;
16
+ url: string;
17
+ summary: string;
18
+ publishedAt: string;
19
+ updatedAt: string;
20
+ }
21
+ export interface Feed {
22
+ title: string;
23
+ siteUrl: string;
24
+ feedUrl: string;
25
+ items: FeedItem[];
26
+ }
27
+ export declare function rss({ title, siteUrl, feedUrl, items }: Feed): string;
28
+ export declare function atom({ title, siteUrl, feedUrl, items }: Feed): string;
29
+ /** The levels a theme can give a part's heading. The page's own h1 is the theme's. */
30
+ export type HeadingLevel = 2 | 3 | 4 | 5 | 6;
31
+ /** The tag for a heading at `level`, kept between h2 and h6. */
32
+ export declare function headingTag(level?: number): `h${HeadingLevel}`;