@bieberkit/plugin-pages 0.0.1 → 0.6.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/CHANGELOG.md ADDED
@@ -0,0 +1,70 @@
1
+ <!--
2
+ BieberKit
3
+
4
+ @file plugins/pages/CHANGELOG.md
5
+ @description Release history generated from changesets for @bieberkit/plugin-pages.
6
+ @author Bieber Kieu <kieutrongthien@gmail.com>
7
+ @generated pnpm changeset version (license header normalized)
8
+ @copyright Copyright (c) 2026 Bieber Kieu
9
+ @license Apache-2.0
10
+
11
+ Licensed under the Apache License, Version 2.0 (the "License");
12
+ you may not use this file except in compliance with the License.
13
+ You may obtain a copy of the License at
14
+
15
+ http://www.apache.org/licenses/LICENSE-2.0
16
+
17
+ Unless required by applicable law or agreed to in writing, software
18
+ distributed under the License is distributed on an "AS IS" BASIS,
19
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
+ See the License for the specific language governing permissions and
21
+ limitations under the License.
22
+
23
+ SPDX-License-Identifier: Apache-2.0
24
+ -->
25
+
26
+ # @bieberkit/plugin-pages
27
+
28
+ ## 0.6.0
29
+
30
+ ### Minor Changes
31
+
32
+ - f8dcdec: Add `--template cms` with localized pages and articles, categories, tags, menus, SEO, redirects and a public theme. The public site is enabled by default. Use `--no-site` for an API and admin project.
33
+
34
+ After creating a CMS project, run `pnpm exec bieberkit migrate:make`, `pnpm exec bieberkit migrate` and `pnpm exec bieberkit db:seed` to publish the starter homepage and article and add the main menu. Rerunning the seed preserves existing editorial content.
35
+
36
+ - f8dcdec: Register plugin content blocks through `definePlugin` using the types from `@bieberkit/content/plugin`. Use the plugin's short name as the block namespace and export the same `blocks` from a browser-safe `./content` package entry. The server validates publication writes and exposes framework-free HTML rendering through `services.content`.
37
+
38
+ New projects wire the portable blocks into admin previews and server rendering. To use plugin blocks in an existing project, add `bieberkitContent()` from `bieberkit/content-vite` to its admin and site Vite configs. Copy the `virtual:bieberkit/content-blocks` type declaration from the new scaffold, then import `blocks` and pass it as `contentBlocks` to `startAdmin` and as `blocks` to the site's `createContent`.
39
+
40
+ - 41d3311: Publish localized pages and articles from the admin. Draft changes stay private until published, and a signed preview link can open a draft. New site projects include publication snapshots, distinct localized slugs, permanent redirects on renames and per-type sitemap listings.
41
+
42
+ - 531fba5: Stream the article shell before related articles and public comments are ready. Publication editors can manage comments for an article locale, and generated articles load no Start client bundle when they have no interactive features.
43
+
44
+ ### Patch Changes
45
+
46
+ - Updated dependencies [b87af44]
47
+ - Updated dependencies [2b2bd1c]
48
+ - Updated dependencies [b27ba2d]
49
+ - Updated dependencies [d69343e]
50
+ - Updated dependencies [f8dcdec]
51
+ - Updated dependencies [4958f26]
52
+ - Updated dependencies [6bf1a53]
53
+ - Updated dependencies [594f5db]
54
+ - Updated dependencies [41d3311]
55
+ - Updated dependencies [d45cc96]
56
+ - Updated dependencies [ab624de]
57
+ - Updated dependencies [f1811d7]
58
+ - Updated dependencies [a9ecbb2]
59
+ - Updated dependencies [dc55f67]
60
+ - Updated dependencies [fd7800b]
61
+ - Updated dependencies [9ee9a18]
62
+ - Updated dependencies [8b309a4]
63
+ - @bieberkit/admin-antd@0.6.0
64
+ - @bieberkit/admin-core@0.6.0
65
+ - @bieberkit/content@0.6.0
66
+ - @bieberkit/http@0.6.0
67
+ - @bieberkit/core@0.6.0
68
+ - @bieberkit/plugin-redirects@0.6.0
69
+ - @bieberkit/site-kit@0.6.0
70
+ - @bieberkit/data@0.6.0
package/README.md CHANGED
@@ -1,3 +1,31 @@
1
- # @bieberkit/plugin-pages
1
+ <!--
2
+ BieberKit
2
3
 
