@brimsites/brimjs 0.0.0-stage → 1.0.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/LICENSE +110 -0
- package/README.md +22 -2
- package/bin/brim.js +5 -0
- package/dist/cli.js +3802 -0
- package/editor-dist/editor.css +1 -0
- package/editor-dist/editor.js +91 -0
- package/package.json +71 -3
- package/skills/brim-convert/SKILL.md +256 -0
- package/skills/brim-hosting/SKILL.md +221 -0
- package/src/astro-shim.d.ts +5 -0
- package/src/auth/accounts.ts +341 -0
- package/src/auth/password.ts +34 -0
- package/src/auth/permissions.ts +44 -0
- package/src/blocks/accordion/Accordion.astro +48 -0
- package/src/blocks/accordion/accordion.css +63 -0
- package/src/blocks/analytics/Analytics.astro +45 -0
- package/src/blocks/analytics/ConsentBanner.astro +41 -0
- package/src/blocks/analytics/analytics.client.ts +125 -0
- package/src/blocks/analytics/analytics.css +51 -0
- package/src/blocks/analytics/consent.ts +51 -0
- package/src/blocks/button/Button.astro +64 -0
- package/src/blocks/button/button.css +100 -0
- package/src/blocks/carousel/Carousel.astro +140 -0
- package/src/blocks/carousel/carousel.client.ts +153 -0
- package/src/blocks/carousel/carousel.css +181 -0
- package/src/blocks/data/icons.ts +285 -0
- package/src/blocks/data/image-shapes.ts +91 -0
- package/src/blocks/data/social-icons.ts +41 -0
- package/src/blocks/data/social-networks.ts +256 -0
- package/src/blocks/divider/Divider.astro +27 -0
- package/src/blocks/divider/divider.css +17 -0
- package/src/blocks/form/Captcha.astro +27 -0
- package/src/blocks/form/Form.astro +250 -0
- package/src/blocks/form/FormField.astro +138 -0
- package/src/blocks/form/Newsletter.astro +80 -0
- package/src/blocks/form/form.client.ts +339 -0
- package/src/blocks/form/form.css +271 -0
- package/src/blocks/gallery/ImageGallery.astro +126 -0
- package/src/blocks/gallery/gallery.css +43 -0
- package/src/blocks/gallery/lightbox.client.ts +178 -0
- package/src/blocks/gallery/lightbox.css +134 -0
- package/src/blocks/icon/Icon.astro +41 -0
- package/src/blocks/icon/icon.css +16 -0
- package/src/blocks/image/Image.astro +158 -0
- package/src/blocks/image/image.css +42 -0
- package/src/blocks/images.ts +64 -0
- package/src/blocks/in-editor.client.ts +8 -0
- package/src/blocks/listing/Listing.astro +288 -0
- package/src/blocks/listing/ListingCards.astro +48 -0
- package/src/blocks/listing/listing.css +136 -0
- package/src/blocks/listing/query.ts +363 -0
- package/src/blocks/map/Map.astro +75 -0
- package/src/blocks/map/map.css +32 -0
- package/src/blocks/schemas/accordion.ts +118 -0
- package/src/blocks/schemas/button.ts +78 -0
- package/src/blocks/schemas/carousel.ts +133 -0
- package/src/blocks/schemas/divider.ts +29 -0
- package/src/blocks/schemas/form-field-types.ts +29 -0
- package/src/blocks/schemas/form.ts +350 -0
- package/src/blocks/schemas/icon.ts +24 -0
- package/src/blocks/schemas/image-gallery.ts +54 -0
- package/src/blocks/schemas/image.ts +87 -0
- package/src/blocks/schemas/index.ts +33 -0
- package/src/blocks/schemas/listing.ts +14 -0
- package/src/blocks/schemas/map.ts +81 -0
- package/src/blocks/schemas/newsletter.ts +324 -0
- package/src/blocks/schemas/social-media.ts +348 -0
- package/src/blocks/schemas/text.ts +151 -0
- package/src/blocks/schemas/video.ts +57 -0
- package/src/blocks/search/Search.astro +147 -0
- package/src/blocks/search/search.css +69 -0
- package/src/blocks/search/state.ts +28 -0
- package/src/blocks/settings.ts +94 -0
- package/src/blocks/social/SocialMedia.astro +102 -0
- package/src/blocks/social/social-links.ts +16 -0
- package/src/blocks/social/social.css +31 -0
- package/src/blocks/theme.ts +35 -0
- package/src/blocks/types.ts +52 -0
- package/src/blocks/video/Video.astro +90 -0
- package/src/blocks/video/video-source.ts +77 -0
- package/src/blocks/video/video.client.ts +43 -0
- package/src/blocks/video/video.css +29 -0
- package/src/check.ts +1119 -0
- package/src/cli.ts +493 -0
- package/src/components/Blocks.astro +68 -0
- package/src/components/Field.astro +61 -0
- package/src/components/Footer.astro +36 -0
- package/src/components/Link.astro +18 -0
- package/src/components/MobileMenu.astro +77 -0
- package/src/components/Navbar.astro +42 -0
- package/src/components/RichText.astro +32 -0
- package/src/components/Seo.astro +202 -0
- package/src/components/Setting.astro +46 -0
- package/src/components/Shared.astro +17 -0
- package/src/components/Text.astro +91 -0
- package/src/components/blocks.css +86 -0
- package/src/components/index.ts +27 -0
- package/src/components/mobile-menu.client.ts +21 -0
- package/src/components/mobile-menu.css +52 -0
- package/src/components/text.css +48 -0
- package/src/config.ts +413 -0
- package/src/content/block-layout.ts +63 -0
- package/src/content/block-values.ts +48 -0
- package/src/content/content-check.ts +174 -0
- package/src/content/content-types.ts +408 -0
- package/src/content/drafts.ts +115 -0
- package/src/content/feed.ts +237 -0
- package/src/content/field-types.ts +107 -0
- package/src/content/history.ts +140 -0
- package/src/content/ids.ts +50 -0
- package/src/content/image-size.ts +212 -0
- package/src/content/image-sizes.ts +126 -0
- package/src/content/item-fields.ts +110 -0
- package/src/content/item-head.ts +126 -0
- package/src/content/item-image.ts +26 -0
- package/src/content/item-path.ts +122 -0
- package/src/content/items.ts +580 -0
- package/src/content/language-scopes.ts +40 -0
- package/src/content/media.ts +271 -0
- package/src/content/menus.ts +51 -0
- package/src/content/page-templates.ts +52 -0
- package/src/content/redirects.ts +112 -0
- package/src/content/references.ts +165 -0
- package/src/content/rich-text.ts +63 -0
- package/src/content/search.ts +167 -0
- package/src/content/seed.ts +229 -0
- package/src/content/site-settings.ts +111 -0
- package/src/content/sitemap.ts +143 -0
- package/src/content/store.ts +225 -0
- package/src/content/tags.ts +67 -0
- package/src/content/text-default.ts +139 -0
- package/src/content/types.ts +137 -0
- package/src/content/validate.ts +253 -0
- package/src/content/validation-error.ts +2 -0
- package/src/db/cached.ts +140 -0
- package/src/db/database.ts +15 -0
- package/src/db/libsql.ts +29 -0
- package/src/db/schema.ts +189 -0
- package/src/db/url.ts +44 -0
- package/src/editor/client/BlockSettings.tsx +1063 -0
- package/src/editor/client/Chrome.tsx +284 -0
- package/src/editor/client/ContentBrowser.tsx +1299 -0
- package/src/editor/client/Editor.tsx +1756 -0
- package/src/editor/client/HistoryPanel.tsx +114 -0
- package/src/editor/client/ImagesWidget.tsx +113 -0
- package/src/editor/client/Inspector.tsx +127 -0
- package/src/editor/client/ItemForm.tsx +535 -0
- package/src/editor/client/LinkWidget.tsx +440 -0
- package/src/editor/client/ListingPanel.tsx +99 -0
- package/src/editor/client/Login.tsx +338 -0
- package/src/editor/client/Menu.tsx +64 -0
- package/src/editor/client/PageSettings.tsx +270 -0
- package/src/editor/client/RedirectsSettings.tsx +130 -0
- package/src/editor/client/Resize.tsx +204 -0
- package/src/editor/client/Sidebar.tsx +51 -0
- package/src/editor/client/SiteMap.tsx +568 -0
- package/src/editor/client/SiteSettings.tsx +409 -0
- package/src/editor/client/TextTools.tsx +391 -0
- package/src/editor/client/Toolbar.tsx +449 -0
- package/src/editor/client/VideoUpload.tsx +251 -0
- package/src/editor/client/api.ts +417 -0
- package/src/editor/client/brand.ts +20 -0
- package/src/editor/client/connection.ts +98 -0
- package/src/editor/client/context.ts +19 -0
- package/src/editor/client/css.d.ts +2 -0
- package/src/editor/client/editor.css +4656 -0
- package/src/editor/client/fields.tsx +812 -0
- package/src/editor/client/icons.tsx +174 -0
- package/src/editor/client/keys.ts +15 -0
- package/src/editor/client/kinds.ts +289 -0
- package/src/editor/client/languages.ts +32 -0
- package/src/editor/client/main.tsx +100 -0
- package/src/editor/client/responses.ts +26 -0
- package/src/editor/client/rich-text.ts +326 -0
- package/src/editor/client/site-tree.ts +239 -0
- package/src/editor/client/theme.ts +55 -0
- package/src/editor/client/tsconfig.json +18 -0
- package/src/editor/client/tus.ts +137 -0
- package/src/editor/client/use-rect.ts +50 -0
- package/src/editor/client/widgets.tsx +1218 -0
- package/src/forms/captcha.ts +83 -0
- package/src/forms/define.ts +166 -0
- package/src/forms/fields.ts +197 -0
- package/src/forms/file-types.ts +108 -0
- package/src/forms/files.ts +216 -0
- package/src/forms/form-page.ts +9 -0
- package/src/forms/handler.ts +622 -0
- package/src/forms/spec.ts +89 -0
- package/src/forms/store.ts +96 -0
- package/src/forms/work.ts +50 -0
- package/src/icons/library.ts +144 -0
- package/src/icons/load.ts +63 -0
- package/src/index.ts +99 -0
- package/src/init.ts +257 -0
- package/src/integration.ts +469 -0
- package/src/mail/mailer.ts +197 -0
- package/src/mail/notify.ts +272 -0
- package/src/mail/settings.ts +173 -0
- package/src/mail/templates.ts +191 -0
- package/src/mcp/page-nodes.ts +209 -0
- package/src/mcp/server.ts +111 -0
- package/src/mcp/tools.ts +637 -0
- package/src/runtime/TemplatePage.astro +39 -0
- package/src/runtime/TemplatePageStatic.astro +13 -0
- package/src/runtime/admin-route.ts +80 -0
- package/src/runtime/connect.ts +53 -0
- package/src/runtime/content.ts +188 -0
- package/src/runtime/context.ts +131 -0
- package/src/runtime/form-files.ts +18 -0
- package/src/runtime/forms-route.ts +33 -0
- package/src/runtime/forms.ts +28 -0
- package/src/runtime/icons.ts +5 -0
- package/src/runtime/media.ts +175 -0
- package/src/runtime/middleware.ts +186 -0
- package/src/runtime/nav.ts +13 -0
- package/src/runtime/query-reads.ts +49 -0
- package/src/runtime/query-store.ts +16 -0
- package/src/runtime/request-state.ts +69 -0
- package/src/runtime/robots.ts +29 -0
- package/src/runtime/rss-static.ts +16 -0
- package/src/runtime/rss.ts +29 -0
- package/src/runtime/server.ts +29 -0
- package/src/runtime/sitemap.ts +34 -0
- package/src/runtime/template-paths.ts +34 -0
- package/src/runtime/uploads-route.ts +13 -0
- package/src/seed-cli.ts +253 -0
- package/src/server/auth.ts +31 -0
- package/src/server/fetch-image.ts +219 -0
- package/src/server/handler.ts +2106 -0
- package/src/server/http.ts +162 -0
- package/src/server/locales.ts +73 -0
- package/src/server/node.ts +57 -0
- package/src/server/query-params.ts +249 -0
- package/src/server/rate-limit.ts +72 -0
- package/src/server/video-host.ts +162 -0
- package/src/starter.ts +70 -0
- package/src/version.ts +4 -0
- package/src/virtual.d.ts +65 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { type ContentType, standardField } from "./content-types.ts";
|
|
2
|
+
import { itemDescription } from "./item-head.ts";
|
|
3
|
+
import { itemImage } from "./item-image.ts";
|
|
4
|
+
import type { ItemStore } from "./items.ts";
|
|
5
|
+
import { referenceFields, referencesTo } from "./references.ts";
|
|
6
|
+
import { routeDrawsItems } from "./sitemap.ts";
|
|
7
|
+
import type { StoredNode } from "./types.ts";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* `brim check --content`: what the site's content still gets wrong, read from the database rather than the code.
|
|
11
|
+
* Values left from testing or a template (lorem ipsum, example.com, +40 000 000 000), terms of a vocabulary that
|
|
12
|
+
* nothing uses (a category page with no products), dynamic pages the sitemap cannot list, and items search engines
|
|
13
|
+
* and shared links would be told too little of. Warnings only: the
|
|
14
|
+
* owner decides, and some of them are on purpose.
|
|
15
|
+
*/
|
|
16
|
+
export interface ContentFinding {
|
|
17
|
+
rule: "placeholder" | "empty-term" | "unlisted-pages" | "search-fields" | "search-empty";
|
|
18
|
+
/** Where, in words a person finds it by: `product/marazzi-art → summary`, `site settings → whatsapp`, `/despre`. */
|
|
19
|
+
where: string;
|
|
20
|
+
message: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface Sources {
|
|
24
|
+
contentTypes: ContentType[];
|
|
25
|
+
items: ItemStore;
|
|
26
|
+
/** Every saved node: texts, links and images of the pages, the site's shared content. */
|
|
27
|
+
nodes: StoredNode[];
|
|
28
|
+
/** The site's own settings as the site shows them (saved values over the code's defaults), per language. */
|
|
29
|
+
settings: { locale: string; values: Record<string, unknown> }[];
|
|
30
|
+
/** Patterns of the dynamic routes written in src/pages, e.g. `/produse/[category]`. */
|
|
31
|
+
patterns: string[];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Text that is still a stand-in, with what to say about it. Each is meant to be rare in real content. */
|
|
35
|
+
const PLACEHOLDERS: { pattern: RegExp; what: string }[] = [
|
|
36
|
+
{ pattern: /\blorem ipsum\b|\bdolor sit amet\b/i, what: "lorem ipsum" },
|
|
37
|
+
{
|
|
38
|
+
pattern:
|
|
39
|
+
/\b(?:[\w.+-]+@)?(?:[\w-]+\.)*(?:example\.(?:com|org|net)|test\.com|domain\.com|yourdomain\.\w+|yoursite\.\w+)\b/i,
|
|
40
|
+
what: "an example address",
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
pattern: /\b[\w.+-]+@[\w-]+\.(?:demo|test|invalid|example|local)\b|\bhttps?:\/\/[\w.-]+\.(?:demo|test|invalid)\b/i,
|
|
44
|
+
what: "a test address",
|
|
45
|
+
},
|
|
46
|
+
// A phone number of one digit repeated (+40 000 000 000, 0700 000 000) or counting up (123456789).
|
|
47
|
+
{ pattern: /(?:\+?\d[\s.-]?)?(\d)(?:[\s.-]?\1){6,}|123[\s.-]?456[\s.-]?789/, what: "a stand-in number" },
|
|
48
|
+
{ pattern: /\b(?:TODO|FIXME|TBD)\b|\bXXX\b/, what: "a note left to fill in" },
|
|
49
|
+
{ pattern: /\bplaceholder\b|\bsample text\b|\byour (?:company|business) name\b/i, what: "a stand-in" },
|
|
50
|
+
];
|
|
51
|
+
|
|
52
|
+
/** What in a text looks like a stand-in, if anything. */
|
|
53
|
+
export function placeholderIn(text: string): string | undefined {
|
|
54
|
+
for (const { pattern, what } of PLACEHOLDERS) {
|
|
55
|
+
const match = pattern.exec(text);
|
|
56
|
+
if (match) return `${what} ("${match[0].trim().slice(0, 60)}")`;
|
|
57
|
+
}
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Every text in a value with where it is: `summary`, `gallery[2].alt`, `specs[0].value`. */
|
|
62
|
+
function texts(value: unknown, path: string, found: { path: string; text: string }[] = []) {
|
|
63
|
+
if (typeof value === "string") found.push({ path, text: value });
|
|
64
|
+
else if (Array.isArray(value)) value.forEach((entry, index) => texts(entry, `${path}[${index}]`, found));
|
|
65
|
+
else if (typeof value === "object" && value !== null) {
|
|
66
|
+
for (const [key, entry] of Object.entries(value)) texts(entry, path ? `${path}.${key}` : key, found);
|
|
67
|
+
}
|
|
68
|
+
return found;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export async function checkContent({
|
|
72
|
+
contentTypes,
|
|
73
|
+
items,
|
|
74
|
+
nodes,
|
|
75
|
+
settings,
|
|
76
|
+
patterns,
|
|
77
|
+
}: Sources): Promise<ContentFinding[]> {
|
|
78
|
+
const findings: ContentFinding[] = [];
|
|
79
|
+
const flag = (where: string, text: string) => {
|
|
80
|
+
const what = placeholderIn(text);
|
|
81
|
+
if (what) findings.push({ rule: "placeholder", where, message: `${what}: replace it with the real value` });
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
for (const type of contentTypes) {
|
|
85
|
+
for (const item of await items.list(type.key)) {
|
|
86
|
+
const name = `${type.key}/${item.slug}${item.locale ? ` (${item.locale})` : ""}`;
|
|
87
|
+
flag(`${name} → title`, item.title);
|
|
88
|
+
for (const { path, text } of texts(item.data, "")) flag(`${name} → ${path}`, text);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
for (const { locale, values } of settings) {
|
|
92
|
+
for (const { path, text } of texts(values, "")) {
|
|
93
|
+
flag(`site settings${locale ? ` (${locale})` : ""} → ${path}`, text);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
for (const node of nodes) {
|
|
97
|
+
// The site settings were read above, with their defaults; the rest are the pages' own texts and links.
|
|
98
|
+
if (node.nodeId === "site-settings") continue;
|
|
99
|
+
for (const { path, text } of texts(node.value, "")) {
|
|
100
|
+
flag(`${node.scope} → ${node.nodeId}${path ? `.${path}` : ""}`, text);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
for (const type of contentTypes.filter((candidate) => candidate.component)) findings.push(...searchFields(type));
|
|
105
|
+
for (const type of contentTypes.filter((candidate) => candidate.component && !candidate.vocabulary)) {
|
|
106
|
+
for (const item of await items.list(type.key, { publishedOnly: true })) {
|
|
107
|
+
const missing = [
|
|
108
|
+
...(standardField(type, "description") && !itemDescription(type, item) ? ["description"] : []),
|
|
109
|
+
...(standardField(type, "image") && !itemImage(type, item) ? ["image"] : []),
|
|
110
|
+
...(type.article && standardField(type, "published") && !item.data.published ? ["published date"] : []),
|
|
111
|
+
];
|
|
112
|
+
if (missing.length === 0) continue;
|
|
113
|
+
findings.push({
|
|
114
|
+
rule: "search-empty",
|
|
115
|
+
where: `${type.key}/${item.slug}${item.locale ? ` (${item.locale})` : ""}`,
|
|
116
|
+
message: `has no ${missing.join(" and no ")} for search engines and shared links`,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Terms of a vocabulary something points at, which nothing uses yet.
|
|
122
|
+
const used = new Set(contentTypes.flatMap((type) => referenceFields(type).map((field) => field.to)));
|
|
123
|
+
for (const vocabulary of contentTypes.filter((type) => type.vocabulary && used.has(type.key))) {
|
|
124
|
+
for (const term of await items.list(vocabulary.key, { locale: "" })) {
|
|
125
|
+
if ((await referencesTo(contentTypes, items, term)).length > 0) continue;
|
|
126
|
+
findings.push({
|
|
127
|
+
rule: "empty-term",
|
|
128
|
+
where: `${vocabulary.key}/${term.slug}`,
|
|
129
|
+
message:
|
|
130
|
+
`"${term.title}" is used by nothing yet` +
|
|
131
|
+
(vocabulary.component ? ": its page lists nothing. Add items to it, or hide or delete it" : ""),
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Dynamic routes the content types do not draw: only the route knows their addresses.
|
|
137
|
+
for (const pattern of patterns) {
|
|
138
|
+
// Catch-all routes, the editor, and the framework's own routes (`/_server-islands/…`, `/_image`) are not pages.
|
|
139
|
+
if (/\[\.\.\.|^\/(?:admin|_)/.test(pattern) || routeDrawsItems(contentTypes, pattern)) continue;
|
|
140
|
+
findings.push({
|
|
141
|
+
rule: "unlisted-pages",
|
|
142
|
+
where: pattern,
|
|
143
|
+
message:
|
|
144
|
+
"these pages are not in the sitemap: Brim cannot know their addresses. Make what they show items of a " +
|
|
145
|
+
"content type with this path (or a vocabulary with pages), whose pages Brim lists",
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
return findings;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** Fields of a type with pages that search engines will not be given, though they look meant for them. */
|
|
152
|
+
function searchFields(type: ContentType): ContentFinding[] {
|
|
153
|
+
const found: ContentFinding[] = [];
|
|
154
|
+
for (const { name } of type.fields) {
|
|
155
|
+
if (/^(?:seo|meta|og)_/.test(name)) {
|
|
156
|
+
found.push({
|
|
157
|
+
rule: "search-fields",
|
|
158
|
+
where: `${type.key} → ${name}`,
|
|
159
|
+
message:
|
|
160
|
+
"every page has its own SEO title, description and preview image (Page Settings): move its values there, then remove this field",
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
for (const name of ["description", "image", "published", "modified", "author"] as const) {
|
|
165
|
+
const field = type.fields.find((candidate) => candidate.name === name);
|
|
166
|
+
if (!field || standardField(type, name)) continue;
|
|
167
|
+
found.push({
|
|
168
|
+
rule: "search-fields",
|
|
169
|
+
where: `${type.key} → ${name}`,
|
|
170
|
+
message: `a ${field.type} field cannot be the item's ${name} for search engines: rename it, or change its type`,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
return found;
|
|
174
|
+
}
|
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
import { type LocaleConfig, readItemPath } from "../server/locales.ts";
|
|
2
|
+
import { checkItemPath, isSlug } from "./item-path.ts";
|
|
3
|
+
import type { BlockLayout } from "./block-layout.ts";
|
|
4
|
+
import type { FieldsData, Typed } from "./field-types.ts";
|
|
5
|
+
import type { PageComponent } from "./page-templates.ts";
|
|
6
|
+
|
|
7
|
+
export type FieldType =
|
|
8
|
+
| "text"
|
|
9
|
+
| "textarea"
|
|
10
|
+
| "richtext"
|
|
11
|
+
| "number"
|
|
12
|
+
| "boolean"
|
|
13
|
+
| "date"
|
|
14
|
+
| "url"
|
|
15
|
+
| "email"
|
|
16
|
+
| "select"
|
|
17
|
+
| "image"
|
|
18
|
+
| "gallery"
|
|
19
|
+
| "blocks"
|
|
20
|
+
| "tags"
|
|
21
|
+
| "keyvalue"
|
|
22
|
+
| "reference";
|
|
23
|
+
|
|
24
|
+
/** What the owner can stack in a `blocks` field: rich text, and Brim's blocks that need nothing from the page's code. */
|
|
25
|
+
export const BLOCK_TYPES = [
|
|
26
|
+
"richtext",
|
|
27
|
+
"image",
|
|
28
|
+
"image-gallery",
|
|
29
|
+
"carousel",
|
|
30
|
+
"video",
|
|
31
|
+
"button",
|
|
32
|
+
"accordion",
|
|
33
|
+
"divider",
|
|
34
|
+
"map",
|
|
35
|
+
] as const;
|
|
36
|
+
|
|
37
|
+
export type BlockType = (typeof BLOCK_TYPES)[number];
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* One block of a `blocks` field: an id of its own, its kind, its value (rich text, or the block's settings) and how it
|
|
41
|
+
* sits in the field (its width and side, see block-layout.ts).
|
|
42
|
+
*/
|
|
43
|
+
export interface BlockEntry {
|
|
44
|
+
id: string;
|
|
45
|
+
type: BlockType;
|
|
46
|
+
value: Record<string, unknown>;
|
|
47
|
+
layout?: BlockLayout;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* A choice of a `select` field: a plain string is both what is saved and what is shown; `{ value, label }` saves
|
|
52
|
+
* the value (`ceramica`, fit for an address) and shows the label (`Ceramică`).
|
|
53
|
+
*/
|
|
54
|
+
/**
|
|
55
|
+
* One choice of a `select` (or `tags`) field: a word, or `{ value, label }` when what is saved differs from what is
|
|
56
|
+
* shown. `labels` gives the label in the site's other languages: `{ value: "lucios", label: "Lucios",
|
|
57
|
+
* labels: { en: "Glossy" } }`.
|
|
58
|
+
*/
|
|
59
|
+
export type SelectOption = string | { value: string; label: string; labels?: Record<string, string> };
|
|
60
|
+
|
|
61
|
+
/** One row of a `keyvalue` field: technical details, opening hours, a spec sheet. */
|
|
62
|
+
export interface KeyValueEntry {
|
|
63
|
+
label: string;
|
|
64
|
+
value: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface ContentField {
|
|
68
|
+
/** Key of the value in an item's data, e.g. `location`. */
|
|
69
|
+
name: string;
|
|
70
|
+
label: string;
|
|
71
|
+
type: FieldType;
|
|
72
|
+
required?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Choices of a `select` field (plain strings or `{ value, label }`); for a `tags` field, the only tags it takes
|
|
75
|
+
* (plain strings, any tag when left out).
|
|
76
|
+
*/
|
|
77
|
+
options?: SelectOption[];
|
|
78
|
+
/** Shown under the field in the editor. */
|
|
79
|
+
help?: string;
|
|
80
|
+
/** The blocks a `blocks` field offers, in the order the editor lists them; all of `BLOCK_TYPES` when left out. */
|
|
81
|
+
blocks?: BlockType[];
|
|
82
|
+
/**
|
|
83
|
+
* For a `reference` field: the key of the content type (often a vocabulary) whose items it points at, e.g.
|
|
84
|
+
* `"category"`. The item keeps the slug of the item it points at (`"ceramica"`), or a list of slugs with `multiple`.
|
|
85
|
+
*/
|
|
86
|
+
to?: string;
|
|
87
|
+
/** For a `reference` field: several items, kept as a list of slugs. */
|
|
88
|
+
multiple?: boolean;
|
|
89
|
+
/**
|
|
90
|
+
* The vocabulary a field takes its terms from: `{ name: "category", label: "Category", vocabulary: "category" }`
|
|
91
|
+
* says so in the declaration, and is a `reference` field to that vocabulary (`type` may be left out). The editor
|
|
92
|
+
* and the MCP show which vocabulary a field uses.
|
|
93
|
+
*/
|
|
94
|
+
vocabulary?: string;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** A field of the site's own settings (src/site-settings.ts): a field with its Site Settings section and default. */
|
|
98
|
+
export type SiteSettingField = ContentField & { group?: string; default?: unknown };
|
|
99
|
+
|
|
100
|
+
/** A field as a content type declares it: `type` may be left out when `vocabulary` names the field's vocabulary. */
|
|
101
|
+
export type ContentFieldInput =
|
|
102
|
+
ContentField | (Omit<ContentField, "type"> & { type?: "reference"; vocabulary: string });
|
|
103
|
+
|
|
104
|
+
/** A content type as declared: its fields may name their vocabulary instead of a type. */
|
|
105
|
+
export type ContentTypeInput = Omit<ContentType, "fields"> & { fields: ContentFieldInput[] };
|
|
106
|
+
|
|
107
|
+
/** A field naming its vocabulary is a reference to it; any other field is as declared. */
|
|
108
|
+
function normalizeField(field: ContentFieldInput): ContentField {
|
|
109
|
+
if (field.vocabulary === undefined) return field as ContentField;
|
|
110
|
+
if (field.type !== undefined && field.type !== "reference")
|
|
111
|
+
throw new Error(
|
|
112
|
+
`Field "${field.name}" takes its terms from the vocabulary "${field.vocabulary}": leave its type out, or make it "reference".`,
|
|
113
|
+
);
|
|
114
|
+
if (field.to !== undefined && field.to !== field.vocabulary)
|
|
115
|
+
throw new Error(`Field "${field.name}" names the vocabulary "${field.vocabulary}" but points at "${field.to}".`);
|
|
116
|
+
return { ...field, type: "reference", to: field.vocabulary };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* A kind of repeatable content: projects, articles, team members.
|
|
121
|
+
* Every item also has a title, an address (slug) and is private or published.
|
|
122
|
+
*/
|
|
123
|
+
export interface ContentType {
|
|
124
|
+
/** Identifies the type in code, e.g. `project`. */
|
|
125
|
+
key: string;
|
|
126
|
+
/** Plural name shown in the editor, e.g. `Projects`. */
|
|
127
|
+
label: string;
|
|
128
|
+
/** Name of one item, e.g. `Project`. */
|
|
129
|
+
singular: string;
|
|
130
|
+
/** First part of an item's address: `/projects/<item>`. Also names the type's feed, `/rss/<slug>.xml`. */
|
|
131
|
+
slug: string;
|
|
132
|
+
/**
|
|
133
|
+
* The address of an item's page when it is not `/<slug>/<item>`: fixed segments, `[slug]` for the item's own slug,
|
|
134
|
+
* and `[field]` for the value of a required `select` or `text` field, e.g. `/produse/[category]/[slug]`. It starts
|
|
135
|
+
* with a fixed segment. The template, the sitemap, feeds, links and the editor all use it; when an item's value
|
|
136
|
+
* changes, its former address sends visitors on to the new one.
|
|
137
|
+
*/
|
|
138
|
+
path?: string;
|
|
139
|
+
fields: ContentField[];
|
|
140
|
+
/**
|
|
141
|
+
* An item with a page (`component`) has a description by default: a `textarea` field `description`, first in the
|
|
142
|
+
* form, that the page gives search engines and shared links when Page Settings say nothing else. `false` leaves
|
|
143
|
+
* it out. A field named `description` in `fields` takes its place: a label of its own ("Summary"), `required`.
|
|
144
|
+
*/
|
|
145
|
+
description?: boolean;
|
|
146
|
+
/**
|
|
147
|
+
* An item with a page has a main picture by default: an `image` field `image`, shown when the page is shared.
|
|
148
|
+
* `false` leaves it out. A field named `image` in `fields` takes its place.
|
|
149
|
+
*/
|
|
150
|
+
image?: boolean;
|
|
151
|
+
/**
|
|
152
|
+
* The items are articles (news, blog posts): pages search engines are told were written by someone, on a date.
|
|
153
|
+
* Adds a `date` field `published`, filled in when an item is first published, and `<Seo>` writes schema.org
|
|
154
|
+
* `Article` data on the item's page from its title, description, image, author and dates. A `date` field named
|
|
155
|
+
* `modified`, when declared, says when the article was last revised.
|
|
156
|
+
*/
|
|
157
|
+
article?: boolean;
|
|
158
|
+
/**
|
|
159
|
+
* Every item has an author by default: a text field `author`, added after the declared fields, that the item's
|
|
160
|
+
* page gives as `<meta name="author">` and in an article's data. `false` leaves it out, for items nobody signs
|
|
161
|
+
* (team members, products). A field named `author` in `fields` takes its place: a `select` of the site's writers,
|
|
162
|
+
* or a vocabulary of them.
|
|
163
|
+
*/
|
|
164
|
+
author?: boolean;
|
|
165
|
+
/** Set by `defineVocabulary`: a list of terms other types point at, which the editor lists as such. */
|
|
166
|
+
vocabulary?: boolean;
|
|
167
|
+
/**
|
|
168
|
+
* Every item has tags by default: a `tags` field `tags`, added after the author, that listings filter on
|
|
169
|
+
* (`filter={{ tags: "garden" }}`) and the editor's content browser too. `false` leaves it out. A field named
|
|
170
|
+
* `tags` in `fields` takes its place, e.g. one with `options`, so only the site's own tags can be chosen.
|
|
171
|
+
*/
|
|
172
|
+
tags?: boolean;
|
|
173
|
+
/**
|
|
174
|
+
* The template of the type: an Astro component that draws the page of every item, at `/<slug>/<item>`, and
|
|
175
|
+
* receives the item as the `item` prop. What the owner changes on it, besides the item's own fields, is saved
|
|
176
|
+
* once for the type and shows on every item's page.
|
|
177
|
+
*/
|
|
178
|
+
component?: PageComponent;
|
|
179
|
+
/**
|
|
180
|
+
* An RSS feed of the type's published items, at `/rss/<slug>.xml` (`/rss/<locale>/<slug>.xml` in another
|
|
181
|
+
* language), for a blog, news or anything else readers follow. Off unless set; `true` uses the defaults.
|
|
182
|
+
* Items need a page of their own to be in it: a template, or a page in the site's code.
|
|
183
|
+
*/
|
|
184
|
+
feed?: boolean | FeedOptions;
|
|
185
|
+
/**
|
|
186
|
+
* The owner puts the items in order by dragging them in the editor: categories of a menu, the steps of a
|
|
187
|
+
* process, a team. `Listing`, `getItems` and menus built from the type (`from` in `Navbar` and `Footer`) then
|
|
188
|
+
* show them in that order unless the code sorts them otherwise (`sort="title"`). Without it, items come newest
|
|
189
|
+
* first. Their order is also `sort="position"` / `sort: "position"`, for a type that is not `ordered`.
|
|
190
|
+
*/
|
|
191
|
+
ordered?: boolean;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** How a content type's feed reads its items. Every field is optional. */
|
|
195
|
+
export interface FeedOptions {
|
|
196
|
+
/** The feed's title; by default the type's `label`, after the site's name when it has one. */
|
|
197
|
+
title?: string;
|
|
198
|
+
/** What the feed is about, shown by feed readers. */
|
|
199
|
+
description?: string;
|
|
200
|
+
/** A `date` field that says when an item was published; by default `published`, else the first one, else its creation. */
|
|
201
|
+
date?: string;
|
|
202
|
+
/**
|
|
203
|
+
* A `text`, `textarea` or `richtext` field that sums an item up; by default `description` (or the first `textarea`
|
|
204
|
+
* of a type without it), then the description set for the item's page, then the first `richtext` field's opening.
|
|
205
|
+
*/
|
|
206
|
+
summary?: string;
|
|
207
|
+
/** How many of the newest items the feed holds; 20 by default. */
|
|
208
|
+
limit?: number;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const KEY = /^[a-z][a-z0-9_]*$/;
|
|
212
|
+
|
|
213
|
+
/** The field an item with a page has unless its type says `description: false`. */
|
|
214
|
+
export const DESCRIPTION_FIELD: ContentField = {
|
|
215
|
+
name: "description",
|
|
216
|
+
label: "Description",
|
|
217
|
+
type: "textarea",
|
|
218
|
+
help: "A sentence or two. Shown in search results and on shared links.",
|
|
219
|
+
};
|
|
220
|
+
/** The field an item with a page has unless its type says `image: false`. */
|
|
221
|
+
export const IMAGE_FIELD: ContentField = {
|
|
222
|
+
name: "image",
|
|
223
|
+
label: "Image",
|
|
224
|
+
type: "image",
|
|
225
|
+
help: "The main picture. Shown when the page is shared.",
|
|
226
|
+
};
|
|
227
|
+
/** The field an item of an `article` type has. */
|
|
228
|
+
export const PUBLISHED_FIELD: ContentField = {
|
|
229
|
+
name: "published",
|
|
230
|
+
label: "Published",
|
|
231
|
+
type: "date",
|
|
232
|
+
help: "Filled in when it is first published.",
|
|
233
|
+
};
|
|
234
|
+
/** The field every item has unless its type says `author: false`; its value is a name, as readers see it. */
|
|
235
|
+
export const AUTHOR_FIELD: ContentField = { name: "author", label: "Author", type: "text" }; // betterleaks:allow (a field definition, not a secret)
|
|
236
|
+
/** The field every item has unless its type says `tags: false`: a list of short words to find and filter it by. */
|
|
237
|
+
export const TAGS_FIELD: ContentField = { name: "tags", label: "Tags", type: "tags" };
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* What a field of a standard name must be for Brim to read it. One of another type is the site's own: it works as
|
|
241
|
+
* declared, and search engines are not given it.
|
|
242
|
+
*/
|
|
243
|
+
const STANDARD_TYPES: Record<string, readonly FieldType[]> = {
|
|
244
|
+
description: ["textarea", "text"],
|
|
245
|
+
image: ["image"],
|
|
246
|
+
published: ["date"],
|
|
247
|
+
modified: ["date"],
|
|
248
|
+
author: ["text", "select", "reference", "tags"],
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
/** The type's field of a standard name, when it is of a type Brim can read; `undefined` otherwise. */
|
|
252
|
+
export function standardField(
|
|
253
|
+
type: Pick<ContentType, "fields">,
|
|
254
|
+
name: "description" | "image" | "published" | "modified" | "author",
|
|
255
|
+
): ContentField | undefined {
|
|
256
|
+
return type.fields.find((field) => field.name === name && STANDARD_TYPES[name]?.includes(field.type));
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Declares a content type. Mistakes in the declaration fail here, at startup, not when content is saved.
|
|
261
|
+
* The type it returns has the fields Brim adds among its own: `description` and `image` (with a page), `published`
|
|
262
|
+
* (an `article`), `author` and `tags`, unless it said `false` to one or declared a field of that name itself.
|
|
263
|
+
*/
|
|
264
|
+
export function defineContentType<const Fields extends readonly ContentFieldInput[]>(
|
|
265
|
+
input: Omit<ContentTypeInput, "fields"> & { fields: Fields },
|
|
266
|
+
): ContentType & Typed<FieldsData<Fields>> {
|
|
267
|
+
const type: ContentType = { ...input, fields: input.fields.map(normalizeField) };
|
|
268
|
+
if (!KEY.test(type.key))
|
|
269
|
+
throw new Error(`Content type key "${type.key}" must be lowercase letters, digits or underscores.`);
|
|
270
|
+
if (!isSlug(type.slug)) throw new Error(`Content type slug "${type.slug}" must be lowercase words joined by dashes.`);
|
|
271
|
+
|
|
272
|
+
const names = new Set<string>();
|
|
273
|
+
for (const field of type.fields) {
|
|
274
|
+
if (!KEY.test(field.name))
|
|
275
|
+
throw new Error(`Field name "${field.name}" in "${type.key}" must be lowercase letters, digits or underscores.`);
|
|
276
|
+
if (names.has(field.name)) throw new Error(`Field "${field.name}" is declared twice in "${type.key}".`);
|
|
277
|
+
if (field.type === "select" && !field.options?.length)
|
|
278
|
+
throw new Error(`Select field "${field.name}" in "${type.key}" needs options.`);
|
|
279
|
+
if (field.type === "reference" && !(field.to && KEY.test(field.to)))
|
|
280
|
+
throw new Error(`Reference field "${field.name}" in "${type.key}" needs "to": the key of the type it points at.`);
|
|
281
|
+
if (field.type !== "reference" && (field.to !== undefined || field.multiple !== undefined))
|
|
282
|
+
throw new Error(
|
|
283
|
+
`Field "${field.name}" in "${type.key}" has "to" or "multiple", which only a reference field takes.`,
|
|
284
|
+
);
|
|
285
|
+
if (field.options) checkOptions(type, field);
|
|
286
|
+
if (field.type === "blocks" && !type.component)
|
|
287
|
+
throw new Error(
|
|
288
|
+
`Blocks field "${field.name}" in "${type.key}" is arranged on the item's page: give the type a component.`,
|
|
289
|
+
);
|
|
290
|
+
const unknown = field.blocks?.find((block) => !BLOCK_TYPES.includes(block));
|
|
291
|
+
if (unknown)
|
|
292
|
+
throw new Error(`Field "${field.name}" in "${type.key}" offers "${unknown}", which is not a block it can hold.`);
|
|
293
|
+
names.add(field.name);
|
|
294
|
+
}
|
|
295
|
+
if (type.article && !type.component)
|
|
296
|
+
throw new Error(`Content type "${type.key}" is made of articles, which have a page each: give it a component.`);
|
|
297
|
+
if (type.component !== undefined && typeof type.component !== "function")
|
|
298
|
+
throw new Error(`The component of content type "${type.key}" must be an Astro component.`);
|
|
299
|
+
const missing = (field: ContentField, wanted: boolean): ContentField[] =>
|
|
300
|
+
wanted && !names.has(field.name) ? [field] : [];
|
|
301
|
+
const hasPage = type.component !== undefined;
|
|
302
|
+
type.fields = [
|
|
303
|
+
...missing(DESCRIPTION_FIELD, hasPage && type.description !== false),
|
|
304
|
+
...missing(IMAGE_FIELD, hasPage && type.image !== false),
|
|
305
|
+
...type.fields,
|
|
306
|
+
...missing(PUBLISHED_FIELD, type.article === true),
|
|
307
|
+
...missing(AUTHOR_FIELD, type.author !== false),
|
|
308
|
+
...missing(TAGS_FIELD, type.tags !== false),
|
|
309
|
+
];
|
|
310
|
+
checkItemPath(type);
|
|
311
|
+
if (typeof type.feed === "object") checkFeed(type, type.feed);
|
|
312
|
+
return type;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function checkOptions(type: ContentType, field: ContentField): void {
|
|
316
|
+
if (field.type === "tags" && field.options?.some((option) => typeof option !== "string"))
|
|
317
|
+
throw new Error(`Tags field "${field.name}" in "${type.key}" takes its choices as plain words.`);
|
|
318
|
+
const values = new Set<string>();
|
|
319
|
+
for (const option of optionsOf(field)) {
|
|
320
|
+
if (option.value.trim() === "" || option.label.trim() === "")
|
|
321
|
+
throw new Error(`Field "${field.name}" in "${type.key}" has a choice without a value or a label.`);
|
|
322
|
+
if (option.labels && Object.values(option.labels).some((label) => typeof label !== "string" || label.trim() === ""))
|
|
323
|
+
throw new Error(`Field "${field.name}" in "${type.key}" has the choice "${option.value}" with an empty label.`);
|
|
324
|
+
if (values.has(option.value))
|
|
325
|
+
throw new Error(`Field "${field.name}" in "${type.key}" has the choice "${option.value}" twice.`);
|
|
326
|
+
values.add(option.value);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/** The choices of a field as `{ value, label }`, whichever way the type wrote them. */
|
|
331
|
+
export function optionsOf(
|
|
332
|
+
field: Pick<ContentField, "options">,
|
|
333
|
+
): { value: string; label: string; labels?: Record<string, string> }[] {
|
|
334
|
+
return (field.options ?? []).map((option) =>
|
|
335
|
+
typeof option === "string" ? { value: option, label: option } : option,
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/** What a field's choices save: `["ceramica", "mozaic"]`. */
|
|
340
|
+
export function optionValues(field: Pick<ContentField, "options">): string[] {
|
|
341
|
+
return optionsOf(field).map((option) => option.value);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* What a site shows for a saved choice: its label (`Ceramică` for `ceramica`), or the value itself when it is not
|
|
346
|
+
* one of the field's choices (any more).
|
|
347
|
+
*/
|
|
348
|
+
export function optionLabel(field: Pick<ContentField, "options">, value: string, locale?: string): string {
|
|
349
|
+
const option = optionsOf(field).find((candidate) => candidate.value === value);
|
|
350
|
+
if (!option) return value;
|
|
351
|
+
return (locale !== undefined && option.labels?.[locale]) || option.label;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* A vocabulary: a list of terms the owner keeps (categories, brands, rooms, materials), which other types point at
|
|
356
|
+
* with `reference` fields. It is a content type like any other, so its terms are items: added, renamed and given
|
|
357
|
+
* pictures in the editor's Content, through the MCP and the API, in every language. By default a term has no author
|
|
358
|
+
* and no tags, and no page of its own unless the vocabulary gives a `component`.
|
|
359
|
+
*
|
|
360
|
+
* export const category = defineVocabulary({ key: "category", label: "Categories", singular: "Category",
|
|
361
|
+
* slug: "categories", fields: [{ name: "image", label: "Image", type: "image" }] });
|
|
362
|
+
* // in product: { name: "category", label: "Category", type: "reference", to: "category", required: true }
|
|
363
|
+
*/
|
|
364
|
+
export function defineVocabulary<const Fields extends readonly ContentFieldInput[]>(
|
|
365
|
+
type: Omit<ContentTypeInput, "vocabulary" | "fields"> & { fields: Fields },
|
|
366
|
+
): ContentType & Typed<FieldsData<Fields>> {
|
|
367
|
+
return defineContentType({ author: false, tags: false, ...type, vocabulary: true });
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
function checkFeed(type: ContentType, feed: FeedOptions): void {
|
|
371
|
+
const field = (name: string | undefined, kinds: FieldType[], role: string) => {
|
|
372
|
+
if (name === undefined) return;
|
|
373
|
+
const found = type.fields.find((candidate) => candidate.name === name);
|
|
374
|
+
if (!found || !kinds.includes(found.type))
|
|
375
|
+
throw new Error(
|
|
376
|
+
`The feed of "${type.key}" reads ${role} from "${name}", which is not a ${kinds.join(" or ")} field.`,
|
|
377
|
+
);
|
|
378
|
+
};
|
|
379
|
+
field(feed.date, ["date"], "the date");
|
|
380
|
+
field(feed.summary, ["text", "textarea", "richtext"], "the summary");
|
|
381
|
+
if (feed.limit !== undefined && !(Number.isInteger(feed.limit) && feed.limit > 0))
|
|
382
|
+
throw new Error(`The feed of "${type.key}" needs a whole number above 0 as its limit.`);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/** The feed options of a type that has a feed, with `true` read as the defaults. */
|
|
386
|
+
export function feedOptionsOf(type: ContentType): FeedOptions | undefined {
|
|
387
|
+
if (!type.feed) return undefined;
|
|
388
|
+
return type.feed === true ? {} : type.feed;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* The type whose template draws the page at this address, the item's slug and its language as stored ("" for the
|
|
393
|
+
* default one): `/projects/lake-house`, or `/ro/projects/casa-de-la-lac` on a site with languages. With a `path`
|
|
394
|
+
* like `/produse/[category]/[slug]` only the shape is read here; the item's category is checked once it is loaded.
|
|
395
|
+
*/
|
|
396
|
+
export function itemPageOf(
|
|
397
|
+
types: ContentType[],
|
|
398
|
+
path: string,
|
|
399
|
+
locales?: LocaleConfig,
|
|
400
|
+
): { type: ContentType; slug: string; locale: string } | undefined {
|
|
401
|
+
return readItemPath(
|
|
402
|
+
types.filter((type) => type.component),
|
|
403
|
+
path,
|
|
404
|
+
locales,
|
|
405
|
+
);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
export { isSlug, slugify } from "./item-path.ts";
|