@conloca/content-api 0.1.16 → 0.2.1
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/dist/asset-constraints.d.ts +16 -0
- package/dist/asset-constraints.d.ts.map +1 -0
- package/dist/asset-constraints.js +29 -0
- package/dist/asset-constraints.js.map +1 -0
- package/dist/asset-metadata-store.d.ts +60 -0
- package/dist/asset-metadata-store.d.ts.map +1 -0
- package/dist/asset-metadata-store.js +335 -0
- package/dist/asset-metadata-store.js.map +1 -0
- package/dist/asset-operations.d.ts +21 -28
- package/dist/asset-operations.d.ts.map +1 -1
- package/dist/asset-operations.js +268 -305
- package/dist/asset-operations.js.map +1 -0
- package/dist/asset-types.d.ts +23 -7
- package/dist/asset-types.d.ts.map +1 -1
- package/dist/asset-types.js +8 -2
- package/dist/asset-types.js.map +1 -0
- package/dist/asset-usage.d.ts +11 -0
- package/dist/asset-usage.d.ts.map +1 -0
- package/dist/asset-usage.js +50 -0
- package/dist/asset-usage.js.map +1 -0
- package/dist/base-content-index.d.ts +8 -2
- package/dist/base-content-index.d.ts.map +1 -1
- package/dist/base-content-index.js +24 -3
- package/dist/base-content-index.js.map +1 -0
- package/dist/cf-access.js +1 -0
- package/dist/cf-access.js.map +1 -0
- package/dist/component-registry.d.ts +1 -1
- package/dist/component-registry.d.ts.map +1 -1
- package/dist/component-registry.js +2 -1
- package/dist/component-registry.js.map +1 -0
- package/dist/component-registry.types.js +1 -0
- package/dist/component-registry.types.js.map +1 -0
- package/dist/component-vocabulary.d.ts +33 -0
- package/dist/component-vocabulary.d.ts.map +1 -0
- package/dist/component-vocabulary.js +105 -0
- package/dist/component-vocabulary.js.map +1 -0
- package/dist/content-api.interface.d.ts +5 -5
- package/dist/content-api.interface.d.ts.map +1 -1
- package/dist/content-api.interface.js +1 -0
- package/dist/content-api.interface.js.map +1 -0
- package/dist/content-filters.d.ts +2 -2
- package/dist/content-filters.d.ts.map +1 -1
- package/dist/content-filters.js +9 -8
- package/dist/content-filters.js.map +1 -0
- package/dist/content-index.d.ts +74 -16
- package/dist/content-index.d.ts.map +1 -1
- package/dist/content-index.js +183 -55
- package/dist/content-index.js.map +1 -0
- package/dist/content-operations.d.ts +71 -7
- package/dist/content-operations.d.ts.map +1 -1
- package/dist/content-operations.js +166 -82
- package/dist/content-operations.js.map +1 -0
- package/dist/content-path.d.ts +64 -0
- package/dist/content-path.d.ts.map +1 -0
- package/dist/content-path.js +95 -0
- package/dist/content-path.js.map +1 -0
- package/dist/content-reader.d.ts +2 -2
- package/dist/content-reader.d.ts.map +1 -1
- package/dist/content-reader.js +2 -1
- package/dist/content-reader.js.map +1 -0
- package/dist/content-utils.d.ts +53 -10
- package/dist/content-utils.d.ts.map +1 -1
- package/dist/content-utils.js +103 -34
- package/dist/content-utils.js.map +1 -0
- package/dist/content-watcher.d.ts +3 -3
- package/dist/content-watcher.d.ts.map +1 -1
- package/dist/content-watcher.js +13 -10
- package/dist/content-watcher.js.map +1 -0
- package/dist/data-index.d.ts +1 -1
- package/dist/data-index.d.ts.map +1 -1
- package/dist/data-index.js +2 -1
- package/dist/data-index.js.map +1 -0
- package/dist/data.d.ts +5 -13
- package/dist/data.d.ts.map +1 -1
- package/dist/data.js +7 -6
- package/dist/data.js.map +1 -0
- package/dist/editor-data-bindings.d.ts +10 -0
- package/dist/editor-data-bindings.d.ts.map +1 -0
- package/dist/editor-data-bindings.js +67 -0
- package/dist/editor-data-bindings.js.map +1 -0
- package/dist/etag-utils.d.ts.map +1 -1
- package/dist/etag-utils.js +5 -4
- package/dist/etag-utils.js.map +1 -0
- package/dist/filesystem-content-api.d.ts +45 -18
- package/dist/filesystem-content-api.d.ts.map +1 -1
- package/dist/filesystem-content-api.js +455 -286
- package/dist/filesystem-content-api.js.map +1 -0
- package/dist/filesystem-reader-backend.d.ts +46 -0
- package/dist/filesystem-reader-backend.d.ts.map +1 -0
- package/dist/filesystem-reader-backend.js +119 -0
- package/dist/filesystem-reader-backend.js.map +1 -0
- package/dist/fragment-index.d.ts +8 -0
- package/dist/fragment-index.d.ts.map +1 -0
- package/dist/fragment-index.js +8 -0
- package/dist/fragment-index.js.map +1 -0
- package/dist/fragments.d.ts +16 -0
- package/dist/fragments.d.ts.map +1 -0
- package/dist/fragments.js +104 -0
- package/dist/fragments.js.map +1 -0
- package/dist/git-operations.d.ts.map +1 -1
- package/dist/git-operations.js +5 -1
- package/dist/git-operations.js.map +1 -0
- package/dist/header-parser.d.ts +4 -4
- package/dist/header-parser.d.ts.map +1 -1
- package/dist/header-parser.js +8 -61
- package/dist/header-parser.js.map +1 -0
- package/dist/in-memory-content-api.d.ts +7 -7
- package/dist/in-memory-content-api.d.ts.map +1 -1
- package/dist/in-memory-content-api.js +74 -56
- package/dist/in-memory-content-api.js.map +1 -0
- package/dist/index.d.ts +19 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -9
- package/dist/index.js.map +1 -0
- package/dist/indexing.d.ts +4 -4
- package/dist/indexing.d.ts.map +1 -1
- package/dist/indexing.js +6 -5
- package/dist/indexing.js.map +1 -0
- package/dist/json-whitespace-view.js +1 -0
- package/dist/json-whitespace-view.js.map +1 -0
- package/dist/middleware.d.ts +8 -6
- package/dist/middleware.d.ts.map +1 -1
- package/dist/middleware.js +178 -142
- package/dist/middleware.js.map +1 -0
- package/dist/node.d.ts +24 -17
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +17 -14
- package/dist/node.js.map +1 -0
- package/dist/page-references.d.ts +21 -0
- package/dist/page-references.d.ts.map +1 -0
- package/dist/page-references.js +50 -0
- package/dist/page-references.js.map +1 -0
- package/dist/read-date.d.ts +3 -0
- package/dist/read-date.d.ts.map +1 -0
- package/dist/read-date.js +9 -0
- package/dist/read-date.js.map +1 -0
- package/dist/reader-backend.d.ts +54 -0
- package/dist/reader-backend.d.ts.map +1 -0
- package/dist/reader-backend.js +2 -0
- package/dist/reader-backend.js.map +1 -0
- package/dist/reader.d.ts +8 -8
- package/dist/reader.d.ts.map +1 -1
- package/dist/reader.js +8 -7
- package/dist/reader.js.map +1 -0
- package/dist/schemas/index.d.ts +6 -6
- package/dist/schemas/index.d.ts.map +1 -1
- package/dist/schemas/index.js +9 -8
- package/dist/schemas/index.js.map +1 -0
- package/dist/site-index.d.ts +3 -3
- package/dist/site-index.d.ts.map +1 -1
- package/dist/site-index.js +9 -5
- package/dist/site-index.js.map +1 -0
- package/dist/site.d.ts +5 -3
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +14 -2
- package/dist/site.js.map +1 -0
- package/dist/types.d.ts +203 -15
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/dist/url-safe-base64.js +1 -0
- package/dist/url-safe-base64.js.map +1 -0
- package/dist/url-validation.d.ts +14 -0
- package/dist/url-validation.d.ts.map +1 -1
- package/dist/url-validation.js +56 -14
- package/dist/url-validation.js.map +1 -0
- package/dist/utils/atomic-write.js +1 -0
- package/dist/utils/atomic-write.js.map +1 -0
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +2 -1
- package/dist/utils.js.map +1 -0
- package/dist/vite-plugin.d.ts +2 -2
- package/dist/vite-plugin.js +5 -4
- package/dist/vite-plugin.js.map +1 -0
- package/dist/vxjson-serialize.d.ts +5 -6
- package/dist/vxjson-serialize.d.ts.map +1 -1
- package/dist/vxjson-serialize.js +13 -10
- package/dist/vxjson-serialize.js.map +1 -0
- package/dist/vxjson.d.ts +4 -3
- package/dist/vxjson.d.ts.map +1 -1
- package/dist/vxjson.js +10 -20
- package/dist/vxjson.js.map +1 -0
- package/dist/xxhash.d.ts.map +1 -1
- package/dist/xxhash.js +6 -2
- package/dist/xxhash.js.map +1 -0
- package/package.json +92 -56
- package/src/asset-constraints.ts +33 -0
- package/src/asset-metadata-store.ts +401 -0
- package/src/asset-operations.ts +814 -0
- package/src/asset-types.ts +74 -0
- package/src/asset-usage.ts +48 -0
- package/src/base-content-index.ts +227 -0
- package/src/cf-access.ts +85 -0
- package/src/component-registry.ts +145 -0
- package/src/component-registry.types.ts +12 -0
- package/src/component-vocabulary.ts +87 -0
- package/src/content-api.interface.ts +94 -0
- package/src/content-filters.ts +278 -0
- package/src/content-index.ts +642 -0
- package/src/content-operations.ts +497 -0
- package/src/content-path.ts +121 -0
- package/src/content-reader.ts +18 -0
- package/src/content-utils.ts +474 -0
- package/src/content-watcher.ts +122 -0
- package/src/data-index.ts +7 -0
- package/src/data.ts +134 -0
- package/src/editor-data-bindings.ts +66 -0
- package/src/etag-utils.ts +204 -0
- package/src/filesystem-content-api.ts +2740 -0
- package/src/filesystem-reader-backend.ts +135 -0
- package/src/fragment-index.ts +7 -0
- package/src/fragments.ts +113 -0
- package/src/git-operations.ts +340 -0
- package/src/header-parser.ts +272 -0
- package/src/in-memory-content-api.ts +760 -0
- package/src/index.ts +45 -0
- package/src/indexing.ts +8 -0
- package/src/json-whitespace-view.ts +155 -0
- package/src/middleware.ts +1322 -0
- package/src/node.ts +40 -0
- package/src/page-references.ts +76 -0
- package/src/read-date.ts +7 -0
- package/src/reader-backend.ts +54 -0
- package/src/reader.ts +15 -0
- package/src/schemas/index.ts +113 -0
- package/src/site-index.ts +330 -0
- package/src/site.ts +198 -0
- package/src/types.ts +759 -0
- package/src/url-safe-base64.ts +38 -0
- package/src/url-validation.ts +121 -0
- package/src/utils/atomic-write.ts +20 -0
- package/src/utils.ts +84 -0
- package/src/vite-plugin.ts +45 -0
- package/src/vxjson-serialize.ts +66 -0
- package/src/vxjson.ts +442 -0
- package/src/xxhash.ts +43 -0
- package/dist/asset-manifest.d.ts +0 -23
- package/dist/asset-manifest.d.ts.map +0 -1
- package/dist/asset-manifest.js +0 -73
- package/dist/block-index.d.ts +0 -9
- package/dist/block-index.d.ts.map +0 -1
- package/dist/block-index.js +0 -11
- package/dist/blocks.d.ts +0 -16
- package/dist/blocks.d.ts.map +0 -1
- package/dist/blocks.js +0 -103
- package/dist/component-registry.types-C0ctF9nh.d.mts +0 -71
- package/dist/component-registry.types-C0ctF9nh.d.mts.map +0 -1
- package/dist/content-index-D092_vk1.mjs +0 -629
- package/dist/content-index-D092_vk1.mjs.map +0 -1
- package/dist/content-index-D6IVMmAB.d.mts +0 -127
- package/dist/content-index-D6IVMmAB.d.mts.map +0 -1
- package/dist/content-operations-DIbsxG5A.d.mts +0 -354
- package/dist/content-operations-DIbsxG5A.d.mts.map +0 -1
- package/dist/content-utils-fWNHTrPy.mjs +0 -280
- package/dist/content-utils-fWNHTrPy.mjs.map +0 -1
- package/dist/data-DquNIEnQ.mjs +0 -62
- package/dist/data-DquNIEnQ.mjs.map +0 -1
- package/dist/filesystem-content-api-B1KIQJfk.mjs +0 -2
- package/dist/filesystem-content-api-C0HIhqZi.mjs +0 -1620
- package/dist/filesystem-content-api-C0HIhqZi.mjs.map +0 -1
- package/dist/filesystem-content-api-DCdNi-co.d.mts +0 -134
- package/dist/filesystem-content-api-DCdNi-co.d.mts.map +0 -1
- package/dist/index-DxVTFK66.d.mts +0 -105
- package/dist/index-DxVTFK66.d.mts.map +0 -1
- package/dist/index.d.mts +0 -80
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs +0 -78
- package/dist/index.mjs.map +0 -1
- package/dist/indexing.d.mts +0 -152
- package/dist/indexing.d.mts.map +0 -1
- package/dist/indexing.mjs +0 -255
- package/dist/indexing.mjs.map +0 -1
- package/dist/node.d.mts +0 -373
- package/dist/node.d.mts.map +0 -1
- package/dist/node.mjs +0 -2572
- package/dist/node.mjs.map +0 -1
- package/dist/reader.d.mts +0 -15
- package/dist/reader.d.mts.map +0 -1
- package/dist/reader.mjs +0 -22
- package/dist/reader.mjs.map +0 -1
- package/dist/schemas/index.d.mts +0 -2
- package/dist/schemas/index.mjs +0 -2
- package/dist/schemas-CFRD0FIQ.mjs +0 -84
- package/dist/schemas-CFRD0FIQ.mjs.map +0 -1
- package/dist/site-8oaj1Q60.mjs +0 -366
- package/dist/site-8oaj1Q60.mjs.map +0 -1
- package/dist/site-index-B_254bCc.d.mts +0 -136
- package/dist/site-index-B_254bCc.d.mts.map +0 -1
- package/dist/types-DOdldbfD.mjs +0 -34
- package/dist/types-DOdldbfD.mjs.map +0 -1
- package/dist/types-DjfhS272.d.mts +0 -456
- package/dist/types-DjfhS272.d.mts.map +0 -1
- package/dist/vxjson-qHrgLGip.mjs +0 -555
- package/dist/vxjson-qHrgLGip.mjs.map +0 -1
- package/dist/vxjson-serialize-geF6qvpn.mjs +0 -34
- package/dist/vxjson-serialize-geF6qvpn.mjs.map +0 -1
- package/dist/vxjson-serialize.d.mts +0 -17
- package/dist/vxjson-serialize.d.mts.map +0 -1
- package/dist/vxjson-serialize.mjs +0 -2
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
import sortKeys from 'sort-keys';
|
|
2
|
+
import { invalidLocaleMessage, isContentLocale } from './content-path.js';
|
|
3
|
+
import { generateContentId, isContentPublished, normalizeAndValidatePathname } from './content-utils.js';
|
|
4
|
+
import type { Fragments } from './fragments.js';
|
|
5
|
+
import type { Site } from './site.js';
|
|
6
|
+
import type { ContentMeta, CreateContentInput, LocaleUpdateData, LocaleVersion } from './types.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Shared business logic for content operations
|
|
10
|
+
* Used by both FileSystemContentAPI and InMemoryContentAPI
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
// Validation result types
|
|
14
|
+
export interface ValidationResult {
|
|
15
|
+
valid: boolean;
|
|
16
|
+
error?: string;
|
|
17
|
+
sortedMeta?: ContentMeta;
|
|
18
|
+
size?: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface CreateValidationResult {
|
|
22
|
+
valid: boolean;
|
|
23
|
+
error?: string;
|
|
24
|
+
reason?:
|
|
25
|
+
| 'metadata_too_large'
|
|
26
|
+
| 'pathname_taken'
|
|
27
|
+
| 'pathname_in_redirects'
|
|
28
|
+
| 'invalid_pathname'
|
|
29
|
+
| 'invalid_name'
|
|
30
|
+
| 'name_taken'
|
|
31
|
+
| 'invalid_collection'
|
|
32
|
+
| 'invalid_locale'
|
|
33
|
+
| 'missing_field'
|
|
34
|
+
| 'unknown_site'
|
|
35
|
+
| 'no_sites_configured';
|
|
36
|
+
existingId?: string;
|
|
37
|
+
/** The input field a caller has to change, when the validator knows which one it is. */
|
|
38
|
+
field?: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Validate and prepare metadata for storage
|
|
43
|
+
* Ensures title exists and metadata doesn't exceed 4KB
|
|
44
|
+
*/
|
|
45
|
+
export function validateAndPrepareMetadata(meta: Partial<ContentMeta>): ValidationResult {
|
|
46
|
+
// Ensure title is present
|
|
47
|
+
if (!meta.title) {
|
|
48
|
+
return {
|
|
49
|
+
valid: false,
|
|
50
|
+
error: 'Title is required in metadata',
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const sortedMeta = sortKeys(meta, { deep: true }) as ContentMeta; // We've validated title exists
|
|
55
|
+
const metaJson = JSON.stringify(sortedMeta, null, 2);
|
|
56
|
+
const metaSize = new TextEncoder().encode(metaJson).length;
|
|
57
|
+
|
|
58
|
+
if (metaSize > 4088) {
|
|
59
|
+
// Leave 8 bytes for safety
|
|
60
|
+
return {
|
|
61
|
+
valid: false,
|
|
62
|
+
error: `Metadata exceeds 4KB limit (${metaSize} bytes)`,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
valid: true,
|
|
68
|
+
sortedMeta,
|
|
69
|
+
size: metaSize,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Build pathname history update
|
|
75
|
+
*/
|
|
76
|
+
export function buildPathnameHistory(
|
|
77
|
+
oldPathname: string | undefined,
|
|
78
|
+
newPathname: string | undefined,
|
|
79
|
+
isPublished: boolean,
|
|
80
|
+
now: string,
|
|
81
|
+
): Record<string, string> {
|
|
82
|
+
const history: Record<string, string> = {};
|
|
83
|
+
|
|
84
|
+
if (oldPathname && newPathname && oldPathname !== newPathname && isPublished) {
|
|
85
|
+
history[oldPathname] = now;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return history;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Build a locale manifest
|
|
93
|
+
*/
|
|
94
|
+
export function buildLocaleVersion(params: {
|
|
95
|
+
locale: string;
|
|
96
|
+
etag: string;
|
|
97
|
+
created: string;
|
|
98
|
+
modified: string;
|
|
99
|
+
meta: ContentMeta;
|
|
100
|
+
kind: 'fragment' | 'page' | 'data';
|
|
101
|
+
publishAt?: string;
|
|
102
|
+
unpublishAt?: string;
|
|
103
|
+
pathname?: string;
|
|
104
|
+
name?: string;
|
|
105
|
+
previousPathnames?: Record<string, string>;
|
|
106
|
+
}): LocaleVersion {
|
|
107
|
+
const manifest: LocaleVersion = {
|
|
108
|
+
locale: params.locale,
|
|
109
|
+
etag: params.etag,
|
|
110
|
+
created: params.created,
|
|
111
|
+
modified: params.modified,
|
|
112
|
+
meta: params.meta,
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
// Add optional fields only if they exist
|
|
116
|
+
if (params.publishAt) {
|
|
117
|
+
manifest.publishAt = params.publishAt;
|
|
118
|
+
}
|
|
119
|
+
if (params.unpublishAt) {
|
|
120
|
+
manifest.unpublishAt = params.unpublishAt;
|
|
121
|
+
}
|
|
122
|
+
if (params.pathname && params.kind === 'page') {
|
|
123
|
+
manifest.pathname = params.pathname;
|
|
124
|
+
}
|
|
125
|
+
if (params.name && (params.kind === 'fragment' || params.kind === 'data')) {
|
|
126
|
+
manifest.name = params.name;
|
|
127
|
+
}
|
|
128
|
+
if (params.previousPathnames && Object.keys(params.previousPathnames).length > 0) {
|
|
129
|
+
manifest.previousPathnames = params.previousPathnames;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return manifest;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Update publish dates on a locale manifest
|
|
137
|
+
*/
|
|
138
|
+
export function updatePublishDates(manifest: LocaleVersion, data: LocaleUpdateData): void {
|
|
139
|
+
// Handle publishAt
|
|
140
|
+
if ('publishAt' in data) {
|
|
141
|
+
if (data.publishAt && typeof data.publishAt === 'string') {
|
|
142
|
+
manifest.publishAt = data.publishAt;
|
|
143
|
+
} else {
|
|
144
|
+
// Explicitly delete the field when value is falsy
|
|
145
|
+
delete manifest.publishAt;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Handle unpublishAt
|
|
150
|
+
if ('unpublishAt' in data) {
|
|
151
|
+
if (data.unpublishAt && typeof data.unpublishAt === 'string') {
|
|
152
|
+
manifest.unpublishAt = data.unpublishAt;
|
|
153
|
+
} else {
|
|
154
|
+
// Explicitly delete the field when value is falsy
|
|
155
|
+
delete manifest.unpublishAt;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Validate content creation data
|
|
162
|
+
*/
|
|
163
|
+
export function validateCreateContent(
|
|
164
|
+
data: CreateContentInput,
|
|
165
|
+
sites: Record<string, Site>,
|
|
166
|
+
fragments: Fragments,
|
|
167
|
+
dataApi?: {
|
|
168
|
+
isDataNameValid: (name: string) => boolean;
|
|
169
|
+
getNameConflict: (collection: string, name: string) => string | null;
|
|
170
|
+
},
|
|
171
|
+
): CreateValidationResult {
|
|
172
|
+
const misplaced = checkEntryPlace(data.collection, Object.keys(data.locales));
|
|
173
|
+
if (misplaced) return misplaced;
|
|
174
|
+
|
|
175
|
+
// Validate metadata for all locales
|
|
176
|
+
for (const localeData of Object.values(data.locales)) {
|
|
177
|
+
const meta = { ...data.meta, ...localeData.meta };
|
|
178
|
+
const validation = validateAndPrepareMetadata(meta);
|
|
179
|
+
if (!validation.valid) {
|
|
180
|
+
return {
|
|
181
|
+
valid: false,
|
|
182
|
+
error: validation.error,
|
|
183
|
+
reason: 'metadata_too_large',
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Validate pathname for pages
|
|
189
|
+
if (data.kind === 'page') {
|
|
190
|
+
// A content root that declares no sites at all cannot take a page, whatever
|
|
191
|
+
// site the caller names. Blaming the `site` field here sends people hunting
|
|
192
|
+
// for a site name when the real cause is the missing config file.
|
|
193
|
+
if (Object.keys(sites).length === 0) {
|
|
194
|
+
return {
|
|
195
|
+
valid: false,
|
|
196
|
+
error: 'No sites are configured. Create content/sites.json, or run `conloca init <directory> <site-name>`.',
|
|
197
|
+
reason: 'no_sites_configured',
|
|
198
|
+
field: 'site',
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (!data.site) {
|
|
203
|
+
return {
|
|
204
|
+
valid: false,
|
|
205
|
+
error: 'Site is required for pages',
|
|
206
|
+
reason: 'missing_field',
|
|
207
|
+
field: 'site',
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// Own-key only: the site name is caller-supplied, so an inherited key like
|
|
212
|
+
// `constructor` used to pass this gate and then break on the non-Site.
|
|
213
|
+
const site = Object.hasOwn(sites, data.site) ? sites[data.site] : undefined;
|
|
214
|
+
if (!site) {
|
|
215
|
+
return {
|
|
216
|
+
valid: false,
|
|
217
|
+
error: `Site ${data.site} not found`,
|
|
218
|
+
reason: 'unknown_site',
|
|
219
|
+
field: 'site',
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const unsupported = checkPageLocales(data.site, site.locales, Object.keys(data.locales));
|
|
224
|
+
if (unsupported) return unsupported;
|
|
225
|
+
|
|
226
|
+
for (const [locale, localeData] of Object.entries(data.locales)) {
|
|
227
|
+
const pathname = localeData.pathname;
|
|
228
|
+
|
|
229
|
+
// Pathname is required for pages
|
|
230
|
+
if (!pathname) {
|
|
231
|
+
return {
|
|
232
|
+
valid: false,
|
|
233
|
+
error: `Pathname is required for pages (locale: ${locale})`,
|
|
234
|
+
reason: 'missing_field',
|
|
235
|
+
field: 'pathname',
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// The tidied path is written back to localeData so the rest of the
|
|
240
|
+
// create flow (file writes, indexing) sees the cleaned form.
|
|
241
|
+
const checked = checkPagePathname(site, pathname, locale);
|
|
242
|
+
if (!checked.valid) return checked;
|
|
243
|
+
localeData.pathname = checked.pathname;
|
|
244
|
+
|
|
245
|
+
// Check if pathname is in redirects
|
|
246
|
+
if (site.isPathnameInRedirects(checked.pathname, locale)) {
|
|
247
|
+
return {
|
|
248
|
+
valid: false,
|
|
249
|
+
error: `Pathname ${checked.pathname} is already in use as a redirect`,
|
|
250
|
+
reason: 'pathname_in_redirects',
|
|
251
|
+
field: 'pathname',
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// A fragment or data entry's name
|
|
258
|
+
if (data.kind === 'fragment') {
|
|
259
|
+
const refused = checkEntryName(
|
|
260
|
+
'fragment',
|
|
261
|
+
data.collection,
|
|
262
|
+
data.name,
|
|
263
|
+
(name) => fragments.isFragmentNameValid(name),
|
|
264
|
+
(name) => fragments.getNameConflict(data.collection, name),
|
|
265
|
+
);
|
|
266
|
+
if (refused) return refused;
|
|
267
|
+
}
|
|
268
|
+
if (data.kind === 'data' && dataApi) {
|
|
269
|
+
const refused = checkEntryName(
|
|
270
|
+
'data',
|
|
271
|
+
data.collection,
|
|
272
|
+
data.name,
|
|
273
|
+
(name) => dataApi.isDataNameValid(name),
|
|
274
|
+
(name) => dataApi.getNameConflict(data.collection, name),
|
|
275
|
+
);
|
|
276
|
+
if (refused) return refused;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return { valid: true };
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/** Why a new entry's collection or one of its locales cannot be part of its file path. */
|
|
283
|
+
export interface PlaceRefusal {
|
|
284
|
+
valid: false;
|
|
285
|
+
reason: 'invalid_collection' | 'invalid_locale';
|
|
286
|
+
error: string;
|
|
287
|
+
field: 'collection' | 'locales';
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Why a new entry cannot be stored in `collection` under `locales`, or null when it can. Both are
|
|
292
|
+
* part of the entry's file path, so a collection must be a plain folder name and a locale a
|
|
293
|
+
* language code the file layout reads back: '../x' in either would put the file somewhere else.
|
|
294
|
+
*/
|
|
295
|
+
export function checkEntryPlace(collection: string | undefined, locales: string[]): PlaceRefusal | null {
|
|
296
|
+
if (!collection) {
|
|
297
|
+
return { valid: false, reason: 'invalid_collection', error: 'Collection name is required', field: 'collection' };
|
|
298
|
+
}
|
|
299
|
+
if (!/^[a-zA-Z0-9_-]+$/.test(collection)) {
|
|
300
|
+
return {
|
|
301
|
+
valid: false,
|
|
302
|
+
reason: 'invalid_collection',
|
|
303
|
+
error: `Invalid collection name: ${collection}. Collection names must contain only alphanumeric characters, hyphens, and underscores.`,
|
|
304
|
+
field: 'collection',
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
const malformed = locales.find((locale) => !isContentLocale(locale));
|
|
308
|
+
if (malformed !== undefined) {
|
|
309
|
+
return {
|
|
310
|
+
valid: false,
|
|
311
|
+
reason: 'invalid_locale',
|
|
312
|
+
error: invalidLocaleMessage(malformed),
|
|
313
|
+
field: 'locales',
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
return null;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Why a new page of `site` cannot be stored under `locales`, or null when it can: each must be a
|
|
321
|
+
* language the site is set up for (`siteLocales`), in the same capitals. The site's pages are read
|
|
322
|
+
* back only in those languages, and a file in another one lands on a page's file: 'EN' on a macOS
|
|
323
|
+
* or Windows disk is the 'en' file, and in an MDX pages folder 'fr' is read as a path folder.
|
|
324
|
+
*/
|
|
325
|
+
export function checkPageLocales(site: string, siteLocales: readonly string[], locales: string[]): PlaceRefusal | null {
|
|
326
|
+
const unsupported = locales.find((locale) => !siteLocales.includes(locale));
|
|
327
|
+
if (unsupported === undefined) return null;
|
|
328
|
+
return {
|
|
329
|
+
valid: false,
|
|
330
|
+
reason: 'invalid_locale',
|
|
331
|
+
error: `Invalid locale: ${unsupported}. Site ${site} is set up for ${siteLocales.join(', ')}.`,
|
|
332
|
+
field: 'locales',
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/** Why a name cannot be a fragment or data entry's name, and the entry that has it when it is taken. */
|
|
337
|
+
export interface NameRefusal {
|
|
338
|
+
valid: false;
|
|
339
|
+
reason: 'invalid_name' | 'name_taken';
|
|
340
|
+
error: string;
|
|
341
|
+
existingId?: string;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Why `name` cannot be the name of a `kind` entry in `collection`, or null when it can: it is
|
|
346
|
+
* missing or malformed, or `conflictOf` finds another entry of the collection with it. The name is
|
|
347
|
+
* part of the entry's file path, so 'a/b' or '../x' would put the file somewhere else.
|
|
348
|
+
*/
|
|
349
|
+
export function checkEntryName(
|
|
350
|
+
kind: 'fragment' | 'data',
|
|
351
|
+
collection: string,
|
|
352
|
+
name: string | undefined,
|
|
353
|
+
isValid: (name: string) => boolean,
|
|
354
|
+
conflictOf: (name: string) => string | null,
|
|
355
|
+
): NameRefusal | null {
|
|
356
|
+
const label = kind === 'fragment' ? 'Fragment' : 'Data';
|
|
357
|
+
if (!name) {
|
|
358
|
+
return { valid: false, reason: 'invalid_name', error: `${label} name is required` };
|
|
359
|
+
}
|
|
360
|
+
if (!isValid(name)) {
|
|
361
|
+
return {
|
|
362
|
+
valid: false,
|
|
363
|
+
reason: 'invalid_name',
|
|
364
|
+
error: `Invalid ${kind} name: ${name}. ${label} names must contain only alphanumeric characters, hyphens, and underscores.`,
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
const existingId = conflictOf(name);
|
|
368
|
+
if (existingId) {
|
|
369
|
+
return {
|
|
370
|
+
valid: false,
|
|
371
|
+
reason: 'name_taken',
|
|
372
|
+
error: `${label} name ${name} already exists in collection ${collection}`,
|
|
373
|
+
existingId,
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
return null;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/** Why a path cannot be a page's path, and the page that has it when it is taken. */
|
|
380
|
+
export interface PathnameRefusal {
|
|
381
|
+
valid: false;
|
|
382
|
+
reason: 'invalid_pathname' | 'pathname_taken';
|
|
383
|
+
error: string;
|
|
384
|
+
existingId?: string;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* `pathname` tidied as a page's path in `locale`, or why it cannot be one: it is malformed, or
|
|
389
|
+
* another page has it. The path names the page's file, so '/../x' would write it outside the
|
|
390
|
+
* content folder, and '/about/' is the file of the page at '/about'. `excludeId` is a page whose
|
|
391
|
+
* own path is changing; it never blocks itself. Without a `site`, only the path's form is checked.
|
|
392
|
+
*/
|
|
393
|
+
export function checkPagePathname(
|
|
394
|
+
site: Site | undefined,
|
|
395
|
+
pathname: string,
|
|
396
|
+
locale: string,
|
|
397
|
+
excludeId?: string,
|
|
398
|
+
): { valid: true; pathname: string } | PathnameRefusal {
|
|
399
|
+
const validation = normalizeAndValidatePathname(pathname);
|
|
400
|
+
if (!validation.valid) {
|
|
401
|
+
return {
|
|
402
|
+
valid: false,
|
|
403
|
+
reason: 'invalid_pathname',
|
|
404
|
+
error: `Invalid pathname for locale ${locale}: ${validation.message}`,
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
const tidied = validation.value;
|
|
408
|
+
const existingId = site?.getPathnameConflict(tidied, locale, excludeId);
|
|
409
|
+
if (existingId) {
|
|
410
|
+
return { valid: false, reason: 'pathname_taken', error: `Pathname ${tidied} already exists`, existingId };
|
|
411
|
+
}
|
|
412
|
+
return { valid: true, pathname: tidied };
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Why a page cannot have `pathname` in `locale` in a site's MDX pages folder (sites.json
|
|
417
|
+
* `mdxPages`), or null when it can. In that folder a page's language is its first folder and a
|
|
418
|
+
* default-language page has none, so '/de/x' in the default language would be written to
|
|
419
|
+
* <folder>/de/x.mdx, the file of the German page at '/x', and read back as that page. `locales`
|
|
420
|
+
* are the languages the folder reads as a first folder. They match in any capitals: macOS and
|
|
421
|
+
* Windows disks treat <folder>/pt-br/x.mdx and <folder>/pt-BR/x.mdx as one file.
|
|
422
|
+
*/
|
|
423
|
+
export function checkMdxPagesPathname(
|
|
424
|
+
pathname: string,
|
|
425
|
+
locale: string,
|
|
426
|
+
folder: { defaultLocale: string; locales: Iterable<string> },
|
|
427
|
+
): PathnameRefusal | null {
|
|
428
|
+
if (locale !== folder.defaultLocale) return null;
|
|
429
|
+
const [first, ...rest] = pathname.slice(1).split('/');
|
|
430
|
+
if (rest.length === 0) return null;
|
|
431
|
+
const kept = [...folder.locales].find((folderLocale) => folderLocale.toLowerCase() === first.toLowerCase());
|
|
432
|
+
if (kept === undefined) return null;
|
|
433
|
+
return {
|
|
434
|
+
valid: false,
|
|
435
|
+
reason: 'invalid_pathname',
|
|
436
|
+
error: `Invalid pathname for locale ${locale}: Path cannot start with \`/${first}/\`: the MDX pages folder keeps the ${kept} pages there`,
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* Generate a new content ID
|
|
442
|
+
*/
|
|
443
|
+
/**
|
|
444
|
+
* Check if content is published
|
|
445
|
+
*/
|
|
446
|
+
export { generateContentId, isContentPublished };
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* Update scope bit flags
|
|
450
|
+
* Can be combined with bitwise OR and checked with bitwise AND
|
|
451
|
+
*/
|
|
452
|
+
export const UPDATE_SCOPE = {
|
|
453
|
+
NONE: 0, // 00
|
|
454
|
+
META: 1 << 0, // 01
|
|
455
|
+
CONTENT: 1 << 1, // 10
|
|
456
|
+
BOTH: 3, // 11 (META | CONTENT)
|
|
457
|
+
} as const;
|
|
458
|
+
|
|
459
|
+
export type UpdateScope = (typeof UPDATE_SCOPE)[keyof typeof UPDATE_SCOPE];
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* Determine what parts of content are being updated
|
|
463
|
+
* Returns bit flags that can be checked with bitwise AND
|
|
464
|
+
*
|
|
465
|
+
* Example usage:
|
|
466
|
+
* ```
|
|
467
|
+
* const scope = analyzeUpdateScope(data);
|
|
468
|
+
* if (scope & UPDATE_SCOPE.META) { // metadata is being updated }
|
|
469
|
+
* if (scope & UPDATE_SCOPE.CONTENT) { // content is being updated }
|
|
470
|
+
* if (scope === UPDATE_SCOPE.BOTH) { // both are being updated }
|
|
471
|
+
* ```
|
|
472
|
+
*/
|
|
473
|
+
export function analyzeUpdateScope(data: LocaleUpdateData): UpdateScope {
|
|
474
|
+
let scope = UPDATE_SCOPE.NONE;
|
|
475
|
+
|
|
476
|
+
// Note: pathname is NOT considered a metadata change because:
|
|
477
|
+
// - For pages, pathname is derived from file path, not stored in metadata
|
|
478
|
+
// - Pathname changes don't affect the metadata hash in the ETag
|
|
479
|
+
if (data.meta !== undefined || data.publishAt !== undefined || data.unpublishAt !== undefined) {
|
|
480
|
+
scope |= UPDATE_SCOPE.META;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
if (data.content !== undefined) {
|
|
484
|
+
scope |= UPDATE_SCOPE.CONTENT;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
return scope;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* Determine whether the modified timestamp should be updated
|
|
492
|
+
* Updates for ANY change - either metadata or content
|
|
493
|
+
*/
|
|
494
|
+
export function shouldUpdateModifiedTimestamp(data: LocaleUpdateData): boolean {
|
|
495
|
+
const scope = analyzeUpdateScope(data);
|
|
496
|
+
return scope !== UPDATE_SCOPE.NONE;
|
|
497
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ONE locale/path grammar for content files.
|
|
3
|
+
*
|
|
4
|
+
* Every reader that turns a storage path back into content identity parses it
|
|
5
|
+
* here: the pure header parser, the filesystem indexer, and any other reader
|
|
6
|
+
* of content files. Each of those used to carry its own copy of the
|
|
7
|
+
* regex and the copies disagreed — a copy that refused `about.EN.mdx`
|
|
8
|
+
* made content the index had accepted unreadable, and an indexer copy
|
|
9
|
+
* matching `\w+` filed `about.en-US.mdx` under a fallback locale with no
|
|
10
|
+
* pathname at all.
|
|
11
|
+
*
|
|
12
|
+
* Zero imports on purpose: some consumers embed this module where nothing
|
|
13
|
+
* effectful may run at import time.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A two-letter language subtag, optionally followed by a two-letter upper-case
|
|
18
|
+
* region (`en`, `nl`, `en-US`). Case is PRESERVED, never normalized: writers
|
|
19
|
+
* splice this exact string back into the filename (`getFilePath`, and any other
|
|
20
|
+
* writer of content files), so lower-casing it here would make a repo holding
|
|
21
|
+
* `about.EN.mdx` save its next edit to `about.en.mdx` and orphan the original.
|
|
22
|
+
*
|
|
23
|
+
* Wider BCP-47 forms (three-letter languages, script subtags like `zh-Hans`,
|
|
24
|
+
* lower-case regions) are deliberately NOT accepted: no spec text defines the
|
|
25
|
+
* grammar, and every writer in the system emits this shape today.
|
|
26
|
+
*/
|
|
27
|
+
const LOCALE_SUBTAG = '[a-zA-Z]{2}(?:-[A-Z]{2})?';
|
|
28
|
+
|
|
29
|
+
const LOCALE = new RegExp(`^${LOCALE_SUBTAG}$`);
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Whether `locale` is one this grammar reads back. A writer checks a new entry's locale with it:
|
|
33
|
+
* the locale is spliced into the file path, so anything else is either unreadable or, like
|
|
34
|
+
* '../x', a path out of the entry's folder.
|
|
35
|
+
*/
|
|
36
|
+
export function isContentLocale(locale: string): boolean {
|
|
37
|
+
return LOCALE.test(locale);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Why `locale` cannot name content files, in the words every refusal of one uses: creating an
|
|
42
|
+
* entry in it, a sites.json that declares it, and `conloca doctor`.
|
|
43
|
+
*/
|
|
44
|
+
export function invalidLocaleMessage(locale: string): string {
|
|
45
|
+
return `Invalid locale: ${locale}. A locale is a two-letter language code, optionally with a region, like en or en-US.`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** `<base>.<locale>.<ext>` — the filename half of every content layout. */
|
|
49
|
+
const LOCALE_FILENAME = new RegExp(`^(.+)\\.(${LOCALE_SUBTAG})\\.(mdx|vxjson|json)$`);
|
|
50
|
+
|
|
51
|
+
export type ContentFileExtension = 'mdx' | 'vxjson' | 'json';
|
|
52
|
+
|
|
53
|
+
export interface LocaleFilename {
|
|
54
|
+
/** Filename with the `.<locale>.<ext>` suffix removed. */
|
|
55
|
+
base: string;
|
|
56
|
+
/** Locale exactly as written in the filename. */
|
|
57
|
+
locale: string;
|
|
58
|
+
extension: ContentFileExtension;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Split `<base>.<locale>.<ext>`. Null when the filename carries no locale suffix. */
|
|
62
|
+
export function parseLocaleFilename(filename: string): LocaleFilename | null {
|
|
63
|
+
const match = LOCALE_FILENAME.exec(filename);
|
|
64
|
+
if (!match) return null;
|
|
65
|
+
return { base: match[1], locale: match[2], extension: match[3] as ContentFileExtension };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface ContentPathLayout {
|
|
69
|
+
kind: 'fragment' | 'page' | 'data';
|
|
70
|
+
site?: string;
|
|
71
|
+
collection: string;
|
|
72
|
+
locale: string;
|
|
73
|
+
pathname?: string;
|
|
74
|
+
name?: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Pure path → identity mapper. Returns null when the path doesn't match any
|
|
79
|
+
* supported layout or lacks an explicit locale suffix.
|
|
80
|
+
*
|
|
81
|
+
* Layouts honoured here mirror filesystem-content-api.ts:137-144:
|
|
82
|
+
*
|
|
83
|
+
* - `fragments/<collection>/<name>.<locale>.{mdx,vxjson}` (collection required;
|
|
84
|
+
* `fragments/<name>.<locale>.ext` is a legacy form that FileSystemContentAPI
|
|
85
|
+
* repairs by renaming. The pure parser refuses it.)
|
|
86
|
+
* - `data/<collection>/<name>.<locale>.json`
|
|
87
|
+
* - `<site>/<collection>/<path...>/<file>.<locale>.{vxjson,mdx}` (pages; `index`
|
|
88
|
+
* basename maps to the parent path).
|
|
89
|
+
*
|
|
90
|
+
* Reads accept .mdx pages even though the filesystem writer emits main-layout
|
|
91
|
+
* pages as .vxjson only (its mdx pages live under the separate mdxPagesRoot):
|
|
92
|
+
* another writer may derive the extension from the content type, so an
|
|
93
|
+
* mdx-typed page can land here as <site>/pages/<f>.<l>.mdx and must re-parse —
|
|
94
|
+
* dropping it made written pages unreadable.
|
|
95
|
+
*/
|
|
96
|
+
export function parseContentPathLayout(path: string): ContentPathLayout | null {
|
|
97
|
+
const parts = path.split('/').filter(Boolean);
|
|
98
|
+
if (parts.length < 3) return null;
|
|
99
|
+
|
|
100
|
+
const suffix = parseLocaleFilename(parts[parts.length - 1]);
|
|
101
|
+
if (!suffix) return null;
|
|
102
|
+
|
|
103
|
+
if (parts[0] === 'fragments') {
|
|
104
|
+
if (parts.length !== 3 || suffix.extension === 'json') return null;
|
|
105
|
+
return { kind: 'fragment', collection: parts[1], name: suffix.base, locale: suffix.locale };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (parts[0] === 'data') {
|
|
109
|
+
if (parts.length !== 3 || suffix.extension !== 'json') return null;
|
|
110
|
+
return { kind: 'data', collection: parts[1], name: suffix.base, locale: suffix.locale };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (suffix.extension === 'json') return null;
|
|
114
|
+
|
|
115
|
+
const pathParts = parts.slice(2);
|
|
116
|
+
pathParts[pathParts.length - 1] = suffix.base;
|
|
117
|
+
const pathname =
|
|
118
|
+
pathParts[pathParts.length - 1] === 'index' ? `/${pathParts.slice(0, -1).join('/')}` : `/${pathParts.join('/')}`;
|
|
119
|
+
|
|
120
|
+
return { kind: 'page', site: parts[0], collection: parts[1], locale: suffix.locale, pathname };
|
|
121
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ContentAPIOptions } from './types.js';
|
|
2
|
+
|
|
3
|
+
export type ContentReaderOptions = ContentAPIOptions;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates a read-oriented content API instance for build-time consumers.
|
|
7
|
+
*
|
|
8
|
+
* The filesystem implementation is loaded lazily so build tooling does not
|
|
9
|
+
* eagerly traverse native hashing dependencies through the reader entrypoint.
|
|
10
|
+
*/
|
|
11
|
+
export async function createContentAPI(options: ContentReaderOptions) {
|
|
12
|
+
const { FileSystemContentAPI: ReaderAPI } = await import('./filesystem-content-api.js');
|
|
13
|
+
|
|
14
|
+
return ReaderAPI.create({
|
|
15
|
+
...options,
|
|
16
|
+
canvasDir: options.canvasDir || './canvas',
|
|
17
|
+
});
|
|
18
|
+
}
|