3
- Reserved for the first BieberKit release of this package. The release will be available under `beta`.
4
+ @file plugins/pages/README.md
5
+ @description Explains how to publish localized pages and articles.
6
+ @author Bieber Kieu <kieutrongthien@gmail.com>
7
+ @copyright Copyright (c) 2026 Bieber Kieu
8
+ @license Apache-2.0
9
+
10
+ Licensed under the Apache License, Version 2.0 (the "License");
11
+ you may not use this file except in compliance with the License.
12
+ You may obtain a copy of the License at
13
+
14
+ http://www.apache.org/licenses/LICENSE-2.0
15
+
16
+ Unless required by applicable law or agreed to in writing, software
17
+ distributed under the License is distributed on an "AS IS" BASIS,
18
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ See the License for the specific language governing permissions and
20
+ limitations under the License.
21
+
22
+ SPDX-License-Identifier: Apache-2.0
23
+ -->
24
+
25
+ # Localized pages and articles
26
+
27
+ Use **Publications** in the admin to create a page or article, load a locale and save its draft. Publish the draft when its content is ready. A draft can be opened on the public site with its private preview link.
28
+
29
+ Leaving the slug empty derives it from the title. Publishing assigns a distinct slug in each locale, and a change to a published slug creates a permanent redirect from the former path. Use `home` as the slug of a locale homepage.
30
+
31
+ New projects made with `--site` include the pages and redirects plugins. The pages plugin contributes published content, language links and separate sitemap listings for pages and articles. See ADR 0053.
@@ -0,0 +1,185 @@
1
+ import { articleCommentsKey, draftsApi, publicationsKey } from "../lib/publications.js";
2
+ import { PublicComments } from "./PublicComments.js";
3
+ import { useAdminClient, useCan, useText } from "@bieberkit/admin-antd";
4
+ import { useMutation, useQueryClient } from "@tanstack/react-query";
5
+ import { Alert, Button, Form, Input, Skeleton, Space } from "antd";
6
+ import { Suspense, lazy, useState } from "react";
7
+ import { jsx, jsxs } from "react/jsx-runtime";
8
+ // src/admin/components/DraftForm.tsx
9
+ /**
10
+ * BieberKit
11
+ *
12
+ * @file plugins/pages/src/admin/components/DraftForm.tsx
13
+ * @description Edits, previews and publishes a localized draft.
14
+ * @author Bieber Kieu <kieutrongthien@gmail.com>
15
+ * @copyright Copyright (c) 2026 Bieber Kieu
16
+ * @license Apache-2.0
17
+ *
18
+ * Licensed under the Apache License, Version 2.0 (the "License");
19
+ * you may not use this file except in compliance with the License.
20
+ * You may obtain a copy of the License at
21
+ *
22
+ * http://www.apache.org/licenses/LICENSE-2.0
23
+ *
24
+ * Unless required by applicable law or agreed to in writing, software
25
+ * distributed under the License is distributed on an "AS IS" BASIS,
26
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27
+ * See the License for the specific language governing permissions and
28
+ * limitations under the License.
29
+ *
30
+ * SPDX-License-Identifier: Apache-2.0
31
+ */
32
+ const Editor = lazy(async () => ({ default: (await import("@bieberkit/admin-antd/content-editor")).ContentEditor }));
33
+ const EMPTY = {
34
+ version: 1,
35
+ blocks: []
36
+ };
37
+ function DraftForm({ id, locale, initial, article }) {
38
+ const text = useText();
39
+ const client = useAdminClient();
40
+ const cache = useQueryClient();
41
+ const canSave = useCan("pages.manage");
42
+ const canPublish = useCan("pages.publish");
43
+ const api = draftsApi(client, id, locale);
44
+ const [form] = Form.useForm();
45
+ const [saved, setSaved] = useState(initial);
46
+ const [document, setDocument] = useState(initial?.document ?? EMPTY);
47
+ const [dirty, setDirty] = useState(false);
48
+ const [preview, setPreview] = useState();
49
+ const [message, setMessage] = useState();
50
+ const reset = (draft) => {
51
+ form.setFieldsValue({
52
+ title: draft?.title ?? "",
53
+ slug: draft?.slug ?? "",
54
+ excerpt: draft?.excerpt ?? ""
55
+ });
56
+ setDocument(draft?.document ?? EMPTY);
57
+ setDirty(false);
58
+ setPreview(void 0);
59
+ };
60
+ const save = useMutation({
61
+ mutationFn: (fields) => api.save({
62
+ title: fields.title,
63
+ document,
64
+ ...fields.slug?.trim() ? { slug: fields.slug } : {},
65
+ ...fields.excerpt?.trim() ? { excerpt: fields.excerpt } : {}
66
+ }),
67
+ onSuccess: async (draft) => {
68
+ if (draft === void 0) return;
69
+ setSaved(draft);
70
+ reset(draft);
71
+ setMessage(text("pages.saved"));
72
+ await cache.invalidateQueries({ queryKey: publicationsKey });
73
+ }
74
+ });
75
+ const publish = useMutation({
76
+ mutationFn: () => api.publish(),
77
+ onSuccess: async () => {
78
+ setMessage(text("pages.published"));
79
+ if (article) await cache.invalidateQueries({ queryKey: articleCommentsKey(id, locale) });
80
+ }
81
+ });
82
+ const openPreview = useMutation({
83
+ mutationFn: () => api.preview(),
84
+ onSuccess: setPreview
85
+ });
86
+ const pending = save.isPending || publish.isPending || openPreview.isPending;
87
+ const error = save.error ?? publish.error ?? openPreview.error;
88
+ const changed = () => {
89
+ setDirty(true);
90
+ setMessage(void 0);
91
+ setPreview(void 0);
92
+ };
93
+ return /* @__PURE__ */ jsxs(Space, {
94
+ orientation: "vertical",
95
+ style: { width: "100%" },
96
+ children: [
97
+ error && /* @__PURE__ */ jsx(Alert, {
98
+ title: error.message,
99
+ type: "error",
100
+ showIcon: true
101
+ }),
102
+ /* @__PURE__ */ jsxs(Form, {
103
+ layout: "vertical",
104
+ form,
105
+ initialValues: initial ?? { title: "" },
106
+ disabled: pending || !canSave,
107
+ onValuesChange: changed,
108
+ onFinish: (fields) => save.mutate(fields),
109
+ children: [
110
+ /* @__PURE__ */ jsx(Form.Item, {
111
+ name: "title",
112
+ label: text("pages.name"),
113
+ rules: [{ required: true }],
114
+ children: /* @__PURE__ */ jsx(Input, { maxLength: 240 })
115
+ }),
116
+ /* @__PURE__ */ jsx(Form.Item, {
117
+ name: "slug",
118
+ label: text("pages.slug"),
119
+ children: /* @__PURE__ */ jsx(Input, { maxLength: 120 })
120
+ }),
121
+ /* @__PURE__ */ jsx(Form.Item, {
122
+ name: "excerpt",
123
+ label: text("pages.excerpt"),
124
+ children: /* @__PURE__ */ jsx(Input.TextArea, {
125
+ maxLength: 1e3,
126
+ rows: 2
127
+ })
128
+ }),
129
+ /* @__PURE__ */ jsx(Suspense, {
130
+ fallback: /* @__PURE__ */ jsx(Skeleton, { active: true }),
131
+ children: /* @__PURE__ */ jsx(Editor, {
132
+ value: document,
133
+ label: text("pages.content"),
134
+ id: "site-publication-content",
135
+ onChange: canSave && !pending ? (value) => {
136
+ setDocument(value);
137
+ changed();
138
+ } : void 0
139
+ })
140
+ }),
141
+ canSave && /* @__PURE__ */ jsxs(Space, { children: [/* @__PURE__ */ jsx(Button, {
142
+ type: "primary",
143
+ htmlType: "submit",
144
+ loading: save.isPending,
145
+ children: text("pages.save")
146
+ }), /* @__PURE__ */ jsx(Button, {
147
+ disabled: !dirty,
148
+ onClick: () => reset(saved),
149
+ children: text("pages.discard")
150
+ })] })
151
+ ]
152
+ }),
153
+ /* @__PURE__ */ jsxs(Space, {
154
+ wrap: true,
155
+ children: [
156
+ canPublish && /* @__PURE__ */ jsx(Button, {
157
+ disabled: dirty || pending || saved === null,
158
+ onClick: () => publish.mutate(),
159
+ children: text("pages.publish")
160
+ }),
161
+ /* @__PURE__ */ jsx(Button, {
162
+ disabled: dirty || pending || saved === null,
163
+ onClick: () => openPreview.mutate(),
164
+ children: text("pages.preview")
165
+ }),
166
+ preview !== void 0 && /* @__PURE__ */ jsx("a", {
167
+ href: preview,
168
+ target: "_blank",
169
+ rel: "noreferrer",
170
+ children: text("pages.openPreview")
171
+ })
172
+ ]
173
+ }),
174
+ message !== void 0 && /* @__PURE__ */ jsx("p", {
175
+ role: "status",
176
+ children: message
177
+ }),
178
+ article && canPublish && /* @__PURE__ */ jsx(PublicComments, {
179
+ id,
180
+ locale
181
+ })
182
+ ]
183
+ });
184
+ }
185
+ export { DraftForm };
@@ -0,0 +1,109 @@
1
+ import { articleCommentsApi, articleCommentsKey } from "../lib/publications.js";
2
+ import { useAdminClient, useText } from "@bieberkit/admin-antd";
3
+ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
4
+ import { Alert, Button, Form, Input, Popconfirm, Skeleton, Space, Typography } from "antd";
5
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
6
+ // src/admin/components/PublicComments.tsx
7
+ /**
8
+ * BieberKit
9
+ *
10
+ * @file plugins/pages/src/admin/components/PublicComments.tsx
11
+ * @description Adds and removes explicitly public article comments.
12
+ * @author Bieber Kieu <kieutrongthien@gmail.com>
13
+ * @copyright Copyright (c) 2026 Bieber Kieu
14
+ * @license Apache-2.0
15
+ *
16
+ * Licensed under the Apache License, Version 2.0 (the "License");
17
+ * you may not use this file except in compliance with the License.
18
+ * You may obtain a copy of the License at
19
+ *
20
+ * http://www.apache.org/licenses/LICENSE-2.0
21
+ *
22
+ * Unless required by applicable law or agreed to in writing, software
23
+ * distributed under the License is distributed on an "AS IS" BASIS,
24
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25
+ * See the License for the specific language governing permissions and
26
+ * limitations under the License.
27
+ *
28
+ * SPDX-License-Identifier: Apache-2.0
29
+ */
30
+ function PublicComments({ id, locale }) {
31
+ const text = useText();
32
+ const client = useAdminClient();
33
+ const cache = useQueryClient();
34
+ const [form] = Form.useForm();
35
+ const api = articleCommentsApi(client, id, locale);
36
+ const queryKey = articleCommentsKey(id, locale);
37
+ const list = useQuery({
38
+ queryKey,
39
+ queryFn: api.get
40
+ });
41
+ const refresh = () => cache.invalidateQueries({ queryKey });
42
+ const save = useMutation({
43
+ mutationFn: api.save,
44
+ onSuccess: async () => {
45
+ form.resetFields();
46
+ await refresh();
47
+ }
48
+ });
49
+ const remove = useMutation({
50
+ mutationFn: api.remove,
51
+ onSuccess: refresh
52
+ });
53
+ const error = list.error ?? save.error ?? remove.error;
54
+ const busy = save.isPending || remove.isPending;
55
+ return /* @__PURE__ */ jsxs("section", { children: [
56
+ /* @__PURE__ */ jsx(Typography.Title, {
57
+ level: 2,
58
+ children: text("pages.comments")
59
+ }),
60
+ error && /* @__PURE__ */ jsx(Alert, {
61
+ type: "error",
62
+ title: error.message,
63
+ showIcon: true
64
+ }),
65
+ list.isPending && /* @__PURE__ */ jsx(Skeleton, { active: true }),
66
+ list.data === null && /* @__PURE__ */ jsx("p", { children: text("pages.commentsAfterPublish") }),
67
+ list.data != null && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs(Form, {
68
+ layout: "vertical",
69
+ form,
70
+ disabled: busy,
71
+ onFinish: (values) => save.mutate(values),
72
+ children: [
73
+ /* @__PURE__ */ jsx(Form.Item, {
74
+ name: "name",
75
+ label: text("pages.commentName"),
76
+ children: /* @__PURE__ */ jsx(Input, { maxLength: 80 })
77
+ }),
78
+ /* @__PURE__ */ jsx(Form.Item, {
79
+ name: "body",
80
+ label: text("pages.commentBody"),
81
+ rules: [{ required: true }],
82
+ children: /* @__PURE__ */ jsx(Input.TextArea, {
83
+ maxLength: 2e3,
84
+ rows: 2
85
+ })
86
+ }),
87
+ /* @__PURE__ */ jsx(Button, {
88
+ htmlType: "submit",
89
+ loading: save.isPending,
90
+ children: text("pages.commentAdd")
91
+ })
92
+ ]
93
+ }), list.data.length > 0 && /* @__PURE__ */ jsx("ul", { children: list.data.map((comment) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs(Space, { children: [
94
+ comment.name !== void 0 && /* @__PURE__ */ jsx("strong", { children: comment.name }),
95
+ /* @__PURE__ */ jsx("span", { children: comment.body }),
96
+ /* @__PURE__ */ jsx(Popconfirm, {
97
+ title: text("pages.commentConfirm"),
98
+ disabled: busy,
99
+ onConfirm: () => remove.mutate(comment.id),
100
+ children: /* @__PURE__ */ jsx(Button, {
101
+ danger: true,
102
+ disabled: busy,
103
+ children: text("pages.commentRemove")
104
+ })
105
+ })
106
+ ] }) }, comment.id)) })] })
107
+ ] });
108
+ }
109
+ export { PublicComments };
@@ -0,0 +1,85 @@
1
+ import { listPublications, publicationsKey } from "../lib/publications.js";
2
+ import { useAdminClient, useText } from "@bieberkit/admin-antd";
3
+ import { useQuery } from "@tanstack/react-query";
4
+ import { Alert, Pagination, Select, Space } from "antd";
5
+ import { useState } from "react";
6
+ import { jsx, jsxs } from "react/jsx-runtime";
7
+ // src/admin/components/PublicationPicker.tsx
8
+ /**
9
+ * BieberKit
10
+ *
11
+ * @file plugins/pages/src/admin/components/PublicationPicker.tsx
12
+ * @description Picks publication identities by title from the editorial list.
13
+ * @author Bieber Kieu <kieutrongthien@gmail.com>
14
+ * @copyright Copyright (c) 2026 Bieber Kieu
15
+ * @license Apache-2.0
16
+ *
17
+ * Licensed under the Apache License, Version 2.0 (the "License");
18
+ * you may not use this file except in compliance with the License.
19
+ * You may obtain a copy of the License at
20
+ *
21
+ * http://www.apache.org/licenses/LICENSE-2.0
22
+ *
23
+ * Unless required by applicable law or agreed to in writing, software
24
+ * distributed under the License is distributed on an "AS IS" BASIS,
25
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26
+ * See the License for the specific language governing permissions and
27
+ * limitations under the License.
28
+ *
29
+ * SPDX-License-Identifier: Apache-2.0
30
+ */
31
+ function PublicationPicker(props) {
32
+ const client = useAdminClient();
33
+ const text = useText();
34
+ const [page, setPage] = useState(1);
35
+ const [known, setKnown] = useState(props.initial);
36
+ const { value, onChange } = props;
37
+ const query = useQuery({
38
+ queryKey: [...publicationsKey, page],
39
+ queryFn: () => listPublications(client, page)
40
+ });
41
+ const rows = query.data?.data ?? [];
42
+ const choices = new Map([...known, ...rows].map((item) => [item.id, item]));
43
+ const options = [.../* @__PURE__ */ new Set([...value ?? [], ...rows.map(({ id }) => id)])].map((id) => {
44
+ const row = choices.get(id);
45
+ return {
46
+ value: id,
47
+ label: row === void 0 ? id : text("pages." + row.kind) + " · " + (row.title ?? text("pages.untitled"))
48
+ };
49
+ });
50
+ return /* @__PURE__ */ jsxs(Space, {
51
+ orientation: "vertical",
52
+ style: { width: "100%" },
53
+ children: [
54
+ query.error && /* @__PURE__ */ jsx(Alert, {
55
+ type: "error",
56
+ title: query.error.message,
57
+ showIcon: true
58
+ }),
59
+ /* @__PURE__ */ jsx(Select, {
60
+ ...props.id === void 0 ? {} : { id: props.id },
61
+ style: { width: "100%" },
62
+ mode: "multiple",
63
+ maxCount: 200,
64
+ showSearch: { optionFilterProp: "label" },
65
+ loading: query.isPending,
66
+ value: value ?? [],
67
+ options,
68
+ onChange: (ids) => {
69
+ setKnown(ids.flatMap((id) => choices.get(id) ?? []));
70
+ onChange?.(ids);
71
+ }
72
+ }),
73
+ /* @__PURE__ */ jsx(Pagination, {
74
+ size: "small",
75
+ current: page,
76
+ total: query.data?.total ?? 0,
77
+ pageSize: 50,
78
+ showSizeChanger: false,
79
+ hideOnSinglePage: true,
80
+ onChange: setPage
81
+ })
82
+ ]
83
+ });
84
+ }
85
+ export { PublicationPicker };
@@ -0,0 +1,27 @@
1
+ /**
2
+ * BieberKit
3
+ *
4
+ * @file plugins/pages/src/admin/index.ts
5
+ * @description Publishes the localized editor to the admin shell.
6
+ * @author Bieber Kieu <kieutrongthien@gmail.com>
7
+ * @copyright Copyright (c) 2026 Bieber Kieu
8
+ * @license Apache-2.0
9
+ *
10
+ * Licensed under the Apache License, Version 2.0 (the "License");
11
+ * you may not use this file except in compliance with the License.
12
+ * You may obtain a copy of the License at
13
+ *
14
+ * http://www.apache.org/licenses/LICENSE-2.0
15
+ *
16
+ * Unless required by applicable law or agreed to in writing, software
17
+ * distributed under the License is distributed on an "AS IS" BASIS,
18
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ * See the License for the specific language governing permissions and
20
+ * limitations under the License.
21
+ *
22
+ * SPDX-License-Identifier: Apache-2.0
23
+ */
24
+ import { TaxonomyAdminPart, taxonomyAdmin } from "./lib/taxonomy-part.js";
25
+ import { AdminPart, AdminView } from "@bieberkit/admin-core";
26
+ declare const part: AdminPart<AdminView>;
27
+ export { type TaxonomyAdminPart, part as default, taxonomyAdmin };
@@ -0,0 +1,46 @@
1
+ import { taxonomyAdmin } from "./lib/taxonomy-part.js";
2
+ import { defineAdminPlugin } from "@bieberkit/admin-core";
3
+ // src/admin/index.ts
4
+ /**
5
+ * BieberKit
6
+ *
7
+ * @file plugins/pages/src/admin/index.ts
8
+ * @description Publishes the localized editor to the admin shell.
9
+ * @author Bieber Kieu <kieutrongthien@gmail.com>
10
+ * @copyright Copyright (c) 2026 Bieber Kieu
11
+ * @license Apache-2.0
12
+ *
13
+ * Licensed under the Apache License, Version 2.0 (the "License");
14
+ * you may not use this file except in compliance with the License.
15
+ * You may obtain a copy of the License at
16
+ *
17
+ * http://www.apache.org/licenses/LICENSE-2.0
18
+ *
19
+ * Unless required by applicable law or agreed to in writing, software
20
+ * distributed under the License is distributed on an "AS IS" BASIS,
21
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
+ * See the License for the specific language governing permissions and
23
+ * limitations under the License.
24
+ *
25
+ * SPDX-License-Identifier: Apache-2.0
26
+ */
27
+ const part = defineAdminPlugin({
28
+ name: "@bieberkit/plugin-pages",
29
+ menu: [{
30
+ page: "/publications",
31
+ group: "content",
32
+ permission: "pages.read"
33
+ }],
34
+ pages: [{
35
+ path: "/publications",
36
+ title: "pages.title",
37
+ permission: "pages.read",
38
+ load: () => import("./pages/PublicationsPage.js")
39
+ }],
40
+ messages: {
41
+ en: async () => ({ default: (await import("./messages/en.js")).en }),
42
+ vi: async () => ({ default: (await import("./messages/vi.js")).vi }),
43
+ zh: async () => ({ default: (await import("./messages/zh.js")).zh })
44
+ }
45
+ });
46
+ export { part as default, taxonomyAdmin };
@@ -0,0 +1,133 @@
1
+ import { AdminApiError } from "@bieberkit/admin-core";
2
+ // src/admin/lib/publications.ts
3
+ /**
4
+ * BieberKit
5
+ *
6
+ * @file plugins/pages/src/admin/lib/publications.ts
7
+ * @description Reads and writes publications through the admin API.
8
+ * @author Bieber Kieu <kieutrongthien@gmail.com>
9
+ * @copyright Copyright (c) 2026 Bieber Kieu
10
+ * @license Apache-2.0
11
+ *
12
+ * Licensed under the Apache License, Version 2.0 (the "License");
13
+ * you may not use this file except in compliance with the License.
14
+ * You may obtain a copy of the License at
15
+ *
16
+ * http://www.apache.org/licenses/LICENSE-2.0
17
+ *
18
+ * Unless required by applicable law or agreed to in writing, software
19
+ * distributed under the License is distributed on an "AS IS" BASIS,
20
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
+ * See the License for the specific language governing permissions and
22
+ * limitations under the License.
23
+ *
24
+ * SPDX-License-Identifier: Apache-2.0
25
+ */
26
+ const API = "/api/v1/pages/publications";
27
+ const publicationsKey = ["site-publications"];
28
+ const valueOf = (input, key) => typeof input === "object" && input !== null ? Reflect.get(input, key) : void 0;
29
+ const textOf = (input) => typeof input === "string" ? input : void 0;
30
+ function readSummary(input) {
31
+ const id = textOf(valueOf(input, "id"));
32
+ const kind = valueOf(input, "kind");
33
+ const title = textOf(valueOf(input, "title"));
34
+ if (id === void 0 || kind !== "page" && kind !== "article") return void 0;
35
+ return title === void 0 ? {
36
+ id,
37
+ kind
38
+ } : {
39
+ id,
40
+ kind,
41
+ title
42
+ };
43
+ }
44
+ function readDraft(input) {
45
+ const title = textOf(valueOf(input, "title"));
46
+ if (title === void 0) return void 0;
47
+ const slug = textOf(valueOf(input, "slug"));
48
+ const excerpt = textOf(valueOf(input, "excerpt"));
49
+ return {
50
+ title,
51
+ document: valueOf(input, "document"),
52
+ ...slug === void 0 ? {} : { slug },
53
+ ...excerpt === void 0 ? {} : { excerpt }
54
+ };
55
+ }
56
+ async function listPublications(client, page) {
57
+ const result = await client.request("GET", API + "?page=" + String(page));
58
+ const items = valueOf(result, "data");
59
+ const total = valueOf(result, "total");
60
+ const data = Array.isArray(items) ? items.map(readSummary).filter((item) => item !== void 0) : [];
61
+ return {
62
+ data,
63
+ total: typeof total === "number" ? total : data.length
64
+ };
65
+ }
66
+ async function newPublication(client, kind) {
67
+ return textOf(valueOf(valueOf(await client.request("POST", API, { body: { kind } }), "data"), "id"));
68
+ }
69
+ function draftsApi(client, id, locale) {
70
+ const root = API + "/" + encodeURIComponent(id);
71
+ const language = encodeURIComponent(locale);
72
+ const draft = root + "/drafts/" + language;
73
+ return {
74
+ async get() {
75
+ try {
76
+ return readDraft(valueOf(await client.request("GET", draft), "data")) ?? null;
77
+ } catch (error) {
78
+ if (error instanceof AdminApiError && error.status === 404) return null;
79
+ throw error;
80
+ }
81
+ },
82
+ async save(body) {
83
+ return readDraft(valueOf(await client.request("PUT", draft, { body }), "data"));
84
+ },
85
+ async publish() {
86
+ return textOf(valueOf(valueOf(await client.request("POST", root + "/publish/" + language), "data"), "slug"));
87
+ },
88
+ async preview() {
89
+ const result = await client.request("POST", root + "/preview/" + language);
90
+ const address = textOf(valueOf(valueOf(result, "data"), "url"));
91
+ const url = address === void 0 ? null : URL.parse(address);
92
+ if (url?.protocol === "https:" || url?.protocol === "http:") return url.href;
93
+ }
94
+ };
95
+ }
96
+ function articleCommentsKey(id, locale) {
97
+ return [
98
+ ...publicationsKey,
99
+ "comments",
100
+ id,
101
+ locale
102
+ ];
103
+ }
104
+ function articleCommentsApi(client, id, locale) {
105
+ const url = API + "/" + encodeURIComponent(id) + "/comments/" + encodeURIComponent(locale);
106
+ return {
107
+ async get() {
108
+ try {
109
+ const items = valueOf(await client.request("GET", url), "data");
110
+ return Array.isArray(items) ? items.flatMap((item) => {
111
+ const key = textOf(valueOf(item, "id"));
112
+ const body = textOf(valueOf(item, "body"));
113
+ const name = textOf(valueOf(item, "name"));
114
+ if (key === void 0 || body === void 0) return [];
115
+ return [name === void 0 ? {
116
+ id: key,
117
+ body
118
+ } : {
119
+ id: key,
120
+ body,
121
+ name
122
+ }];
123
+ }) : [];
124
+ } catch (error) {
125
+ if (error instanceof AdminApiError && error.status === 404) return null;
126
+ throw error;
127
+ }
128
+ },
129
+ save: (body) => client.request("POST", url, { body }),
130
+ remove: (comment) => client.request("DELETE", url + "/" + encodeURIComponent(comment))
131
+ };
132
+ }
133
+ export { articleCommentsApi, articleCommentsKey, draftsApi, listPublications, newPublication, publicationsKey };