@composable-os/pack-content 0.0.0-stage → 0.1.0-beta.8
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/LICENSE +109 -0
- package/dist/blocks/content-native-post/post-screen.d.ts +11 -0
- package/dist/blocks/content-native-post/post-screen.js +26 -0
- package/dist/blocks/content-native-rich-text/rich-text-view.d.ts +24 -0
- package/dist/blocks/content-native-rich-text/rich-text-view.js +122 -0
- package/dist/blocks/content-post/post-page.d.ts +35 -0
- package/dist/blocks/content-post/post-page.js +41 -0
- package/dist/blocks/content-post-list/post-list.d.ts +15 -0
- package/dist/blocks/content-post-list/post-list.js +25 -0
- package/dist/blocks/content-rich-text/rich-text.d.ts +28 -0
- package/dist/blocks/content-rich-text/rich-text.js +85 -0
- package/dist/client/index.d.ts +514 -0
- package/dist/client/index.js +198 -0
- package/dist/index.d.ts +167 -0
- package/dist/index.js +149 -0
- package/dist/tools.d.ts +11 -0
- package/dist/tools.js +30 -0
- package/package.json +36 -4
- package/README.md +0 -3
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
// The Content pack's headless entry (stage 28, step 6; ADRs 0418 and 0453): functions and hooks
|
|
2
|
+
// over the typed client, no markup. A client app imports it as `@composable-os/pack-content/client`
|
|
3
|
+
// and hands it its generated client; the content blocks render what it returns.
|
|
4
|
+
//
|
|
5
|
+
// The public reads posts with the host's own `content.get`, `content.list` and `content.preview`
|
|
6
|
+
// (ADR 0442): only published versions, only the fields the post declares public. Nothing here
|
|
7
|
+
// decides what is published or who may read it. Rich text arrives as structured data (ADR 0440);
|
|
8
|
+
// the renderers draw it block by block with the app's own components and never as HTML.
|
|
9
|
+
import { packHooks } from "@composable-os/client";
|
|
10
|
+
/** The post object, as the host names it. */
|
|
11
|
+
export const POST = "content.post";
|
|
12
|
+
// --- Plain functions ------------------------------------------------------------------------------
|
|
13
|
+
/**
|
|
14
|
+
* Where a picture is, at the width asked for: `/api/media/<id>?w=640` on a site's own hostname,
|
|
15
|
+
* which the client template's media route forwards to the host (issue #181). `base` puts another
|
|
16
|
+
* origin or prefix in front (`https://cdn.example.com`).
|
|
17
|
+
*/
|
|
18
|
+
export function mediaPath(id, width, base = "") {
|
|
19
|
+
return `${base.replace(/\/+$/, "")}/api/media/${encodeURIComponent(id)}${width ? `?w=${Math.round(width)}` : ""}`;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Where a phone asks the host itself for a picture: its public media route beside the HTTP
|
|
23
|
+
* surface, `https://<host>/api/v1/media/<id>?w=<width>` (bypassed by Cloudflare Access with the
|
|
24
|
+
* rest of /api/v1). For the native blocks' `mediaUrl`: `hostMediaUrl(hostUrl)`.
|
|
25
|
+
*/
|
|
26
|
+
export function hostMediaUrl(hostUrl) {
|
|
27
|
+
const host = hostUrl.replace(/\/+$/, "");
|
|
28
|
+
return (id, width) => `${host}/api/v1/media/${encodeURIComponent(id)}${width ? `?w=${Math.round(width)}` : ""}`;
|
|
29
|
+
}
|
|
30
|
+
/** The text of inline runs, without marks: for excerpts, alt text and screen readers. */
|
|
31
|
+
export function inlineText(content) {
|
|
32
|
+
return (content ?? []).map((run) => (run.type === "text" ? run.text : "\n")).join("");
|
|
33
|
+
}
|
|
34
|
+
/** A document's words, block by block, for a summary or a search box. */
|
|
35
|
+
export function plainText(value) {
|
|
36
|
+
const out = [];
|
|
37
|
+
const list = (body) => {
|
|
38
|
+
for (const item of body.items) {
|
|
39
|
+
out.push(inlineText(item.content));
|
|
40
|
+
if (item.list)
|
|
41
|
+
list(item.list);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
for (const block of value?.blocks ?? []) {
|
|
45
|
+
switch (block.type) {
|
|
46
|
+
case "paragraph":
|
|
47
|
+
case "heading":
|
|
48
|
+
case "quote":
|
|
49
|
+
case "callout":
|
|
50
|
+
out.push(inlineText(block.content));
|
|
51
|
+
break;
|
|
52
|
+
case "list":
|
|
53
|
+
list(block);
|
|
54
|
+
break;
|
|
55
|
+
case "image":
|
|
56
|
+
if (block.caption)
|
|
57
|
+
out.push(inlineText(block.caption));
|
|
58
|
+
break;
|
|
59
|
+
case "embed":
|
|
60
|
+
if (block.caption)
|
|
61
|
+
out.push(block.caption);
|
|
62
|
+
break;
|
|
63
|
+
case "button":
|
|
64
|
+
out.push(block.label);
|
|
65
|
+
break;
|
|
66
|
+
case "divider":
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return out.filter(Boolean).join("\n");
|
|
71
|
+
}
|
|
72
|
+
/** What an embed's address is: a YouTube or Vimeo video the renderer can show, or a link. */
|
|
73
|
+
export function embedKind(url) {
|
|
74
|
+
const youtube = /^https:\/\/(?:www\.|m\.)?youtube\.com\/watch\?(?:.*&)?v=([A-Za-z0-9_-]{6,20})/.exec(url) ??
|
|
75
|
+
/^https:\/\/youtu\.be\/([A-Za-z0-9_-]{6,20})/.exec(url) ??
|
|
76
|
+
/^https:\/\/(?:www\.)?youtube\.com\/(?:embed|shorts)\/([A-Za-z0-9_-]{6,20})/.exec(url);
|
|
77
|
+
if (youtube?.[1])
|
|
78
|
+
return { kind: "youtube", id: youtube[1] };
|
|
79
|
+
const vimeo = /^https:\/\/(?:www\.|player\.)?vimeo\.com\/(?:video\/)?([0-9]{4,15})/.exec(url);
|
|
80
|
+
if (vimeo?.[1])
|
|
81
|
+
return { kind: "vimeo", id: vimeo[1] };
|
|
82
|
+
return { kind: "link" };
|
|
83
|
+
}
|
|
84
|
+
/** The player address for a video embed, from the id `embedKind` found (never the raw URL). */
|
|
85
|
+
export function embedPlayer(kind) {
|
|
86
|
+
return kind.kind === "youtube"
|
|
87
|
+
? `https://www.youtube-nocookie.com/embed/${encodeURIComponent(kind.id)}`
|
|
88
|
+
: `https://player.vimeo.com/video/${encodeURIComponent(kind.id)}`;
|
|
89
|
+
}
|
|
90
|
+
/** A post's date as a reader sees it (`21 Nov 2026`), in their own locale. Display only. */
|
|
91
|
+
export function postDate(post, locale) {
|
|
92
|
+
const iso = post.values.date ?? post.values.publishedAt;
|
|
93
|
+
if (!iso)
|
|
94
|
+
return "";
|
|
95
|
+
const at = new Date(iso);
|
|
96
|
+
if (Number.isNaN(at.getTime()))
|
|
97
|
+
return "";
|
|
98
|
+
try {
|
|
99
|
+
return new Intl.DateTimeFormat(locale, { dateStyle: "medium" }).format(at);
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
return iso.slice(0, 10);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* The head of a post's page, from its published values (ADR 0470): its search title (else its
|
|
107
|
+
* title, with ` · <siteName>`), its search description (else its excerpt, else the start of its
|
|
108
|
+
* body), its share picture (else its cover), and whether to ask search engines not to list it.
|
|
109
|
+
* Plain data, so any page can render it: React 19's hoisted <title>/<meta> (the `PostHead` block),
|
|
110
|
+
* TanStack Start's route `head()`, or an Astro page's <head>.
|
|
111
|
+
*/
|
|
112
|
+
export function postHead(post, options = {}) {
|
|
113
|
+
const v = post.values;
|
|
114
|
+
const base = v.seoTitle || v.title || "";
|
|
115
|
+
const title = options.siteName && !v.seoTitle ? `${base} · ${options.siteName}` : base;
|
|
116
|
+
const words = v.seoDescription || v.excerpt || plainText(v.body).slice(0, 200).trim();
|
|
117
|
+
const picture = v.seoImage ?? v.cover ?? null;
|
|
118
|
+
const toUrl = options.mediaUrl ?? ((id, width) => mediaPath(id, width, options.origin ?? ""));
|
|
119
|
+
return {
|
|
120
|
+
title,
|
|
121
|
+
description: words || null,
|
|
122
|
+
image: picture ? { url: toUrl(picture.media, 1200), alt: picture.alt } : null,
|
|
123
|
+
robots: v.noindex ? "noindex" : null,
|
|
124
|
+
canonical: options.url ?? null,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* The operations each hook calls (ADR 0453). A customer's client and the public's get the
|
|
129
|
+
* reading hooks; the staff client gets the publish controls too.
|
|
130
|
+
*
|
|
131
|
+
* The publish controls are a person's: `usePublish` calls `record.publish`, which publishes at
|
|
132
|
+
* once for a person with the permission. An AI actor's call of the same operation waits for a
|
|
133
|
+
* person to approve it, whatever the policy (criterion 12, ADR 0480); that is the host's, so
|
|
134
|
+
* no hook and no block changes for it.
|
|
135
|
+
*/
|
|
136
|
+
export const CONTENT_HOOKS_CALL = {
|
|
137
|
+
usePosts: ["content.list"],
|
|
138
|
+
usePost: ["content.get"],
|
|
139
|
+
usePreview: ["content.preview"],
|
|
140
|
+
useCategories: ["x.content.categories"],
|
|
141
|
+
usePublish: ["record.publish"],
|
|
142
|
+
useSchedulePublish: ["record.schedulePublish"],
|
|
143
|
+
useUnpublish: ["record.unpublish"],
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* Hooks for a React or React Native app:
|
|
147
|
+
* `const content = createContentHooks({ useQuery, useMutation }, api)`. `api` is any generated
|
|
148
|
+
* client: the customer's, the public's (the same customer client, signed out) or the staff one.
|
|
149
|
+
* The hooks it cannot back are not there, and calling one does not compile.
|
|
150
|
+
*/
|
|
151
|
+
export function createContentHooks(react, client) {
|
|
152
|
+
return packHooks(client, CONTENT_HOOKS_CALL, (api) => allContentHooks(react, api));
|
|
153
|
+
}
|
|
154
|
+
function allContentHooks(react, api) {
|
|
155
|
+
const { useQuery, useMutation } = react;
|
|
156
|
+
return {
|
|
157
|
+
/** A page of published posts, newest first (or as asked). */
|
|
158
|
+
usePosts(input = {}, object = POST) {
|
|
159
|
+
return useQuery(api.query("content.list", { object, ...input }));
|
|
160
|
+
},
|
|
161
|
+
/**
|
|
162
|
+
* One published post by its address. An old address answers `redirect`: send the reader to
|
|
163
|
+
* the post's address now (a 301 on the web).
|
|
164
|
+
*/
|
|
165
|
+
usePost(slug, object = POST) {
|
|
166
|
+
const options = slug
|
|
167
|
+
? api.query("content.get", { object, slug })
|
|
168
|
+
: { queryKey: ["content.get", "none"], queryFn: async () => undefined };
|
|
169
|
+
return useQuery({ ...options, enabled: slug !== null });
|
|
170
|
+
},
|
|
171
|
+
/** A post's working copy, with a preview link's token. */
|
|
172
|
+
usePreview(slug, token, object = POST) {
|
|
173
|
+
const options = slug && token
|
|
174
|
+
? api.query("content.preview", { object, slug, token })
|
|
175
|
+
: { queryKey: ["content.preview", "none"], queryFn: async () => undefined };
|
|
176
|
+
return useQuery({
|
|
177
|
+
...options,
|
|
178
|
+
enabled: Boolean(slug && token),
|
|
179
|
+
});
|
|
180
|
+
},
|
|
181
|
+
/** The categories, by name. */
|
|
182
|
+
useCategories() {
|
|
183
|
+
return useQuery(api.query("x.content.categories", {}));
|
|
184
|
+
},
|
|
185
|
+
/** Staff: publish a post now (a person with the publish permission). */
|
|
186
|
+
usePublish() {
|
|
187
|
+
return useMutation(api.mutation("record.publish"));
|
|
188
|
+
},
|
|
189
|
+
/** Staff: publish a post at a time; what is published is the post as it is now. */
|
|
190
|
+
useSchedulePublish() {
|
|
191
|
+
return useMutation(api.mutation("record.schedulePublish"));
|
|
192
|
+
},
|
|
193
|
+
/** Staff: take a post down; its versions are kept. */
|
|
194
|
+
useUnpublish() {
|
|
195
|
+
return useMutation(api.mutation("record.unpublish"));
|
|
196
|
+
},
|
|
197
|
+
};
|
|
198
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
declare const _default: import("@composable-os/sdk").Extension<{
|
|
2
|
+
readonly id: "content";
|
|
3
|
+
readonly version: "0.2.0";
|
|
4
|
+
readonly contractVersion: 1;
|
|
5
|
+
readonly label: "Content";
|
|
6
|
+
readonly description: string;
|
|
7
|
+
readonly permissions: {
|
|
8
|
+
readonly operations: ["public.list"];
|
|
9
|
+
readonly modules: ["ops"];
|
|
10
|
+
};
|
|
11
|
+
readonly objects: {
|
|
12
|
+
readonly post: {
|
|
13
|
+
readonly label: "Post";
|
|
14
|
+
readonly plural: "Posts";
|
|
15
|
+
readonly icon: "newspaper";
|
|
16
|
+
readonly titleField: "title";
|
|
17
|
+
readonly description: string;
|
|
18
|
+
readonly fields: {
|
|
19
|
+
readonly title: {
|
|
20
|
+
readonly type: "text";
|
|
21
|
+
readonly label: "Title";
|
|
22
|
+
readonly required: true;
|
|
23
|
+
};
|
|
24
|
+
readonly slug: {
|
|
25
|
+
readonly type: "slug";
|
|
26
|
+
readonly label: "Address";
|
|
27
|
+
readonly description: "Where the post is read: /blog/<address>. Made from the title.";
|
|
28
|
+
};
|
|
29
|
+
readonly excerpt: {
|
|
30
|
+
readonly type: "text";
|
|
31
|
+
readonly label: "Excerpt";
|
|
32
|
+
readonly description: "One or two sentences for lists and link previews.";
|
|
33
|
+
};
|
|
34
|
+
readonly body: {
|
|
35
|
+
readonly type: "richText";
|
|
36
|
+
readonly label: "Body";
|
|
37
|
+
};
|
|
38
|
+
readonly cover: {
|
|
39
|
+
readonly type: "image";
|
|
40
|
+
readonly label: "Cover picture";
|
|
41
|
+
};
|
|
42
|
+
readonly author: {
|
|
43
|
+
readonly type: "user";
|
|
44
|
+
readonly label: "Author";
|
|
45
|
+
};
|
|
46
|
+
readonly byline: {
|
|
47
|
+
readonly type: "text";
|
|
48
|
+
readonly label: "Byline";
|
|
49
|
+
readonly description: "Who wrote it, as readers see it: \"Words by Sam Lee\". Left empty, none.";
|
|
50
|
+
};
|
|
51
|
+
readonly category: {
|
|
52
|
+
readonly type: "relation";
|
|
53
|
+
readonly label: "Category";
|
|
54
|
+
readonly to: "content.category";
|
|
55
|
+
};
|
|
56
|
+
readonly date: {
|
|
57
|
+
readonly type: "datetime";
|
|
58
|
+
readonly label: "Date";
|
|
59
|
+
readonly description: "The date readers are shown. Left empty, it is when the post goes live.";
|
|
60
|
+
};
|
|
61
|
+
readonly seoTitle: {
|
|
62
|
+
readonly type: "text";
|
|
63
|
+
readonly label: "Search title";
|
|
64
|
+
};
|
|
65
|
+
readonly seoDescription: {
|
|
66
|
+
readonly type: "text";
|
|
67
|
+
readonly label: "Search description";
|
|
68
|
+
};
|
|
69
|
+
readonly seoImage: {
|
|
70
|
+
readonly type: "image";
|
|
71
|
+
readonly label: "Share picture";
|
|
72
|
+
};
|
|
73
|
+
readonly noindex: {
|
|
74
|
+
readonly type: "boolean";
|
|
75
|
+
readonly label: "Hide from search engines";
|
|
76
|
+
readonly description: "Asks search engines not to list the post's page.";
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
readonly indexes: readonly [readonly ["category"], readonly ["date"]];
|
|
80
|
+
readonly publishable: {
|
|
81
|
+
readonly content: readonly ["title", "excerpt", "body", "cover", "author", "byline", "category", "date", "seoTitle", "seoDescription", "seoImage", "noindex"];
|
|
82
|
+
readonly slug: "slug";
|
|
83
|
+
readonly date: "date";
|
|
84
|
+
};
|
|
85
|
+
readonly public: {
|
|
86
|
+
readonly read: readonly ["title", "slug", "excerpt", "body", "cover", "byline", "category", "date", "publishedAt", "seoTitle", "seoDescription", "seoImage", "noindex"];
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
readonly category: {
|
|
90
|
+
readonly label: "Category";
|
|
91
|
+
readonly plural: "Categories";
|
|
92
|
+
readonly icon: "tags";
|
|
93
|
+
readonly titleField: "name";
|
|
94
|
+
readonly navigation: "settings";
|
|
95
|
+
readonly fields: {
|
|
96
|
+
readonly name: {
|
|
97
|
+
readonly type: "text";
|
|
98
|
+
readonly label: "Name";
|
|
99
|
+
readonly required: true;
|
|
100
|
+
};
|
|
101
|
+
readonly slug: {
|
|
102
|
+
readonly type: "slug";
|
|
103
|
+
readonly label: "Address";
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
readonly public: {
|
|
107
|
+
readonly read: readonly ["name", "slug"];
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
readonly views: {
|
|
112
|
+
readonly drafts: {
|
|
113
|
+
readonly label: "Drafts";
|
|
114
|
+
readonly object: "content.post";
|
|
115
|
+
readonly filter: {
|
|
116
|
+
readonly field: "publishState";
|
|
117
|
+
readonly op: "eq";
|
|
118
|
+
readonly value: "draft";
|
|
119
|
+
};
|
|
120
|
+
readonly sort: {
|
|
121
|
+
readonly field: "updatedAt";
|
|
122
|
+
readonly direction: "desc";
|
|
123
|
+
};
|
|
124
|
+
readonly columns: ["title", "category", "author", "updatedAt"];
|
|
125
|
+
};
|
|
126
|
+
readonly scheduled: {
|
|
127
|
+
readonly label: "Scheduled";
|
|
128
|
+
readonly object: "content.post";
|
|
129
|
+
readonly filter: {
|
|
130
|
+
readonly field: "publishState";
|
|
131
|
+
readonly op: "eq";
|
|
132
|
+
readonly value: "scheduled";
|
|
133
|
+
};
|
|
134
|
+
readonly sort: {
|
|
135
|
+
readonly field: "publishAt";
|
|
136
|
+
readonly direction: "asc";
|
|
137
|
+
};
|
|
138
|
+
readonly columns: ["title", "category", "author", "publishAt"];
|
|
139
|
+
};
|
|
140
|
+
readonly published: {
|
|
141
|
+
readonly label: "Published";
|
|
142
|
+
readonly object: "content.post";
|
|
143
|
+
readonly filter: {
|
|
144
|
+
readonly field: "publishState";
|
|
145
|
+
readonly op: "eq";
|
|
146
|
+
readonly value: "published";
|
|
147
|
+
};
|
|
148
|
+
readonly sort: {
|
|
149
|
+
readonly field: "date";
|
|
150
|
+
readonly direction: "desc";
|
|
151
|
+
};
|
|
152
|
+
readonly columns: ["title", "category", "date", "publishedAt", "publishedVersion"];
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
readonly tools: {
|
|
156
|
+
readonly categories: import("@composable-os/sdk").ToolSpec<import("zod").ZodObject<{
|
|
157
|
+
limit: import("zod").ZodDefault<import("zod").ZodNumber>;
|
|
158
|
+
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
159
|
+
categories: import("zod").ZodArray<import("zod").ZodObject<{
|
|
160
|
+
id: import("zod").ZodString;
|
|
161
|
+
name: import("zod").ZodNullable<import("zod").ZodString>;
|
|
162
|
+
slug: import("zod").ZodNullable<import("zod").ZodString>;
|
|
163
|
+
}, import("zod/v4/core").$strip>>;
|
|
164
|
+
}, import("zod/v4/core").$strip>>;
|
|
165
|
+
};
|
|
166
|
+
}>;
|
|
167
|
+
export default _default;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
// Content (stage 28, step 6): blog posts and their categories, which staff write and the public
|
|
2
|
+
// reads. Any product can turn it on (`packs` in its product.ts).
|
|
3
|
+
//
|
|
4
|
+
// Everything that is a rule is the host's, declared here as behaviours (ADR 0404):
|
|
5
|
+
// - a post is `publishable` (ADRs 0446, 0441): staff and the assistant edit its working copy;
|
|
6
|
+
// a person with the publish permission publishes it, now or at a time; its versions are kept;
|
|
7
|
+
// - the public reads only its published version, by its slug, with only the fields
|
|
8
|
+
// `public.read` lists (ADR 0442): `content.get` and `content.list`, which the hooks call;
|
|
9
|
+
// - its body is `richText` (ADR 0440) and its cover an `image` (ADR 0444): structured data,
|
|
10
|
+
// never HTML, and a picture the public is served only while a published post shows it.
|
|
11
|
+
// The pack adds no rule of its own. Its one tool lists the categories for a site's menu.
|
|
12
|
+
import { defineExtension } from "@composable-os/sdk";
|
|
13
|
+
import { categories } from "./tools.js";
|
|
14
|
+
export default defineExtension({
|
|
15
|
+
id: "content",
|
|
16
|
+
version: "0.2.0",
|
|
17
|
+
contractVersion: 1,
|
|
18
|
+
label: "Content",
|
|
19
|
+
description: "Blog posts and their categories: staff write and schedule them, a person publishes them, " +
|
|
20
|
+
"and the public reads what was published, on the web and in the app.",
|
|
21
|
+
permissions: {
|
|
22
|
+
// public.list: the categories the public may read, for the categories tool.
|
|
23
|
+
operations: ["public.list"],
|
|
24
|
+
modules: ["ops"],
|
|
25
|
+
},
|
|
26
|
+
objects: {
|
|
27
|
+
post: {
|
|
28
|
+
label: "Post",
|
|
29
|
+
plural: "Posts",
|
|
30
|
+
icon: "newspaper",
|
|
31
|
+
titleField: "title",
|
|
32
|
+
description: "A blog post. Its working copy is what staff edit; the public reads the version last " +
|
|
33
|
+
"published.",
|
|
34
|
+
fields: {
|
|
35
|
+
title: { type: "text", label: "Title", required: true },
|
|
36
|
+
slug: {
|
|
37
|
+
type: "slug",
|
|
38
|
+
label: "Address",
|
|
39
|
+
description: "Where the post is read: /blog/<address>. Made from the title.",
|
|
40
|
+
},
|
|
41
|
+
excerpt: {
|
|
42
|
+
type: "text",
|
|
43
|
+
label: "Excerpt",
|
|
44
|
+
description: "One or two sentences for lists and link previews.",
|
|
45
|
+
},
|
|
46
|
+
body: { type: "richText", label: "Body" },
|
|
47
|
+
cover: { type: "image", label: "Cover picture" },
|
|
48
|
+
author: { type: "user", label: "Author" },
|
|
49
|
+
// What readers see as who wrote it (ADR 0470): plain text, because a post's author is a
|
|
50
|
+
// staff account, which the public never reads.
|
|
51
|
+
byline: {
|
|
52
|
+
type: "text",
|
|
53
|
+
label: "Byline",
|
|
54
|
+
description: 'Who wrote it, as readers see it: "Words by Sam Lee". Left empty, none.',
|
|
55
|
+
},
|
|
56
|
+
category: { type: "relation", label: "Category", to: "content.category" },
|
|
57
|
+
date: {
|
|
58
|
+
type: "datetime",
|
|
59
|
+
label: "Date",
|
|
60
|
+
description: "The date readers are shown. Left empty, it is when the post goes live.",
|
|
61
|
+
},
|
|
62
|
+
// What search engines and link previews show (ADR 0470). Each is optional: left empty,
|
|
63
|
+
// the page uses the title, the excerpt and the cover.
|
|
64
|
+
seoTitle: { type: "text", label: "Search title" },
|
|
65
|
+
seoDescription: { type: "text", label: "Search description" },
|
|
66
|
+
seoImage: { type: "image", label: "Share picture" },
|
|
67
|
+
noindex: {
|
|
68
|
+
type: "boolean",
|
|
69
|
+
label: "Hide from search engines",
|
|
70
|
+
description: "Asks search engines not to list the post's page.",
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
indexes: [["category"], ["date"]],
|
|
74
|
+
publishable: {
|
|
75
|
+
content: [
|
|
76
|
+
"title",
|
|
77
|
+
"excerpt",
|
|
78
|
+
"body",
|
|
79
|
+
"cover",
|
|
80
|
+
"author",
|
|
81
|
+
"byline",
|
|
82
|
+
"category",
|
|
83
|
+
"date",
|
|
84
|
+
"seoTitle",
|
|
85
|
+
"seoDescription",
|
|
86
|
+
"seoImage",
|
|
87
|
+
"noindex",
|
|
88
|
+
],
|
|
89
|
+
slug: "slug",
|
|
90
|
+
date: "date",
|
|
91
|
+
},
|
|
92
|
+
// The author is a staff account, which the public does not read; a post shows its date.
|
|
93
|
+
public: {
|
|
94
|
+
read: [
|
|
95
|
+
"title",
|
|
96
|
+
"slug",
|
|
97
|
+
"excerpt",
|
|
98
|
+
"body",
|
|
99
|
+
"cover",
|
|
100
|
+
"byline",
|
|
101
|
+
"category",
|
|
102
|
+
"date",
|
|
103
|
+
"publishedAt",
|
|
104
|
+
"seoTitle",
|
|
105
|
+
"seoDescription",
|
|
106
|
+
"seoImage",
|
|
107
|
+
"noindex",
|
|
108
|
+
],
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
category: {
|
|
112
|
+
label: "Category",
|
|
113
|
+
plural: "Categories",
|
|
114
|
+
icon: "tags",
|
|
115
|
+
titleField: "name",
|
|
116
|
+
navigation: "settings",
|
|
117
|
+
fields: {
|
|
118
|
+
name: { type: "text", label: "Name", required: true },
|
|
119
|
+
slug: { type: "slug", label: "Address" },
|
|
120
|
+
},
|
|
121
|
+
// Every live category is public: a site's menu and a post's label.
|
|
122
|
+
public: { read: ["name", "slug"] },
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
views: {
|
|
126
|
+
drafts: {
|
|
127
|
+
label: "Drafts",
|
|
128
|
+
object: "content.post",
|
|
129
|
+
filter: { field: "publishState", op: "eq", value: "draft" },
|
|
130
|
+
sort: { field: "updatedAt", direction: "desc" },
|
|
131
|
+
columns: ["title", "category", "author", "updatedAt"],
|
|
132
|
+
},
|
|
133
|
+
scheduled: {
|
|
134
|
+
label: "Scheduled",
|
|
135
|
+
object: "content.post",
|
|
136
|
+
filter: { field: "publishState", op: "eq", value: "scheduled" },
|
|
137
|
+
sort: { field: "publishAt", direction: "asc" },
|
|
138
|
+
columns: ["title", "category", "author", "publishAt"],
|
|
139
|
+
},
|
|
140
|
+
published: {
|
|
141
|
+
label: "Published",
|
|
142
|
+
object: "content.post",
|
|
143
|
+
filter: { field: "publishState", op: "eq", value: "published" },
|
|
144
|
+
sort: { field: "date", direction: "desc" },
|
|
145
|
+
columns: ["title", "category", "date", "publishedAt", "publishedVersion"],
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
tools: { categories },
|
|
149
|
+
});
|
package/dist/tools.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from "@composable-os/sdk";
|
|
2
|
+
export declare const CATEGORY = "content.category";
|
|
3
|
+
export declare const categories: import("@composable-os/sdk").ToolSpec<z.ZodObject<{
|
|
4
|
+
limit: z.ZodDefault<z.ZodNumber>;
|
|
5
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
6
|
+
categories: z.ZodArray<z.ZodObject<{
|
|
7
|
+
id: z.ZodString;
|
|
8
|
+
name: z.ZodNullable<z.ZodString>;
|
|
9
|
+
slug: z.ZodNullable<z.ZodString>;
|
|
10
|
+
}, z.core.$strip>>;
|
|
11
|
+
}, z.core.$strip>>;
|
package/dist/tools.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// The Content pack's tools (stage 28, step 6). Posts need none: the public reads them with the
|
|
2
|
+
// host's `content.get` and `content.list`, which serve published versions only. This one lists
|
|
3
|
+
// the categories for a site's menu, through `public.list`, so the seam decides what is shown.
|
|
4
|
+
import { defineTool, z } from "@composable-os/sdk";
|
|
5
|
+
export const CATEGORY = "content.category";
|
|
6
|
+
const text = (value) => (typeof value === "string" ? value : null);
|
|
7
|
+
export const categories = defineTool({
|
|
8
|
+
description: "Every category of posts, by name: its id, name and address (slug), for a site's menu or " +
|
|
9
|
+
"a post's label. Read-only.",
|
|
10
|
+
input: z.object({ limit: z.number().int().min(1).max(200).default(100) }),
|
|
11
|
+
output: z.object({
|
|
12
|
+
categories: z.array(z.object({ id: z.string(), name: z.string().nullable(), slug: z.string().nullable() })),
|
|
13
|
+
}),
|
|
14
|
+
risk: "read",
|
|
15
|
+
audiences: ["staff", "customer", "public"],
|
|
16
|
+
async handler(input, ctx) {
|
|
17
|
+
const page = await ctx.ops.call("public.list", {
|
|
18
|
+
object: CATEGORY,
|
|
19
|
+
sort: { field: "name", direction: "asc" },
|
|
20
|
+
limit: input.limit,
|
|
21
|
+
});
|
|
22
|
+
return {
|
|
23
|
+
categories: page.items.map((item) => ({
|
|
24
|
+
id: item.id,
|
|
25
|
+
name: text(item.values.name),
|
|
26
|
+
slug: text(item.values.slug),
|
|
27
|
+
})),
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@composable-os/pack-content",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0-beta.8",
|
|
4
|
+
"license": "FSL-1.1-ALv2",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/timoconnellaus/composable-os.git"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://composableos.dev",
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public",
|
|
13
|
+
"provenance": true
|
|
14
|
+
},
|
|
15
|
+
"description": "Content: blog posts and categories, written by staff, published by a person, read by the public as structured rich text on the web and in the app (stage 28). Installed in every deployment of a product that lists it. Bundled as source into cos-runner.",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"default": "./dist/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./client": {
|
|
22
|
+
"types": "./dist/client/index.d.ts",
|
|
23
|
+
"default": "./dist/client/index.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"composableOs": {
|
|
30
|
+
"optional": true,
|
|
31
|
+
"label": "Content",
|
|
32
|
+
"description": "Blog posts staff write, schedule and publish, read by the public on your site and in your app."
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@composable-os/client": "0.1.0-beta.8",
|
|
36
|
+
"@composable-os/sdk": "0.1.0-beta.8"
|
|
37
|
+
}
|
|
38
|
+
}
|
package/README.md
DELETED