astronaut-cms 0.0.1 → 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 +21 -0
- package/README.md +84 -3
- package/dist/admin/THIRD_PARTY_LICENSES.md +7598 -0
- package/dist/admin/assets/assistant-DkS355co.js +201 -0
- package/dist/admin/assets/badge-BXsOvOPX.js +1 -0
- package/dist/admin/assets/changes-Ba0G_GN1.js +1 -0
- package/dist/admin/assets/client-VKp75fDU.js +5 -0
- package/dist/admin/assets/clsx-DB0hHKMi.js +1 -0
- package/dist/admin/assets/collapsible-B6P_J0Bg.js +1 -0
- package/dist/admin/assets/collapsible-item-UaoJaaPw.js +1 -0
- package/dist/admin/assets/collections._collection-BE1enDCq.js +1 -0
- package/dist/admin/assets/collections._collection._entry-D3UksnCo.js +52 -0
- package/dist/admin/assets/collections._collection.index-BN5d8UIY.js +1 -0
- package/dist/admin/assets/component-lookup-CUCiK8Xh.js +4 -0
- package/dist/admin/assets/config-Pm_BHLNT.js +1 -0
- package/dist/admin/assets/copy-DezZzPMV.js +1 -0
- package/dist/admin/assets/css-BGIxQoYs.js +1 -0
- package/dist/admin/assets/css-DgaLhXQH.js +1 -0
- package/dist/admin/assets/diff-woXpYk--.js +1 -0
- package/dist/admin/assets/dist-DzkcSBZl.js +1 -0
- package/dist/admin/assets/dist-UbA1s2kM.js +1 -0
- package/dist/admin/assets/docx-BctAmX91.js +56 -0
- package/dist/admin/assets/editor-FGqMznBK.js +2 -0
- package/dist/admin/assets/empty-DSBYiI_7.js +1 -0
- package/dist/admin/assets/entry-link-CQLN2Zpf.js +158 -0
- package/dist/admin/assets/error-banner-yskeRXe8.js +159 -0
- package/dist/admin/assets/errors-DkJ5E_ak.js +1 -0
- package/dist/admin/assets/field-BDK5tt3J.js +41 -0
- package/dist/admin/assets/field-schema-CacrjSYw.js +1 -0
- package/dist/admin/assets/file-text-BzBif8ui.js +1 -0
- package/dist/admin/assets/github-dark-C-LZuMrd.js +1 -0
- package/dist/admin/assets/github-light-EUqPIrTm.js +1 -0
- package/dist/admin/assets/highlighted-body-JLMTFACH-CIQujGv2.js +1 -0
- package/dist/admin/assets/html-CvFb5cGI.js +1 -0
- package/dist/admin/assets/javascript-BzbQS41l.js +1 -0
- package/dist/admin/assets/javascript-CpIGwZ_Y.js +1 -0
- package/dist/admin/assets/json-qhed-kSA.js +1 -0
- package/dist/admin/assets/jsx-Bz0zcwM4.js +1 -0
- package/dist/admin/assets/lib-CMURo-7A.js +21 -0
- package/dist/admin/assets/library-Cr3f75Es.js +1 -0
- package/dist/admin/assets/list-skeleton-BdTNfVXs.js +1 -0
- package/dist/admin/assets/markdown-BYOwaDjH.js +1 -0
- package/dist/admin/assets/matchContext-Bq5Es9aD.js +2 -0
- package/dist/admin/assets/media-browser-9-CPTCks.js +1 -0
- package/dist/admin/assets/media._library-BfFaEZLR.js +1 -0
- package/dist/admin/assets/mermaid-WFAXDIZX-CJ3hhA0i.js +1 -0
- package/dist/admin/assets/page-header-B4nvAsVA.js +1 -0
- package/dist/admin/assets/pdf-DgessaF0.js +106 -0
- package/dist/admin/assets/python-gzcpVVnB.js +1 -0
- package/dist/admin/assets/react-kbcsfQYH.js +1 -0
- package/dist/admin/assets/rolldown-runtime-BWaJ3C7D.js +1 -0
- package/dist/admin/assets/routes-CBt04sNR.js +1 -0
- package/dist/admin/assets/routes-D7tEdYGV.js +1 -0
- package/dist/admin/assets/save-actions-Cz0TkpcP.js +32 -0
- package/dist/admin/assets/select-Bv2EoLhN.js +1 -0
- package/dist/admin/assets/separator-DlYj_PoQ.js +3 -0
- package/dist/admin/assets/shell-DBEiq06l.js +1 -0
- package/dist/admin/assets/shellscript-CLZ0U2zV.js +1 -0
- package/dist/admin/assets/skeleton-CKiqTaRh.js +1 -0
- package/dist/admin/assets/sql-CEbI0hMM.js +1 -0
- package/dist/admin/assets/syntax-BAXqRKRO.js +8 -0
- package/dist/admin/assets/toggle-Y2UpJZyU.js +1 -0
- package/dist/admin/assets/toml-BPTmHmyx.js +1 -0
- package/dist/admin/assets/tsx-udAQXfEw.js +1 -0
- package/dist/admin/assets/typescript-bsJCZSQ-.js +1 -0
- package/dist/admin/assets/ui.module.css-WaO_77ml.js +56 -0
- package/dist/admin/assets/use-entries-B2lsaiK9.js +1 -0
- package/dist/admin/assets/useSelector-CWr3iU9K.js +1 -0
- package/dist/admin/assets/yaml-rwi0_p6S.js +1 -0
- package/dist/admin/assets/zwitch-Wwuax-dJ.js +1 -0
- package/dist/admin/bootstrap.d.ts +1 -0
- package/dist/admin/bootstrap.js +1 -0
- package/dist/admin/editor.d.ts +57 -0
- package/dist/admin/editor.js +1 -0
- package/dist/server/assets.d.ts +2 -0
- package/dist/server/assets.js +30 -0
- package/dist/server/chunks/anchors-DuZ1fokt.js +86 -0
- package/dist/server/chunks/auth-DJP9ryVd.js +44 -0
- package/dist/server/chunks/cms-markers-CUqrOnfA.js +78 -0
- package/dist/server/chunks/component-lookup-DAFg_Qg8.js +128 -0
- package/dist/server/chunks/config-WQqG4mNH.d.ts +193 -0
- package/dist/server/chunks/digest-BYzWNJea.js +753 -0
- package/dist/server/chunks/entry-checks-CKMag1G4.js +608 -0
- package/dist/server/chunks/field-schema-CfdN75jT.js +48 -0
- package/dist/server/chunks/http-BnsNh57m.d.ts +35 -0
- package/dist/server/chunks/i18n-BPmx7ESy.d.ts +15 -0
- package/dist/server/chunks/index-CYbkNvu5.d.ts +22 -0
- package/dist/server/chunks/media-BhqUVVYY.js +223 -0
- package/dist/server/chunks/paths-CEW9fvg8.js +17 -0
- package/dist/server/chunks/paths-Dztx2eUw.js +13 -0
- package/dist/server/chunks/types-DOR5XaJO.js +397 -0
- package/dist/server/chunks/types-Dkx4Xovf.d.ts +359 -0
- package/dist/server/chunks/types-DwA-C6Br.d.ts +266 -0
- package/dist/server/chunks/user-config-DoypbpQf.js +283 -0
- package/dist/server/chunks/xml-D8qPILJU.js +81 -0
- package/dist/server/config.d.ts +3 -0
- package/dist/server/config.js +18 -0
- package/dist/server/content.d.ts +48 -0
- package/dist/server/content.js +89 -0
- package/dist/server/endpoint.d.ts +11 -0
- package/dist/server/endpoint.js +2712 -0
- package/dist/server/integration.d.ts +7 -0
- package/dist/server/integration.js +1174 -0
- package/dist/server/internal.d.ts +65 -0
- package/dist/server/internal.js +30 -0
- package/dist/server/server-local.d.ts +453 -0
- package/dist/server/server-local.js +336 -0
- package/dist/styles/THIRD_PARTY_LICENSES.md +193 -0
- package/dist/styles/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
- package/dist/styles/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
- package/dist/styles/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
- package/dist/styles/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
- package/dist/styles/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
- package/dist/styles/styles.css +3 -0
- package/package.json +151 -5
- package/src/astro/Image.astro +28 -0
- package/src/astro/Video.astro +44 -0
- package/src/astro/admin.astro +137 -0
- package/src/astro/licenses.ts +5 -0
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
import { d as diagnostic, s as isRecord, u as ContentValidationError } from "./field-schema-CfdN75jT.js";
|
|
2
|
+
import { t as projectPath } from "./paths-CEW9fvg8.js";
|
|
3
|
+
import { extname, join, relative } from "pathe";
|
|
4
|
+
import { isMap, isNode, isScalar, isSeq, parse, parseDocument, stringify } from "yaml";
|
|
5
|
+
import { parse as parse$1, stringify as stringify$1 } from "smol-toml";
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import { fromMarkdown } from "mdast-util-from-markdown";
|
|
8
|
+
import { frontmatterFromMarkdown } from "mdast-util-frontmatter";
|
|
9
|
+
import { frontmatter } from "micromark-extension-frontmatter";
|
|
10
|
+
import picomatch from "picomatch/posix.js";
|
|
11
|
+
import { slug } from "github-slugger";
|
|
12
|
+
// src/shared/content-parser.ts
|
|
13
|
+
/**
|
|
14
|
+
* Extracts the file extension from a file name or path.
|
|
15
|
+
*/
|
|
16
|
+
var getFileExtension = (fileName) => extname(fileName).slice(1);
|
|
17
|
+
var isYaml = (format) => format === "yaml" || format === "yml";
|
|
18
|
+
var tomlValue = z.lazy(() => z.union([
|
|
19
|
+
z.string(),
|
|
20
|
+
z.custom((value) => typeof value === "number"),
|
|
21
|
+
z.bigint(),
|
|
22
|
+
z.boolean(),
|
|
23
|
+
z.instanceof(Date),
|
|
24
|
+
z.array(tomlValue),
|
|
25
|
+
z.record(z.string(), tomlValue)
|
|
26
|
+
]));
|
|
27
|
+
var tomlTable = z.record(z.string(), tomlValue);
|
|
28
|
+
function serializableToml(data) {
|
|
29
|
+
const result = tomlTable.safeParse(data);
|
|
30
|
+
if (!result.success) throw new ContentValidationError(result.error.issues.map((issue) => diagnostic("TOML cannot store this value.", issue.path.map(String).join("."))));
|
|
31
|
+
return result.data;
|
|
32
|
+
}
|
|
33
|
+
/** The YAML frontmatter a Markdown file opens with, and the body on the lines after it. */
|
|
34
|
+
function splitFrontmatter(raw) {
|
|
35
|
+
const [node] = fromMarkdown(raw, {
|
|
36
|
+
extensions: [frontmatter()],
|
|
37
|
+
mdastExtensions: [frontmatterFromMarkdown()]
|
|
38
|
+
}).children;
|
|
39
|
+
if (node?.type !== "yaml" || !node.position) return { body: raw };
|
|
40
|
+
const newline = raw.indexOf("\n", node.position.end.offset);
|
|
41
|
+
return {
|
|
42
|
+
frontmatter: node.value,
|
|
43
|
+
body: newline === -1 ? "" : raw.slice(newline + 1)
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function parseContent(rawContent, format) {
|
|
47
|
+
switch (format) {
|
|
48
|
+
case "md":
|
|
49
|
+
case "mdx":
|
|
50
|
+
case "mdoc": {
|
|
51
|
+
const { frontmatter, body } = splitFrontmatter(rawContent);
|
|
52
|
+
if (frontmatter === void 0) return {
|
|
53
|
+
data: {},
|
|
54
|
+
body
|
|
55
|
+
};
|
|
56
|
+
return {
|
|
57
|
+
data: parse(frontmatter) ?? {},
|
|
58
|
+
body
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
case "json": return {
|
|
62
|
+
data: JSON.parse(rawContent),
|
|
63
|
+
body: ""
|
|
64
|
+
};
|
|
65
|
+
case "yaml":
|
|
66
|
+
case "yml": return {
|
|
67
|
+
data: parse(rawContent) ?? {},
|
|
68
|
+
body: ""
|
|
69
|
+
};
|
|
70
|
+
case "toml": return {
|
|
71
|
+
data: parse$1(rawContent),
|
|
72
|
+
body: ""
|
|
73
|
+
};
|
|
74
|
+
default: return {
|
|
75
|
+
data: {},
|
|
76
|
+
body: rawContent
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function serializeContent(data, body, format) {
|
|
81
|
+
switch (format) {
|
|
82
|
+
case "md":
|
|
83
|
+
case "mdx":
|
|
84
|
+
case "mdoc": return `---\n${stringify(data, { lineWidth: 0 }).trimEnd()}\n---\n${body}`;
|
|
85
|
+
case "json": return JSON.stringify(data, null, 2) + "\n";
|
|
86
|
+
case "yaml":
|
|
87
|
+
case "yml": return stringify(data, { lineWidth: 0 });
|
|
88
|
+
case "toml": return stringify$1(serializableToml(data)) + "\n";
|
|
89
|
+
default: return body;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/** Astro names an array entry by `id` and falls back to `slug`. */
|
|
93
|
+
var idKey = (item) => item.id == null && item.slug != null ? "slug" : "id";
|
|
94
|
+
function arrayEntries(items) {
|
|
95
|
+
const entries = /* @__PURE__ */ new Map();
|
|
96
|
+
for (const item of items) {
|
|
97
|
+
const id = idOf(item[idKey(item)]);
|
|
98
|
+
if (id) entries.set(id, item);
|
|
99
|
+
}
|
|
100
|
+
return entries;
|
|
101
|
+
}
|
|
102
|
+
function parseContainer(rawContent, format) {
|
|
103
|
+
switch (format) {
|
|
104
|
+
case "json": return JSON.parse(rawContent);
|
|
105
|
+
case "toml": return parse$1(rawContent);
|
|
106
|
+
default: return null;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/** Parsed once, so the entries and the document a rewrite edits come from the same pass. */
|
|
110
|
+
function parseYamlDocument(rawContent) {
|
|
111
|
+
const doc = parseDocument(rawContent);
|
|
112
|
+
if (doc.errors[0]) throw doc.errors[0];
|
|
113
|
+
return doc;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Parses a file that contains multiple entries (used by file() loader collections).
|
|
117
|
+
* Returns the entries keyed by ID in file order and the detected layout.
|
|
118
|
+
*/
|
|
119
|
+
function parseMultiEntryFile(rawContent, format) {
|
|
120
|
+
const yaml = isYaml(format) ? parseYamlDocument(rawContent) : void 0;
|
|
121
|
+
const parsed = yaml ? yaml.toJS() : parseContainer(rawContent, format);
|
|
122
|
+
const source = yaml && { yaml };
|
|
123
|
+
if (Array.isArray(parsed)) return {
|
|
124
|
+
entries: arrayEntries(parsed),
|
|
125
|
+
layout: "array",
|
|
126
|
+
...source
|
|
127
|
+
};
|
|
128
|
+
const record = parsed ?? {};
|
|
129
|
+
const { $schema, ...rest } = record;
|
|
130
|
+
const isReference = typeof $schema === "string";
|
|
131
|
+
const entries = Object.entries(isReference ? rest : record);
|
|
132
|
+
return {
|
|
133
|
+
entries: new Map(entries),
|
|
134
|
+
layout: "object",
|
|
135
|
+
...isReference && { jsonSchema: $schema },
|
|
136
|
+
...source
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Serializes multiple entries back into a single file string.
|
|
141
|
+
* Preserves the original layout (array vs object).
|
|
142
|
+
*/
|
|
143
|
+
function serializeMultiEntryFile({ entries, layout, jsonSchema, yaml }, format) {
|
|
144
|
+
if (layout === "array") {
|
|
145
|
+
const arr = [...entries].map(([id, data]) => {
|
|
146
|
+
const key = idKey(data);
|
|
147
|
+
const current = data[key];
|
|
148
|
+
return {
|
|
149
|
+
...data,
|
|
150
|
+
[key]: idOf(current) === id ? current : id
|
|
151
|
+
};
|
|
152
|
+
});
|
|
153
|
+
return isYaml(format) ? serializeYaml(arr, yaml) : JSON.stringify(arr, null, 2) + "\n";
|
|
154
|
+
}
|
|
155
|
+
const record = {
|
|
156
|
+
...jsonSchema !== void 0 && { $schema: jsonSchema },
|
|
157
|
+
...Object.fromEntries(entries)
|
|
158
|
+
};
|
|
159
|
+
switch (format) {
|
|
160
|
+
case "yaml":
|
|
161
|
+
case "yml": return serializeYaml(record, yaml);
|
|
162
|
+
case "toml": return stringify$1(serializableToml(record)) + "\n";
|
|
163
|
+
default: return JSON.stringify(record, null, 2) + "\n";
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/** An entry's id as the map keys it, or undefined for a value that is none. */
|
|
167
|
+
function idOf(value) {
|
|
168
|
+
return typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? `${value}` : void 0;
|
|
169
|
+
}
|
|
170
|
+
var sameValue = (node, value) => isNode(node) && JSON.stringify(node.toJSON()) === JSON.stringify(value);
|
|
171
|
+
/**
|
|
172
|
+
* `value` written over `node`, reusing every part of the old tree that still
|
|
173
|
+
* holds the same value, so what a save leaves alone keeps its comments and
|
|
174
|
+
* blank lines. Maps are matched by key and sequence items by `id`, falling back
|
|
175
|
+
* to their position. A replaced node inherits the comments around the old one.
|
|
176
|
+
*/
|
|
177
|
+
function mergeYaml(doc, node, value) {
|
|
178
|
+
if (sameValue(node, value)) return node;
|
|
179
|
+
if (isMap(node) && isRecord(value)) {
|
|
180
|
+
const pairs = new Map(node.items.map((pair) => [isScalar(pair.key) ? idOf(pair.key.value) : void 0, pair]));
|
|
181
|
+
node.items = Object.entries(value).map(([key, item]) => {
|
|
182
|
+
const pair = pairs.get(key);
|
|
183
|
+
if (!pair) return doc.createPair(key, item);
|
|
184
|
+
pair.value = mergeYaml(doc, pair.value, item);
|
|
185
|
+
return pair;
|
|
186
|
+
});
|
|
187
|
+
return node;
|
|
188
|
+
}
|
|
189
|
+
if (isSeq(node) && Array.isArray(value)) {
|
|
190
|
+
const items = node.items;
|
|
191
|
+
const byId = new Map(items.filter(isMap).map((item) => [idOf(item.get("id") ?? item.get("slug")), item]));
|
|
192
|
+
node.items = value.map((item, index) => {
|
|
193
|
+
const id = isRecord(item) ? idOf(item[idKey(item)]) : void 0;
|
|
194
|
+
return mergeYaml(doc, id === void 0 ? items[index] : byId.get(id), item);
|
|
195
|
+
});
|
|
196
|
+
return node;
|
|
197
|
+
}
|
|
198
|
+
const next = doc.createNode(value);
|
|
199
|
+
if (isNode(node)) {
|
|
200
|
+
next.commentBefore = node.commentBefore;
|
|
201
|
+
next.comment = node.comment;
|
|
202
|
+
next.spaceBefore = node.spaceBefore;
|
|
203
|
+
}
|
|
204
|
+
return next;
|
|
205
|
+
}
|
|
206
|
+
/** A YAML container, written over the document it was read from when there is one. */
|
|
207
|
+
function serializeYaml(value, source) {
|
|
208
|
+
if (!source) return stringify(value, { lineWidth: 0 });
|
|
209
|
+
const doc = source.clone();
|
|
210
|
+
const merged = mergeYaml(doc, doc.contents, value);
|
|
211
|
+
doc.contents = isNode(merged) ? merged : doc.createNode(merged);
|
|
212
|
+
return doc.toString({ lineWidth: 0 });
|
|
213
|
+
}
|
|
214
|
+
// src/shared/i18n.ts
|
|
215
|
+
/** The locale a path sits directly under, or `null` when it sits under none. */
|
|
216
|
+
function localeOf(path, locales) {
|
|
217
|
+
const slash = path.indexOf("/");
|
|
218
|
+
const head = slash === -1 ? path : path.slice(0, slash);
|
|
219
|
+
return locales.includes(head) ? head : null;
|
|
220
|
+
}
|
|
221
|
+
function splitLocale(id, locales) {
|
|
222
|
+
const locale = localeOf(id, locales);
|
|
223
|
+
return locale ? {
|
|
224
|
+
locale,
|
|
225
|
+
slug: id.slice(locale.length + 1)
|
|
226
|
+
} : {
|
|
227
|
+
locale: null,
|
|
228
|
+
slug: id
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
function joinLocale(locale, slug) {
|
|
232
|
+
return slug ? `${locale}/${slug}` : locale;
|
|
233
|
+
}
|
|
234
|
+
// src/shared/types.ts
|
|
235
|
+
var CONTENT_FORMATS = [
|
|
236
|
+
"md",
|
|
237
|
+
"mdx",
|
|
238
|
+
"mdoc"
|
|
239
|
+
];
|
|
240
|
+
var DATA_FORMATS = [
|
|
241
|
+
"json",
|
|
242
|
+
"yaml",
|
|
243
|
+
"yml",
|
|
244
|
+
"toml"
|
|
245
|
+
];
|
|
246
|
+
var ALL_FORMATS = [...CONTENT_FORMATS, ...DATA_FORMATS];
|
|
247
|
+
/** A file extension as one of the formats the CMS knows, or null for anything else. */
|
|
248
|
+
function asEntryFormat(value) {
|
|
249
|
+
return ALL_FORMATS.includes(value) ? value : null;
|
|
250
|
+
}
|
|
251
|
+
var naturalCollator = new Intl.Collator(void 0, { numeric: true });
|
|
252
|
+
/**
|
|
253
|
+
* Compares two entry ids under `sort`. File order is no order of ids, so it
|
|
254
|
+
* compares them as astro does, for whatever the file does not place.
|
|
255
|
+
*/
|
|
256
|
+
function compareIds(sort) {
|
|
257
|
+
return sort === "natural" ? (a, b) => naturalCollator.compare(a, b) : (a, b) => a.localeCompare(b);
|
|
258
|
+
}
|
|
259
|
+
/** Entries by id under `sort`, or as given for file order, which the listing already is. */
|
|
260
|
+
function sortByIds(entries, sort) {
|
|
261
|
+
if (sort === "file") return [...entries];
|
|
262
|
+
const compare = compareIds(sort);
|
|
263
|
+
return entries.toSorted((a, b) => compare(a.id, b.id));
|
|
264
|
+
}
|
|
265
|
+
/** `derive` cached per manifest entry, which never changes once loaded. */
|
|
266
|
+
function perCollection(derive) {
|
|
267
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
268
|
+
return (col) => {
|
|
269
|
+
const cached = cache.get(col);
|
|
270
|
+
if (cached !== void 0) return cached;
|
|
271
|
+
const value = derive(col);
|
|
272
|
+
cache.set(col, value);
|
|
273
|
+
return value;
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* The files of a singleton, whose loader can only ever load the files it names,
|
|
278
|
+
* so the admin edits them directly and nothing may add, rename or remove one,
|
|
279
|
+
* which would only write a file the site never reads. That is the one file a
|
|
280
|
+
* literal pattern names, or, with content languages, one file per language for
|
|
281
|
+
* a pattern that is a language folder followed by a literal file, such as
|
|
282
|
+
* `*\/site.yaml`. Null for any other collection. Resolved once into the
|
|
283
|
+
* manifest, as {@link CollectionManifestEntry.singleton}.
|
|
284
|
+
*/
|
|
285
|
+
function findSingleton(col, i18n) {
|
|
286
|
+
const patterns = loaderPatterns(col);
|
|
287
|
+
const [pattern] = patterns;
|
|
288
|
+
if (col.loaderType !== "glob" || patterns.length !== 1 || !pattern) return null;
|
|
289
|
+
const [root] = globRoots(col);
|
|
290
|
+
if (root?.file) {
|
|
291
|
+
const main = globEntry(col, root.path);
|
|
292
|
+
return main && {
|
|
293
|
+
main,
|
|
294
|
+
translations: []
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
const slash = pattern.indexOf("/");
|
|
298
|
+
const file = pattern.slice(slash + 1);
|
|
299
|
+
if (!i18n || slash < 0 || picomatch.scan(file, { unescape: true }).isGlob) return null;
|
|
300
|
+
const entryIn = (locale) => globEntry(col, projectPath(collectionBase(col), joinLocale(locale, file)));
|
|
301
|
+
const main = entryIn(i18n.defaultLocale);
|
|
302
|
+
const translations = i18n.locales.filter((locale) => locale !== i18n.defaultLocale).map(entryIn);
|
|
303
|
+
return main && translations.every((entry) => entry !== null) ? {
|
|
304
|
+
main,
|
|
305
|
+
translations
|
|
306
|
+
} : null;
|
|
307
|
+
}
|
|
308
|
+
/** The ids of a singleton's entries, the main one first, none for any other collection. */
|
|
309
|
+
var singletonIds = ({ singleton }) => singleton ? [singleton.main, ...singleton.translations].map((entry) => entry.id) : [];
|
|
310
|
+
var ASTRO_CONFIG_FILES = new Set([
|
|
311
|
+
"js",
|
|
312
|
+
"ts",
|
|
313
|
+
"mjs"
|
|
314
|
+
].map((ext) => `src/content/config.${ext}`));
|
|
315
|
+
/** A glob collection's patterns, none for a loader that is neither `glob()` nor `file()`. */
|
|
316
|
+
function loaderPatterns(col) {
|
|
317
|
+
return [col.loaderPattern ?? []].flat();
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Whether astro's `glob()` loader of `col` loads a project-relative `path`,
|
|
321
|
+
* decided as astro decides it: `!` patterns ignore what the others match, and
|
|
322
|
+
* dotfiles and paths outside the base never match.
|
|
323
|
+
*/
|
|
324
|
+
var globMatcher = perCollection((col) => {
|
|
325
|
+
const patterns = loaderPatterns(col);
|
|
326
|
+
const ignore = patterns.filter((p) => p.startsWith("!")).map((p) => p.slice(1));
|
|
327
|
+
const isMatch = picomatch(patterns.filter((p) => !p.startsWith("!")), ignore.length > 0 ? { ignore } : void 0);
|
|
328
|
+
const base = collectionBase(col);
|
|
329
|
+
return (path) => {
|
|
330
|
+
const entry = relative(base, path);
|
|
331
|
+
return !entry.startsWith("../") && !ASTRO_CONFIG_FILES.has(path) && isMatch(entry);
|
|
332
|
+
};
|
|
333
|
+
});
|
|
334
|
+
/**
|
|
335
|
+
* Where a walk for a glob collection's files has to look: the static prefix of
|
|
336
|
+
* each pattern, a directory to descend into or, for a literal pattern, the one
|
|
337
|
+
* file it names. None lies inside another.
|
|
338
|
+
*/
|
|
339
|
+
function globRoots(col) {
|
|
340
|
+
const roots = loaderPatterns(col).filter((p) => !p.startsWith("!")).map((p) => {
|
|
341
|
+
const { base, isGlob } = picomatch.scan(p, { unescape: true });
|
|
342
|
+
return {
|
|
343
|
+
path: projectPath(collectionBase(col), base),
|
|
344
|
+
file: !isGlob
|
|
345
|
+
};
|
|
346
|
+
});
|
|
347
|
+
return roots.filter((root, index) => roots.findIndex((other) => other.path === root.path) === index && !roots.some((dir) => dir.path !== root.path && inGlobRoot(root.path, dir)));
|
|
348
|
+
}
|
|
349
|
+
/** Whether a walk from `root` reaches the project-relative `path`. */
|
|
350
|
+
function inGlobRoot(path, root) {
|
|
351
|
+
return root.file ? path === root.path : root.path === "" || path.startsWith(`${root.path}/`);
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* The id astro's default `generateId` gives the file at the base-relative
|
|
355
|
+
* `entry`: the `slug` its data sets, or else its path without the extension,
|
|
356
|
+
* each segment slugged and a trailing `/index` dropped.
|
|
357
|
+
*/
|
|
358
|
+
function astroEntryId(entry, data) {
|
|
359
|
+
if (data?.slug) return String(data.slug);
|
|
360
|
+
return entry.slice(0, entry.length - extname(entry).length).split("/").map((segment) => slug(segment)).join("/").replace(/\/index$/, "");
|
|
361
|
+
}
|
|
362
|
+
/** The id astro gives the entry in a glob collection's project-relative `path`, holding `data`. */
|
|
363
|
+
function globEntryId(col, path, data) {
|
|
364
|
+
return astroEntryId(relative(collectionBase(col), path), data);
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* The entry a glob collection's loader makes of the file at the project-relative
|
|
368
|
+
* `path`, or null for a file it does not load or the CMS cannot read. The one
|
|
369
|
+
* rule the storage listing, the changeset and the build map files with.
|
|
370
|
+
*/
|
|
371
|
+
function globEntry(col, path) {
|
|
372
|
+
const format = asEntryFormat(getFileExtension(path));
|
|
373
|
+
return format && globMatcher(col)(path) ? {
|
|
374
|
+
id: globEntryId(col, path),
|
|
375
|
+
format,
|
|
376
|
+
path
|
|
377
|
+
} : null;
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Project-relative directory a glob collection's loader reads from, the
|
|
381
|
+
* project root (`""`) as astro defaults it.
|
|
382
|
+
*/
|
|
383
|
+
function collectionBase(col) {
|
|
384
|
+
return col.loaderBase ?? "";
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Project-relative path of the file an entry's content goes to: the shared
|
|
388
|
+
* container in a file collection, and in a glob collection the file a literal
|
|
389
|
+
* pattern names for its id or else the id with the format's extension, whose
|
|
390
|
+
* astro id is the id itself whenever the id is slugged already. An existing
|
|
391
|
+
* entry's file is the one the listing reports, which astro may name differently.
|
|
392
|
+
*/
|
|
393
|
+
function entryFilePath(collection, id, format) {
|
|
394
|
+
if (collection.loaderType === "file" && collection.loaderFileName) return collection.loaderFileName;
|
|
395
|
+
return globRoots(collection).find((root) => root.file && getFileExtension(root.path) === format && globEntryId(collection, root.path) === id)?.path ?? join(collectionBase(collection), `${id}.${format}`);
|
|
396
|
+
}
|
|
397
|
+
export { getFileExtension as _, compareIds as a, serializeContent as b, globEntry as c, inGlobRoot as d, loaderPatterns as f, splitLocale as g, joinLocale as h, collectionBase as i, globEntryId as l, sortByIds as m, DATA_FORMATS as n, entryFilePath as o, singletonIds as p, asEntryFormat as r, findSingleton as s, ALL_FORMATS as t, globRoots as u, parseContent as v, serializeMultiEntryFile as x, parseMultiEntryFile as y };
|