@conloca/content-api 0.1.16 → 0.2.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/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 +18 -13
- package/dist/asset-operations.d.ts.map +1 -1
- package/dist/asset-operations.js +302 -254
- 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 +10 -0
- package/dist/asset-usage.d.ts.map +1 -0
- package/dist/asset-usage.js +49 -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 +59 -0
- package/dist/content-path.d.ts.map +1 -0
- package/dist/content-path.js +88 -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 +407 -281
- 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 +6 -6
- package/dist/middleware.d.ts.map +1 -1
- package/dist/middleware.js +170 -119
- 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 +914 -0
- package/src/asset-types.ts +74 -0
- package/src/asset-usage.ts +47 -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 +113 -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 +2685 -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 +1341 -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
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import type { Site } from './site';
|
|
4
|
-
import type { ContentMeta, CreateContentInput, LocaleUpdateData, LocaleVersion } from './types';
|
|
1
|
+
import { generateContentId, isContentPublished } from './content-utils.js';
|
|
2
|
+
import type { Fragments } from './fragments.js';
|
|
3
|
+
import type { Site } from './site.js';
|
|
4
|
+
import type { ContentMeta, CreateContentInput, LocaleUpdateData, LocaleVersion } from './types.js';
|
|
5
5
|
/**
|
|
6
6
|
* Shared business logic for content operations
|
|
7
7
|
* Used by both FileSystemContentAPI and InMemoryContentAPI
|
|
@@ -15,8 +15,10 @@ export interface ValidationResult {
|
|
|
15
15
|
export interface CreateValidationResult {
|
|
16
16
|
valid: boolean;
|
|
17
17
|
error?: string;
|
|
18
|
-
reason?: 'metadata_too_large' | 'pathname_taken' | 'pathname_in_redirects' | 'invalid_pathname' | 'invalid_name' | 'name_taken';
|
|
18
|
+
reason?: 'metadata_too_large' | 'pathname_taken' | 'pathname_in_redirects' | 'invalid_pathname' | 'invalid_name' | 'name_taken' | 'invalid_collection' | 'invalid_locale' | 'missing_field' | 'unknown_site' | 'no_sites_configured';
|
|
19
19
|
existingId?: string;
|
|
20
|
+
/** The input field a caller has to change, when the validator knows which one it is. */
|
|
21
|
+
field?: string;
|
|
20
22
|
}
|
|
21
23
|
/**
|
|
22
24
|
* Validate and prepare metadata for storage
|
|
@@ -36,7 +38,7 @@ export declare function buildLocaleVersion(params: {
|
|
|
36
38
|
created: string;
|
|
37
39
|
modified: string;
|
|
38
40
|
meta: ContentMeta;
|
|
39
|
-
kind: '
|
|
41
|
+
kind: 'fragment' | 'page' | 'data';
|
|
40
42
|
publishAt?: string;
|
|
41
43
|
unpublishAt?: string;
|
|
42
44
|
pathname?: string;
|
|
@@ -50,10 +52,72 @@ export declare function updatePublishDates(manifest: LocaleVersion, data: Locale
|
|
|
50
52
|
/**
|
|
51
53
|
* Validate content creation data
|
|
52
54
|
*/
|
|
53
|
-
export declare function validateCreateContent(data: CreateContentInput, sites: Record<string, Site>,
|
|
55
|
+
export declare function validateCreateContent(data: CreateContentInput, sites: Record<string, Site>, fragments: Fragments, dataApi?: {
|
|
54
56
|
isDataNameValid: (name: string) => boolean;
|
|
55
57
|
getNameConflict: (collection: string, name: string) => string | null;
|
|
56
58
|
}): CreateValidationResult;
|
|
59
|
+
/** Why a new entry's collection or one of its locales cannot be part of its file path. */
|
|
60
|
+
export interface PlaceRefusal {
|
|
61
|
+
valid: false;
|
|
62
|
+
reason: 'invalid_collection' | 'invalid_locale';
|
|
63
|
+
error: string;
|
|
64
|
+
field: 'collection' | 'locales';
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Why a new entry cannot be stored in `collection` under `locales`, or null when it can. Both are
|
|
68
|
+
* part of the entry's file path, so a collection must be a plain folder name and a locale a
|
|
69
|
+
* language code the file layout reads back: '../x' in either would put the file somewhere else.
|
|
70
|
+
*/
|
|
71
|
+
export declare function checkEntryPlace(collection: string | undefined, locales: string[]): PlaceRefusal | null;
|
|
72
|
+
/**
|
|
73
|
+
* Why a new page of `site` cannot be stored under `locales`, or null when it can: each must be a
|
|
74
|
+
* language the site is set up for (`siteLocales`), in the same capitals. The site's pages are read
|
|
75
|
+
* back only in those languages, and a file in another one lands on a page's file: 'EN' on a macOS
|
|
76
|
+
* or Windows disk is the 'en' file, and in an MDX pages folder 'fr' is read as a path folder.
|
|
77
|
+
*/
|
|
78
|
+
export declare function checkPageLocales(site: string, siteLocales: readonly string[], locales: string[]): PlaceRefusal | null;
|
|
79
|
+
/** Why a name cannot be a fragment or data entry's name, and the entry that has it when it is taken. */
|
|
80
|
+
export interface NameRefusal {
|
|
81
|
+
valid: false;
|
|
82
|
+
reason: 'invalid_name' | 'name_taken';
|
|
83
|
+
error: string;
|
|
84
|
+
existingId?: string;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Why `name` cannot be the name of a `kind` entry in `collection`, or null when it can: it is
|
|
88
|
+
* missing or malformed, or `conflictOf` finds another entry of the collection with it. The name is
|
|
89
|
+
* part of the entry's file path, so 'a/b' or '../x' would put the file somewhere else.
|
|
90
|
+
*/
|
|
91
|
+
export declare function checkEntryName(kind: 'fragment' | 'data', collection: string, name: string | undefined, isValid: (name: string) => boolean, conflictOf: (name: string) => string | null): NameRefusal | null;
|
|
92
|
+
/** Why a path cannot be a page's path, and the page that has it when it is taken. */
|
|
93
|
+
export interface PathnameRefusal {
|
|
94
|
+
valid: false;
|
|
95
|
+
reason: 'invalid_pathname' | 'pathname_taken';
|
|
96
|
+
error: string;
|
|
97
|
+
existingId?: string;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* `pathname` tidied as a page's path in `locale`, or why it cannot be one: it is malformed, or
|
|
101
|
+
* another page has it. The path names the page's file, so '/../x' would write it outside the
|
|
102
|
+
* content folder, and '/about/' is the file of the page at '/about'. `excludeId` is a page whose
|
|
103
|
+
* own path is changing; it never blocks itself. Without a `site`, only the path's form is checked.
|
|
104
|
+
*/
|
|
105
|
+
export declare function checkPagePathname(site: Site | undefined, pathname: string, locale: string, excludeId?: string): {
|
|
106
|
+
valid: true;
|
|
107
|
+
pathname: string;
|
|
108
|
+
} | PathnameRefusal;
|
|
109
|
+
/**
|
|
110
|
+
* Why a page cannot have `pathname` in `locale` in a site's MDX pages folder (sites.json
|
|
111
|
+
* `mdxPages`), or null when it can. In that folder a page's language is its first folder and a
|
|
112
|
+
* default-language page has none, so '/de/x' in the default language would be written to
|
|
113
|
+
* <folder>/de/x.mdx, the file of the German page at '/x', and read back as that page. `locales`
|
|
114
|
+
* are the languages the folder reads as a first folder. They match in any capitals: macOS and
|
|
115
|
+
* Windows disks treat <folder>/pt-br/x.mdx and <folder>/pt-BR/x.mdx as one file.
|
|
116
|
+
*/
|
|
117
|
+
export declare function checkMdxPagesPathname(pathname: string, locale: string, folder: {
|
|
118
|
+
defaultLocale: string;
|
|
119
|
+
locales: Iterable<string>;
|
|
120
|
+
}): PathnameRefusal | null;
|
|
57
121
|
/**
|
|
58
122
|
* Generate a new content ID
|
|
59
123
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-operations.d.ts","sourceRoot":"","sources":["../src/content-operations.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"content-operations.d.ts","sourceRoot":"","sources":["../src/content-operations.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAgC,MAAM,oBAAoB,CAAC;AACzG,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEnG;;;GAGG;AAGH,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,WAAW,CAAC;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,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;AACrF,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,KAAK,CAAC;IACb,MAAM,EAAE,kBAAkB,GAAG,gBAAgB,CAAC;IAC9C,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,IAAI,GAAG,SAAS,EACtB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,SAAS,CAAC,EAAE,MAAM,GACjB;IAAE,KAAK,EAAE,IAAI,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,eAAe,CAerD;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE;IAAE,aAAa,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAA;CAAE,GAC3D,eAAe,GAAG,IAAI,CAWxB;AAED;;GAEG;AACH;;GAEG;AACH,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,CAAC;AAEjD;;;GAGG;AACH,eAAO,MAAM,YAAY;aACvB,IAAI,EAAE,CAAC;aACP,IAAI;aACJ,OAAO;aACP,IAAI,EAAE,CAAC;CACC,CAAC;AAEX,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,OAAO,YAAY,CAAC,CAAC;AAE3E;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,gBAAgB,GAAG,WAAW,CAetE;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAG7E"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import sortKeys from 'sort-keys';
|
|
2
|
-
import {
|
|
2
|
+
import { isContentLocale } from './content-path.js';
|
|
3
|
+
import { generateContentId, isContentPublished, normalizeAndValidatePathname } from './content-utils.js';
|
|
3
4
|
/**
|
|
4
5
|
* Validate and prepare metadata for storage
|
|
5
6
|
* Ensures title exists and metadata doesn't exceed 4KB
|
|
@@ -59,7 +60,7 @@ export function buildLocaleVersion(params) {
|
|
|
59
60
|
if (params.pathname && params.kind === 'page') {
|
|
60
61
|
manifest.pathname = params.pathname;
|
|
61
62
|
}
|
|
62
|
-
if (params.name && (params.kind === '
|
|
63
|
+
if (params.name && (params.kind === 'fragment' || params.kind === 'data')) {
|
|
63
64
|
manifest.name = params.name;
|
|
64
65
|
}
|
|
65
66
|
if (params.previousPathnames && Object.keys(params.previousPathnames).length > 0) {
|
|
@@ -95,7 +96,10 @@ export function updatePublishDates(manifest, data) {
|
|
|
95
96
|
/**
|
|
96
97
|
* Validate content creation data
|
|
97
98
|
*/
|
|
98
|
-
export function validateCreateContent(data, sites,
|
|
99
|
+
export function validateCreateContent(data, sites, fragments, dataApi) {
|
|
100
|
+
const misplaced = checkEntryPlace(data.collection, Object.keys(data.locales));
|
|
101
|
+
if (misplaced)
|
|
102
|
+
return misplaced;
|
|
99
103
|
// Validate metadata for all locales
|
|
100
104
|
for (const localeData of Object.values(data.locales)) {
|
|
101
105
|
const meta = { ...data.meta, ...localeData.meta };
|
|
@@ -110,19 +114,39 @@ export function validateCreateContent(data, sites, blocks, dataApi) {
|
|
|
110
114
|
}
|
|
111
115
|
// Validate pathname for pages
|
|
112
116
|
if (data.kind === 'page') {
|
|
117
|
+
// A content root that declares no sites at all cannot take a page, whatever
|
|
118
|
+
// site the caller names. Blaming the `site` field here sends people hunting
|
|
119
|
+
// for a site name when the real cause is the missing config file.
|
|
120
|
+
if (Object.keys(sites).length === 0) {
|
|
121
|
+
return {
|
|
122
|
+
valid: false,
|
|
123
|
+
error: 'No sites are configured. Create content/sites.json, or run `conloca init <directory> <site-name>`.',
|
|
124
|
+
reason: 'no_sites_configured',
|
|
125
|
+
field: 'site',
|
|
126
|
+
};
|
|
127
|
+
}
|
|
113
128
|
if (!data.site) {
|
|
114
129
|
return {
|
|
115
130
|
valid: false,
|
|
116
131
|
error: 'Site is required for pages',
|
|
132
|
+
reason: 'missing_field',
|
|
133
|
+
field: 'site',
|
|
117
134
|
};
|
|
118
135
|
}
|
|
119
|
-
|
|
136
|
+
// Own-key only: the site name is caller-supplied, so an inherited key like
|
|
137
|
+
// `constructor` used to pass this gate and then break on the non-Site.
|
|
138
|
+
const site = Object.hasOwn(sites, data.site) ? sites[data.site] : undefined;
|
|
120
139
|
if (!site) {
|
|
121
140
|
return {
|
|
122
141
|
valid: false,
|
|
123
142
|
error: `Site ${data.site} not found`,
|
|
143
|
+
reason: 'unknown_site',
|
|
144
|
+
field: 'site',
|
|
124
145
|
};
|
|
125
146
|
}
|
|
147
|
+
const unsupported = checkPageLocales(data.site, site.locales, Object.keys(data.locales));
|
|
148
|
+
if (unsupported)
|
|
149
|
+
return unsupported;
|
|
126
150
|
for (const [locale, localeData] of Object.entries(data.locales)) {
|
|
127
151
|
const pathname = localeData.pathname;
|
|
128
152
|
// Pathname is required for pages
|
|
@@ -130,99 +154,158 @@ export function validateCreateContent(data, sites, blocks, dataApi) {
|
|
|
130
154
|
return {
|
|
131
155
|
valid: false,
|
|
132
156
|
error: `Pathname is required for pages (locale: ${locale})`,
|
|
157
|
+
reason: 'missing_field',
|
|
158
|
+
field: 'pathname',
|
|
133
159
|
};
|
|
134
160
|
}
|
|
135
|
-
//
|
|
136
|
-
//
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
valid: false,
|
|
142
|
-
error: `Invalid pathname for locale ${locale}: ${validation.message}`,
|
|
143
|
-
reason: 'invalid_pathname',
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
localeData.pathname = validation.value;
|
|
147
|
-
const normalized = validation.value;
|
|
148
|
-
// Check if pathname is already taken
|
|
149
|
-
const existingId = site.getPathnameConflict(normalized, locale);
|
|
150
|
-
if (existingId) {
|
|
151
|
-
return {
|
|
152
|
-
valid: false,
|
|
153
|
-
error: `Pathname ${normalized} already exists`,
|
|
154
|
-
reason: 'pathname_taken',
|
|
155
|
-
existingId,
|
|
156
|
-
};
|
|
157
|
-
}
|
|
161
|
+
// The tidied path is written back to localeData so the rest of the
|
|
162
|
+
// create flow (file writes, indexing) sees the cleaned form.
|
|
163
|
+
const checked = checkPagePathname(site, pathname, locale);
|
|
164
|
+
if (!checked.valid)
|
|
165
|
+
return checked;
|
|
166
|
+
localeData.pathname = checked.pathname;
|
|
158
167
|
// Check if pathname is in redirects
|
|
159
|
-
if (site.isPathnameInRedirects(
|
|
168
|
+
if (site.isPathnameInRedirects(checked.pathname, locale)) {
|
|
160
169
|
return {
|
|
161
170
|
valid: false,
|
|
162
|
-
error: `Pathname ${
|
|
171
|
+
error: `Pathname ${checked.pathname} is already in use as a redirect`,
|
|
163
172
|
reason: 'pathname_in_redirects',
|
|
173
|
+
field: 'pathname',
|
|
164
174
|
};
|
|
165
175
|
}
|
|
166
176
|
}
|
|
167
177
|
}
|
|
168
|
-
//
|
|
169
|
-
if (data.kind === '
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
error: 'Block name is required',
|
|
174
|
-
reason: 'invalid_name',
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
// Validate block name format
|
|
178
|
-
if (!blocks.isBlockNameValid(data.name)) {
|
|
179
|
-
return {
|
|
180
|
-
valid: false,
|
|
181
|
-
error: `Invalid block name: ${data.name}. Block names must contain only alphanumeric characters, hyphens, and underscores.`,
|
|
182
|
-
reason: 'invalid_name',
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
// Check if name is already taken in any locale
|
|
186
|
-
const existingId = blocks.getNameConflict(data.collection, data.name);
|
|
187
|
-
if (existingId) {
|
|
188
|
-
return {
|
|
189
|
-
valid: false,
|
|
190
|
-
error: `Block name ${data.name} already exists in collection ${data.collection}`,
|
|
191
|
-
reason: 'name_taken',
|
|
192
|
-
existingId,
|
|
193
|
-
};
|
|
194
|
-
}
|
|
178
|
+
// A fragment or data entry's name
|
|
179
|
+
if (data.kind === 'fragment') {
|
|
180
|
+
const refused = checkEntryName('fragment', data.collection, data.name, (name) => fragments.isFragmentNameValid(name), (name) => fragments.getNameConflict(data.collection, name));
|
|
181
|
+
if (refused)
|
|
182
|
+
return refused;
|
|
195
183
|
}
|
|
196
|
-
// Validate data entry name uniqueness
|
|
197
184
|
if (data.kind === 'data' && dataApi) {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
error: 'Data name is required',
|
|
202
|
-
reason: 'invalid_name',
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
// Validate data name format
|
|
206
|
-
if (!dataApi.isDataNameValid(data.name)) {
|
|
207
|
-
return {
|
|
208
|
-
valid: false,
|
|
209
|
-
error: `Invalid data name: ${data.name}. Data names must contain only alphanumeric characters, hyphens, and underscores.`,
|
|
210
|
-
reason: 'invalid_name',
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
// Check if name is already taken in any locale
|
|
214
|
-
const existingId = dataApi.getNameConflict(data.collection, data.name);
|
|
215
|
-
if (existingId) {
|
|
216
|
-
return {
|
|
217
|
-
valid: false,
|
|
218
|
-
error: `Data name ${data.name} already exists in collection ${data.collection}`,
|
|
219
|
-
reason: 'name_taken',
|
|
220
|
-
existingId,
|
|
221
|
-
};
|
|
222
|
-
}
|
|
185
|
+
const refused = checkEntryName('data', data.collection, data.name, (name) => dataApi.isDataNameValid(name), (name) => dataApi.getNameConflict(data.collection, name));
|
|
186
|
+
if (refused)
|
|
187
|
+
return refused;
|
|
223
188
|
}
|
|
224
189
|
return { valid: true };
|
|
225
190
|
}
|
|
191
|
+
/**
|
|
192
|
+
* Why a new entry cannot be stored in `collection` under `locales`, or null when it can. Both are
|
|
193
|
+
* part of the entry's file path, so a collection must be a plain folder name and a locale a
|
|
194
|
+
* language code the file layout reads back: '../x' in either would put the file somewhere else.
|
|
195
|
+
*/
|
|
196
|
+
export function checkEntryPlace(collection, locales) {
|
|
197
|
+
if (!collection) {
|
|
198
|
+
return { valid: false, reason: 'invalid_collection', error: 'Collection name is required', field: 'collection' };
|
|
199
|
+
}
|
|
200
|
+
if (!/^[a-zA-Z0-9_-]+$/.test(collection)) {
|
|
201
|
+
return {
|
|
202
|
+
valid: false,
|
|
203
|
+
reason: 'invalid_collection',
|
|
204
|
+
error: `Invalid collection name: ${collection}. Collection names must contain only alphanumeric characters, hyphens, and underscores.`,
|
|
205
|
+
field: 'collection',
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
const malformed = locales.find((locale) => !isContentLocale(locale));
|
|
209
|
+
if (malformed !== undefined) {
|
|
210
|
+
return {
|
|
211
|
+
valid: false,
|
|
212
|
+
reason: 'invalid_locale',
|
|
213
|
+
error: `Invalid locale: ${malformed}. A locale is a two-letter language code, optionally with a region, like en or en-US.`,
|
|
214
|
+
field: 'locales',
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Why a new page of `site` cannot be stored under `locales`, or null when it can: each must be a
|
|
221
|
+
* language the site is set up for (`siteLocales`), in the same capitals. The site's pages are read
|
|
222
|
+
* back only in those languages, and a file in another one lands on a page's file: 'EN' on a macOS
|
|
223
|
+
* or Windows disk is the 'en' file, and in an MDX pages folder 'fr' is read as a path folder.
|
|
224
|
+
*/
|
|
225
|
+
export function checkPageLocales(site, siteLocales, locales) {
|
|
226
|
+
const unsupported = locales.find((locale) => !siteLocales.includes(locale));
|
|
227
|
+
if (unsupported === undefined)
|
|
228
|
+
return null;
|
|
229
|
+
return {
|
|
230
|
+
valid: false,
|
|
231
|
+
reason: 'invalid_locale',
|
|
232
|
+
error: `Invalid locale: ${unsupported}. Site ${site} is set up for ${siteLocales.join(', ')}.`,
|
|
233
|
+
field: 'locales',
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Why `name` cannot be the name of a `kind` entry in `collection`, or null when it can: it is
|
|
238
|
+
* missing or malformed, or `conflictOf` finds another entry of the collection with it. The name is
|
|
239
|
+
* part of the entry's file path, so 'a/b' or '../x' would put the file somewhere else.
|
|
240
|
+
*/
|
|
241
|
+
export function checkEntryName(kind, collection, name, isValid, conflictOf) {
|
|
242
|
+
const label = kind === 'fragment' ? 'Fragment' : 'Data';
|
|
243
|
+
if (!name) {
|
|
244
|
+
return { valid: false, reason: 'invalid_name', error: `${label} name is required` };
|
|
245
|
+
}
|
|
246
|
+
if (!isValid(name)) {
|
|
247
|
+
return {
|
|
248
|
+
valid: false,
|
|
249
|
+
reason: 'invalid_name',
|
|
250
|
+
error: `Invalid ${kind} name: ${name}. ${label} names must contain only alphanumeric characters, hyphens, and underscores.`,
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
const existingId = conflictOf(name);
|
|
254
|
+
if (existingId) {
|
|
255
|
+
return {
|
|
256
|
+
valid: false,
|
|
257
|
+
reason: 'name_taken',
|
|
258
|
+
error: `${label} name ${name} already exists in collection ${collection}`,
|
|
259
|
+
existingId,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
return null;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* `pathname` tidied as a page's path in `locale`, or why it cannot be one: it is malformed, or
|
|
266
|
+
* another page has it. The path names the page's file, so '/../x' would write it outside the
|
|
267
|
+
* content folder, and '/about/' is the file of the page at '/about'. `excludeId` is a page whose
|
|
268
|
+
* own path is changing; it never blocks itself. Without a `site`, only the path's form is checked.
|
|
269
|
+
*/
|
|
270
|
+
export function checkPagePathname(site, pathname, locale, excludeId) {
|
|
271
|
+
const validation = normalizeAndValidatePathname(pathname);
|
|
272
|
+
if (!validation.valid) {
|
|
273
|
+
return {
|
|
274
|
+
valid: false,
|
|
275
|
+
reason: 'invalid_pathname',
|
|
276
|
+
error: `Invalid pathname for locale ${locale}: ${validation.message}`,
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
const tidied = validation.value;
|
|
280
|
+
const existingId = site?.getPathnameConflict(tidied, locale, excludeId);
|
|
281
|
+
if (existingId) {
|
|
282
|
+
return { valid: false, reason: 'pathname_taken', error: `Pathname ${tidied} already exists`, existingId };
|
|
283
|
+
}
|
|
284
|
+
return { valid: true, pathname: tidied };
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Why a page cannot have `pathname` in `locale` in a site's MDX pages folder (sites.json
|
|
288
|
+
* `mdxPages`), or null when it can. In that folder a page's language is its first folder and a
|
|
289
|
+
* default-language page has none, so '/de/x' in the default language would be written to
|
|
290
|
+
* <folder>/de/x.mdx, the file of the German page at '/x', and read back as that page. `locales`
|
|
291
|
+
* are the languages the folder reads as a first folder. They match in any capitals: macOS and
|
|
292
|
+
* Windows disks treat <folder>/pt-br/x.mdx and <folder>/pt-BR/x.mdx as one file.
|
|
293
|
+
*/
|
|
294
|
+
export function checkMdxPagesPathname(pathname, locale, folder) {
|
|
295
|
+
if (locale !== folder.defaultLocale)
|
|
296
|
+
return null;
|
|
297
|
+
const [first, ...rest] = pathname.slice(1).split('/');
|
|
298
|
+
if (rest.length === 0)
|
|
299
|
+
return null;
|
|
300
|
+
const kept = [...folder.locales].find((folderLocale) => folderLocale.toLowerCase() === first.toLowerCase());
|
|
301
|
+
if (kept === undefined)
|
|
302
|
+
return null;
|
|
303
|
+
return {
|
|
304
|
+
valid: false,
|
|
305
|
+
reason: 'invalid_pathname',
|
|
306
|
+
error: `Invalid pathname for locale ${locale}: Path cannot start with \`/${first}/\`: the MDX pages folder keeps the ${kept} pages there`,
|
|
307
|
+
};
|
|
308
|
+
}
|
|
226
309
|
/**
|
|
227
310
|
* Generate a new content ID
|
|
228
311
|
*/
|
|
@@ -273,3 +356,4 @@ export function shouldUpdateModifiedTimestamp(data) {
|
|
|
273
356
|
const scope = analyzeUpdateScope(data);
|
|
274
357
|
return scope !== UPDATE_SCOPE.NONE;
|
|
275
358
|
}
|
|
359
|
+
//# sourceMappingURL=content-operations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-operations.js","sourceRoot":"","sources":["../src/content-operations.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,4BAA4B,EAAE,MAAM,oBAAoB,CAAC;AAsCzG;;;GAGG;AACH,MAAM,UAAU,0BAA0B,CAAC,IAA0B;IACnE,0BAA0B;IAC1B,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;QAChB,OAAO;YACL,KAAK,EAAE,KAAK;YACZ,KAAK,EAAE,+BAA+B;SACvC,CAAC;IACJ,CAAC;IAED,MAAM,UAAU,GAAG,QAAQ,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAgB,CAAC,CAAC,+BAA+B;IACjG,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IACrD,MAAM,QAAQ,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC;IAE3D,IAAI,QAAQ,GAAG,IAAI,EAAE,CAAC;QACpB,2BAA2B;QAC3B,OAAO;YACL,KAAK,EAAE,KAAK;YACZ,KAAK,EAAE,+BAA+B,QAAQ,SAAS;SACxD,CAAC;IACJ,CAAC;IAED,OAAO;QACL,KAAK,EAAE,IAAI;QACX,UAAU;QACV,IAAI,EAAE,QAAQ;KACf,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAClC,WAA+B,EAC/B,WAA+B,EAC/B,WAAoB,EACpB,GAAW;IAEX,MAAM,OAAO,GAA2B,EAAE,CAAC;IAE3C,IAAI,WAAW,IAAI,WAAW,IAAI,WAAW,KAAK,WAAW,IAAI,WAA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AkB,CAAC,IAAI,CAAC,CAAC;IACvC,OAAO,KAAK,KAAK,YAAY,CAAC,IAAI,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
* Whether `locale` is one this grammar reads back. A writer checks a new entry's locale with it:
|
|
17
|
+
* the locale is spliced into the file path, so anything else is either unreadable or, like
|
|
18
|
+
* '../x', a path out of the entry's folder.
|
|
19
|
+
*/
|
|
20
|
+
export declare function isContentLocale(locale: string): boolean;
|
|
21
|
+
export type ContentFileExtension = 'mdx' | 'vxjson' | 'json';
|
|
22
|
+
export interface LocaleFilename {
|
|
23
|
+
/** Filename with the `.<locale>.<ext>` suffix removed. */
|
|
24
|
+
base: string;
|
|
25
|
+
/** Locale exactly as written in the filename. */
|
|
26
|
+
locale: string;
|
|
27
|
+
extension: ContentFileExtension;
|
|
28
|
+
}
|
|
29
|
+
/** Split `<base>.<locale>.<ext>`. Null when the filename carries no locale suffix. */
|
|
30
|
+
export declare function parseLocaleFilename(filename: string): LocaleFilename | null;
|
|
31
|
+
export interface ContentPathLayout {
|
|
32
|
+
kind: 'fragment' | 'page' | 'data';
|
|
33
|
+
site?: string;
|
|
34
|
+
collection: string;
|
|
35
|
+
locale: string;
|
|
36
|
+
pathname?: string;
|
|
37
|
+
name?: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Pure path → identity mapper. Returns null when the path doesn't match any
|
|
41
|
+
* supported layout or lacks an explicit locale suffix.
|
|
42
|
+
*
|
|
43
|
+
* Layouts honoured here mirror filesystem-content-api.ts:137-144:
|
|
44
|
+
*
|
|
45
|
+
* - `fragments/<collection>/<name>.<locale>.{mdx,vxjson}` (collection required;
|
|
46
|
+
* `fragments/<name>.<locale>.ext` is a legacy form that FileSystemContentAPI
|
|
47
|
+
* repairs by renaming. The pure parser refuses it.)
|
|
48
|
+
* - `data/<collection>/<name>.<locale>.json`
|
|
49
|
+
* - `<site>/<collection>/<path...>/<file>.<locale>.{vxjson,mdx}` (pages; `index`
|
|
50
|
+
* basename maps to the parent path).
|
|
51
|
+
*
|
|
52
|
+
* Reads accept .mdx pages even though the filesystem writer emits main-layout
|
|
53
|
+
* pages as .vxjson only (its mdx pages live under the separate mdxPagesRoot):
|
|
54
|
+
* another writer may derive the extension from the content type, so an
|
|
55
|
+
* mdx-typed page can land here as <site>/pages/<f>.<l>.mdx and must re-parse —
|
|
56
|
+
* dropping it made written pages unreadable.
|
|
57
|
+
*/
|
|
58
|
+
export declare function parseContentPathLayout(path: string): ContentPathLayout | null;
|
|
59
|
+
//# sourceMappingURL=content-path.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-path.d.ts","sourceRoot":"","sources":["../src/content-path.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAiBH;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEvD;AAKD,MAAM,MAAM,oBAAoB,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;AAE7D,MAAM,WAAW,cAAc;IAC7B,0DAA0D;IAC1D,IAAI,EAAE,MAAM,CAAC;IACb,iDAAiD;IACjD,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,oBAAoB,CAAC;CACjC;AAED,sFAAsF;AACtF,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI,CAI3E;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,MAAM,CAAC;IACnC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,iBAAiB,GAAG,IAAI,CAyB7E"}
|
|
@@ -0,0 +1,88 @@
|
|
|
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
|
+
* A two-letter language subtag, optionally followed by a two-letter upper-case
|
|
17
|
+
* region (`en`, `nl`, `en-US`). Case is PRESERVED, never normalized: writers
|
|
18
|
+
* splice this exact string back into the filename (`getFilePath`, and any other
|
|
19
|
+
* writer of content files), so lower-casing it here would make a repo holding
|
|
20
|
+
* `about.EN.mdx` save its next edit to `about.en.mdx` and orphan the original.
|
|
21
|
+
*
|
|
22
|
+
* Wider BCP-47 forms (three-letter languages, script subtags like `zh-Hans`,
|
|
23
|
+
* lower-case regions) are deliberately NOT accepted: no spec text defines the
|
|
24
|
+
* grammar, and every writer in the system emits this shape today.
|
|
25
|
+
*/
|
|
26
|
+
const LOCALE_SUBTAG = '[a-zA-Z]{2}(?:-[A-Z]{2})?';
|
|
27
|
+
const LOCALE = new RegExp(`^${LOCALE_SUBTAG}$`);
|
|
28
|
+
/**
|
|
29
|
+
* Whether `locale` is one this grammar reads back. A writer checks a new entry's locale with it:
|
|
30
|
+
* the locale is spliced into the file path, so anything else is either unreadable or, like
|
|
31
|
+
* '../x', a path out of the entry's folder.
|
|
32
|
+
*/
|
|
33
|
+
export function isContentLocale(locale) {
|
|
34
|
+
return LOCALE.test(locale);
|
|
35
|
+
}
|
|
36
|
+
/** `<base>.<locale>.<ext>` — the filename half of every content layout. */
|
|
37
|
+
const LOCALE_FILENAME = new RegExp(`^(.+)\\.(${LOCALE_SUBTAG})\\.(mdx|vxjson|json)$`);
|
|
38
|
+
/** Split `<base>.<locale>.<ext>`. Null when the filename carries no locale suffix. */
|
|
39
|
+
export function parseLocaleFilename(filename) {
|
|
40
|
+
const match = LOCALE_FILENAME.exec(filename);
|
|
41
|
+
if (!match)
|
|
42
|
+
return null;
|
|
43
|
+
return { base: match[1], locale: match[2], extension: match[3] };
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Pure path → identity mapper. Returns null when the path doesn't match any
|
|
47
|
+
* supported layout or lacks an explicit locale suffix.
|
|
48
|
+
*
|
|
49
|
+
* Layouts honoured here mirror filesystem-content-api.ts:137-144:
|
|
50
|
+
*
|
|
51
|
+
* - `fragments/<collection>/<name>.<locale>.{mdx,vxjson}` (collection required;
|
|
52
|
+
* `fragments/<name>.<locale>.ext` is a legacy form that FileSystemContentAPI
|
|
53
|
+
* repairs by renaming. The pure parser refuses it.)
|
|
54
|
+
* - `data/<collection>/<name>.<locale>.json`
|
|
55
|
+
* - `<site>/<collection>/<path...>/<file>.<locale>.{vxjson,mdx}` (pages; `index`
|
|
56
|
+
* basename maps to the parent path).
|
|
57
|
+
*
|
|
58
|
+
* Reads accept .mdx pages even though the filesystem writer emits main-layout
|
|
59
|
+
* pages as .vxjson only (its mdx pages live under the separate mdxPagesRoot):
|
|
60
|
+
* another writer may derive the extension from the content type, so an
|
|
61
|
+
* mdx-typed page can land here as <site>/pages/<f>.<l>.mdx and must re-parse —
|
|
62
|
+
* dropping it made written pages unreadable.
|
|
63
|
+
*/
|
|
64
|
+
export function parseContentPathLayout(path) {
|
|
65
|
+
const parts = path.split('/').filter(Boolean);
|
|
66
|
+
if (parts.length < 3)
|
|
67
|
+
return null;
|
|
68
|
+
const suffix = parseLocaleFilename(parts[parts.length - 1]);
|
|
69
|
+
if (!suffix)
|
|
70
|
+
return null;
|
|
71
|
+
if (parts[0] === 'fragments') {
|
|
72
|
+
if (parts.length !== 3 || suffix.extension === 'json')
|
|
73
|
+
return null;
|
|
74
|
+
return { kind: 'fragment', collection: parts[1], name: suffix.base, locale: suffix.locale };
|
|
75
|
+
}
|
|
76
|
+
if (parts[0] === 'data') {
|
|
77
|
+
if (parts.length !== 3 || suffix.extension !== 'json')
|
|
78
|
+
return null;
|
|
79
|
+
return { kind: 'data', collection: parts[1], name: suffix.base, locale: suffix.locale };
|
|
80
|
+
}
|
|
81
|
+
if (suffix.extension === 'json')
|
|
82
|
+
return null;
|
|
83
|
+
const pathParts = parts.slice(2);
|
|
84
|
+
pathParts[pathParts.length - 1] = suffix.base;
|
|
85
|
+
const pathname = pathParts[pathParts.length - 1] === 'index' ? `/${pathParts.slice(0, -1).join('/')}` : `/${pathParts.join('/')}`;
|
|
86
|
+
return { kind: 'page', site: parts[0], collection: parts[1], locale: suffix.locale, pathname };
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=content-path.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-path.js","sourceRoot":"","sources":["../src/content-path.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;G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-1,4 +1,4 @@
|
|
|
1
|
-
import type { ContentAPIOptions } from './types';
|
|
1
|
+
import type { ContentAPIOptions } from './types.js';
|
|
2
2
|
export type ContentReaderOptions = ContentAPIOptions;
|
|
3
3
|
/**
|
|
4
4
|
* Creates a read-oriented content API instance for build-time consumers.
|
|
@@ -6,5 +6,5 @@ export type ContentReaderOptions = ContentAPIOptions;
|
|
|
6
6
|
* The filesystem implementation is loaded lazily so build tooling does not
|
|
7
7
|
* eagerly traverse native hashing dependencies through the reader entrypoint.
|
|
8
8
|
*/
|
|
9
|
-
export declare function createContentAPI(options: ContentReaderOptions): Promise<import("./filesystem-content-api").FileSystemContentAPI>;
|
|
9
|
+
export declare function createContentAPI(options: ContentReaderOptions): Promise<import("./filesystem-content-api.js").FileSystemContentAPI>;
|
|
10
10
|
//# sourceMappingURL=content-reader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-reader.d.ts","sourceRoot":"","sources":["../src/content-reader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"content-reader.d.ts","sourceRoot":"","sources":["../src/content-reader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD,MAAM,MAAM,oBAAoB,GAAG,iBAAiB,CAAC;AAErD;;;;;GAKG;AACH,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,oBAAoB,uEAOnE"}
|
package/dist/content-reader.js
CHANGED
|
@@ -5,9 +5,10 @@
|
|
|
5
5
|
* eagerly traverse native hashing dependencies through the reader entrypoint.
|
|
6
6
|
*/
|
|
7
7
|
export async function createContentAPI(options) {
|
|
8
|
-
const { FileSystemContentAPI: ReaderAPI } = await import('./filesystem-content-api');
|
|
8
|
+
const { FileSystemContentAPI: ReaderAPI } = await import('./filesystem-content-api.js');
|
|
9
9
|
return ReaderAPI.create({
|
|
10
10
|
...options,
|
|
11
11
|
canvasDir: options.canvasDir || './canvas',
|
|
12
12
|
});
|
|
13
13
|
}
|
|
14
|
+
//# sourceMappingURL=content-reader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-reader.js","sourceRoot":"","sources":["../src/content-reader.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,OAA6B;IAClE,MAAM,EAAE,oBAAoB,EAAE,SAAS,EAAE,GAAG,MAAM,MAAM,CAAC,6BAA6B,CAAC,CAAC;IAExF,OAAO,SAAS,CAAC,MAAM,CAAC;QACtB,GAAG,OAAO;QACV,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,UAAU;KAC3C,CAAC,CAAC;AACL,CAAC"}
|