@acdh-oeaw/keystatic-lib 0.1.0 → 0.1.2
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/chunk-5ZKY25OZ.js +16 -0
- package/dist/chunk-5ZKY25OZ.js.map +1 -0
- package/dist/chunk-CI4JBTGG.js +8 -0
- package/dist/chunk-CI4JBTGG.js.map +1 -0
- package/dist/chunk-EAFZLNV4.js +15 -0
- package/dist/chunk-EAFZLNV4.js.map +1 -0
- package/dist/chunk-FVPLAXGT.js +10 -0
- package/dist/chunk-FVPLAXGT.js.map +1 -0
- package/dist/chunk-M7J4ISS4.js +8 -0
- package/dist/chunk-M7J4ISS4.js.map +1 -0
- package/dist/chunk-TQSIK35I.js +29 -0
- package/dist/chunk-TQSIK35I.js.map +1 -0
- package/dist/config.d.ts +16 -0
- package/dist/config.js +3 -0
- package/dist/config.js.map +1 -0
- package/dist/create-asset-options.d.ts +7 -0
- package/dist/create-asset-options.js +3 -0
- package/dist/create-asset-options.js.map +1 -0
- package/dist/create-component.d.ts +6 -0
- package/dist/create-component.js +3 -0
- package/dist/create-component.js.map +1 -0
- package/dist/create-content-field-options.d.ts +10 -0
- package/dist/create-content-field-options.js +4 -0
- package/dist/create-content-field-options.js.map +1 -0
- package/dist/create-label.d.ts +5 -0
- package/dist/create-label.js +3 -0
- package/dist/create-label.js.map +1 -0
- package/dist/index.d.ts +9 -84
- package/dist/index.js +6 -139
- package/dist/index.js.map +1 -1
- package/dist/reader.d.ts +44 -0
- package/dist/reader.js +88 -0
- package/dist/reader.js.map +1 -0
- package/dist/resources.d.ts +15 -0
- package/dist/resources.js +3 -0
- package/dist/resources.js.map +1 -0
- package/dist/with-i18n-prefix.d.ts +6 -0
- package/dist/with-i18n-prefix.js +3 -0
- package/dist/with-i18n-prefix.js.map +1 -0
- package/package.json +4 -4
- package/readme.md +48 -6
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import slugify from '@sindresorhus/slugify';
|
|
2
|
+
|
|
3
|
+
// src/create-asset-options.ts
|
|
4
|
+
function createAssetOptions(path) {
|
|
5
|
+
return {
|
|
6
|
+
directory: `./public/assets${path}`,
|
|
7
|
+
publicPath: `/assets${path}`,
|
|
8
|
+
transformFilename(originalFilename) {
|
|
9
|
+
return slugify(originalFilename, { preserveCharacters: ["."] });
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { createAssetOptions };
|
|
15
|
+
//# sourceMappingURL=chunk-5ZKY25OZ.js.map
|
|
16
|
+
//# sourceMappingURL=chunk-5ZKY25OZ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/create-asset-options.ts"],"names":[],"mappings":";;;AAEO,SAAS,mBAAgD,IAAa,EAAA;AAC5E,EAAO,OAAA;AAAA,IACN,SAAA,EAAW,kBAAkB,IAAI,CAAA,CAAA;AAAA,IACjC,UAAA,EAAY,UAAU,IAAI,CAAA,CAAA;AAAA,IAC1B,kBAAkB,gBAA0B,EAAA;AAC3C,MAAA,OAAO,QAAQ,gBAAkB,EAAA,EAAE,oBAAoB,CAAC,GAAG,GAAG,CAAA,CAAA;AAAA,KAC/D;AAAA,GACD,CAAA;AACD","file":"chunk-5ZKY25OZ.js","sourcesContent":["import slugify from \"@sindresorhus/slugify\";\n\nexport function createAssetOptions<TPath extends `/${string}/`>(path: TPath) {\n\treturn {\n\t\tdirectory: `./public/assets${path}` as const,\n\t\tpublicPath: `/assets${path}` as const,\n\t\ttransformFilename(originalFilename: string) {\n\t\t\treturn slugify(originalFilename, { preserveCharacters: [\".\"] });\n\t\t},\n\t};\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/create-label.ts"],"names":[],"mappings":";AAEO,SAAS,WAAA,CAAY,OAAe,MAAgB,EAAA;AAC1D,EAAO,OAAA,CAAA,EAAG,KAAK,CAAA,EAAA,EAAK,MAAM,CAAA,CAAA,CAAA,CAAA;AAC3B","file":"chunk-CI4JBTGG.js","sourcesContent":["import type { Locale } from \"./config\";\n\nexport function createLabel(label: string, locale: Locale) {\n\treturn `${label} (${locale})`;\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createAssetOptions } from './chunk-5ZKY25OZ.js';
|
|
2
|
+
|
|
3
|
+
// src/create-content-field-options.ts
|
|
4
|
+
function createContentFieldOptions(assetPath) {
|
|
5
|
+
const assetPaths = createAssetOptions(assetPath);
|
|
6
|
+
const headingLevels = [2, 3, 4, 5];
|
|
7
|
+
return {
|
|
8
|
+
heading: headingLevels,
|
|
9
|
+
image: assetPaths
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { createContentFieldOptions };
|
|
14
|
+
//# sourceMappingURL=chunk-EAFZLNV4.js.map
|
|
15
|
+
//# sourceMappingURL=chunk-EAFZLNV4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/create-content-field-options.ts"],"names":[],"mappings":";;;AAEO,SAAS,0BAAuD,SAAkB,EAAA;AACxF,EAAM,MAAA,UAAA,GAAa,mBAAmB,SAAS,CAAA,CAAA;AAC/C,EAAA,MAAM,aAAgB,GAAA,CAAC,CAAG,EAAA,CAAA,EAAG,GAAG,CAAC,CAAA,CAAA;AAEjC,EAAO,OAAA;AAAA,IACN,OAAS,EAAA,aAAA;AAAA,IACT,KAAO,EAAA,UAAA;AAAA,GACR,CAAA;AACD","file":"chunk-EAFZLNV4.js","sourcesContent":["import { createAssetOptions } from \"./create-asset-options\";\n\nexport function createContentFieldOptions<TPath extends `/${string}/`>(assetPath: TPath) {\n\tconst assetPaths = createAssetOptions(assetPath);\n\tconst headingLevels = [2, 3, 4, 5] as const;\n\n\treturn {\n\t\theading: headingLevels,\n\t\timage: assetPaths,\n\t};\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// src/create-component.ts
|
|
2
|
+
function createComponent(createComponentFactory) {
|
|
3
|
+
return function createComponent2(assetPath, locale) {
|
|
4
|
+
return createComponentFactory(assetPath, locale);
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export { createComponent };
|
|
9
|
+
//# sourceMappingURL=chunk-FVPLAXGT.js.map
|
|
10
|
+
//# sourceMappingURL=chunk-FVPLAXGT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/create-component.ts"],"names":["createComponent"],"mappings":";AAIO,SAAS,gBAId,sBAA2E,EAAA;AAC5E,EAAO,OAAA,SAASA,gBAAgB,CAAA,SAAA,EAAkB,MAAiB,EAAA;AAClE,IAAO,OAAA,sBAAA,CAAuB,WAAW,MAAM,CAAA,CAAA;AAAA,GAChD,CAAA;AACD","file":"chunk-FVPLAXGT.js","sourcesContent":["import type { ContentComponent } from \"@keystatic/core/content-components\";\n\nimport type { Locale } from \"./config\";\n\nexport function createComponent<\n\tTPath extends `/${string}/`,\n\tTLocale extends Locale,\n\tTComponent extends ContentComponent,\n>(createComponentFactory: (assetPath: TPath, locale: TLocale) => TComponent) {\n\treturn function createComponent(assetPath: TPath, locale: TLocale) {\n\t\treturn createComponentFactory(assetPath, locale);\n\t};\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/with-i18n-prefix.ts"],"names":[],"mappings":";AAEO,SAAS,cAAA,CACf,OACA,MACC,EAAA;AACD,EAAO,OAAA,CAAA,EAAG,MAAM,CAAA,CAAA,EAAI,KAAK,CAAA,CAAA,CAAA;AAC1B","file":"chunk-M7J4ISS4.js","sourcesContent":["import type { Locale } from \"./config\";\n\nexport function withI18nPrefix<TLabel extends string, TLocale extends Locale>(\n\tlabel: TLabel,\n\tlocale: TLocale,\n) {\n\treturn `${locale}:${label}` as const;\n}\n\nexport type WithoutI18nPrefix<\n\tT extends string,\n\tTLocale extends Locale,\n> = T extends `${TLocale}:${infer U}` ? U : T;\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// src/resources.ts
|
|
2
|
+
function createCollectionPaths(path, locale) {
|
|
3
|
+
return {
|
|
4
|
+
assetPath: `/content/${locale}${path}`,
|
|
5
|
+
contentPath: `./content/${locale}${path}*/`
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
function createSingletonPaths(path, locale) {
|
|
9
|
+
return {
|
|
10
|
+
assetPath: `/content/${locale}${path}`,
|
|
11
|
+
contentPath: `./content/${locale}${path}`
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function createCollection(path, createLocalisedCollectionFactory) {
|
|
15
|
+
return function createLocalisedCollection(locale) {
|
|
16
|
+
const paths = createCollectionPaths(path, locale);
|
|
17
|
+
return createLocalisedCollectionFactory(paths, locale);
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function createSingleton(path, createLocalisedSingletonFactory) {
|
|
21
|
+
return function createLocalisedSingleton(locale) {
|
|
22
|
+
const paths = createSingletonPaths(path, locale);
|
|
23
|
+
return createLocalisedSingletonFactory(paths, locale);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { createCollection, createCollectionPaths, createSingleton, createSingletonPaths };
|
|
28
|
+
//# sourceMappingURL=chunk-TQSIK35I.js.map
|
|
29
|
+
//# sourceMappingURL=chunk-TQSIK35I.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/resources.ts"],"names":[],"mappings":";AAIO,SAAS,qBAAA,CAAmD,MAAa,MAAgB,EAAA;AAC/F,EAAO,OAAA;AAAA,IACN,SAAW,EAAA,CAAA,SAAA,EAAY,MAAM,CAAA,EAAG,IAAI,CAAA,CAAA;AAAA,IACpC,WAAa,EAAA,CAAA,UAAA,EAAa,MAAM,CAAA,EAAG,IAAI,CAAA,EAAA,CAAA;AAAA,GACxC,CAAA;AACD,CAAA;AAEO,SAAS,oBAAA,CAAkD,MAAa,MAAgB,EAAA;AAC9F,EAAO,OAAA;AAAA,IACN,SAAW,EAAA,CAAA,SAAA,EAAY,MAAM,CAAA,EAAG,IAAI,CAAA,CAAA;AAAA,IACpC,WAAa,EAAA,CAAA,UAAA,EAAa,MAAM,CAAA,EAAG,IAAI,CAAA,CAAA;AAAA,GACxC,CAAA;AACD,CAAA;AAEO,SAAS,gBAAA,CAMf,MACA,gCAIC,EAAA;AACD,EAAO,OAAA,SAAS,0BAA0B,MAAiB,EAAA;AAC1D,IAAM,MAAA,KAAA,GAAQ,qBAAsB,CAAA,IAAA,EAAM,MAAM,CAAA,CAAA;AAChD,IAAO,OAAA,gCAAA,CAAiC,OAAO,MAAM,CAAA,CAAA;AAAA,GACtD,CAAA;AACD,CAAA;AAEO,SAAS,eAAA,CAKf,MACA,+BAIC,EAAA;AACD,EAAO,OAAA,SAAS,yBAAyB,MAAiB,EAAA;AACzD,IAAM,MAAA,KAAA,GAAQ,oBAAqB,CAAA,IAAA,EAAM,MAAM,CAAA,CAAA;AAC/C,IAAO,OAAA,+BAAA,CAAgC,OAAO,MAAM,CAAA,CAAA;AAAA,GACrD,CAAA;AACD","file":"chunk-TQSIK35I.js","sourcesContent":["import type { Collection, ComponentSchema, Singleton } from \"@keystatic/core\";\n\nimport type { Locale } from \"./config\";\n\nexport function createCollectionPaths<TPath extends `/${string}/`>(path: TPath, locale: Locale) {\n\treturn {\n\t\tassetPath: `/content/${locale}${path}`,\n\t\tcontentPath: `./content/${locale}${path}*/`,\n\t} as const;\n}\n\nexport function createSingletonPaths<TPath extends `/${string}/`>(path: TPath, locale: Locale) {\n\treturn {\n\t\tassetPath: `/content/${locale}${path}`,\n\t\tcontentPath: `./content/${locale}${path}`,\n\t} as const;\n}\n\nexport function createCollection<\n\tTPath extends `/${string}/`,\n\tTLocale extends Locale,\n\tTSchema extends Record<string, ComponentSchema>,\n\tTSlugField extends string,\n>(\n\tpath: TPath,\n\tcreateLocalisedCollectionFactory: (\n\t\tpaths: ReturnType<typeof createCollectionPaths<TPath>>,\n\t\tlocale: TLocale,\n\t) => Collection<TSchema, TSlugField>,\n) {\n\treturn function createLocalisedCollection(locale: TLocale) {\n\t\tconst paths = createCollectionPaths(path, locale);\n\t\treturn createLocalisedCollectionFactory(paths, locale);\n\t};\n}\n\nexport function createSingleton<\n\tTPath extends `/${string}/`,\n\tTLocale extends Locale,\n\tTSchema extends Record<string, ComponentSchema>,\n>(\n\tpath: TPath,\n\tcreateLocalisedSingletonFactory: (\n\t\tpaths: ReturnType<typeof createSingletonPaths<TPath>>,\n\t\tlocale: TLocale,\n\t) => Singleton<TSchema>,\n) {\n\treturn function createLocalisedSingleton(locale: TLocale) {\n\t\tconst paths = createSingletonPaths(path, locale);\n\t\treturn createLocalisedSingletonFactory(paths, locale);\n\t};\n}\n"]}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provide supported locales by augmenting the interface:
|
|
3
|
+
*
|
|
4
|
+
* ```ts
|
|
5
|
+
* export interface KeystaticConfig {
|
|
6
|
+
* locales: "de" | "en"
|
|
7
|
+
* }
|
|
8
|
+
* ```
|
|
9
|
+
*/
|
|
10
|
+
interface KeystaticConfig {
|
|
11
|
+
}
|
|
12
|
+
type Locale = KeystaticConfig extends {
|
|
13
|
+
locales: string;
|
|
14
|
+
} ? KeystaticConfig["locales"] : string;
|
|
15
|
+
|
|
16
|
+
export type { KeystaticConfig, Locale };
|
package/dist/config.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"config.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"create-asset-options.js"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ContentComponent } from '@keystatic/core/content-components';
|
|
2
|
+
import { Locale } from './config.js';
|
|
3
|
+
|
|
4
|
+
declare function createComponent<TPath extends `/${string}/`, TLocale extends Locale, TComponent extends ContentComponent>(createComponentFactory: (assetPath: TPath, locale: TLocale) => TComponent): (assetPath: TPath, locale: TLocale) => TComponent;
|
|
5
|
+
|
|
6
|
+
export { createComponent };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"create-component.js"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare function createContentFieldOptions<TPath extends `/${string}/`>(assetPath: TPath): {
|
|
2
|
+
heading: readonly [2, 3, 4, 5];
|
|
3
|
+
image: {
|
|
4
|
+
directory: `./public/assets${TPath}`;
|
|
5
|
+
publicPath: `/assets${TPath}`;
|
|
6
|
+
transformFilename(originalFilename: string): string;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export { createContentFieldOptions };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"create-content-field-options.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"create-label.js"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,84 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*
|
|
11
|
-
* ```ts
|
|
12
|
-
* export interface KeystaticConfig {
|
|
13
|
-
* locales: "de" | "en"
|
|
14
|
-
* }
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
interface KeystaticConfig {
|
|
18
|
-
}
|
|
19
|
-
type Locale = KeystaticConfig extends {
|
|
20
|
-
locales: string;
|
|
21
|
-
} ? KeystaticConfig["locales"] : string;
|
|
22
|
-
declare function createLabel(label: string, locale: Locale): string;
|
|
23
|
-
declare function createAssetOptions<TPath extends `/${string}/`>(path: TPath): {
|
|
24
|
-
directory: `./public/assets${TPath}`;
|
|
25
|
-
publicPath: `/assets${TPath}`;
|
|
26
|
-
transformFilename(originalFilename: string): string;
|
|
27
|
-
};
|
|
28
|
-
declare function createContentFieldOptions<TPath extends `/${string}/`>(assetPath: TPath): {
|
|
29
|
-
heading: readonly [2, 3, 4, 5];
|
|
30
|
-
image: {
|
|
31
|
-
directory: `./public/assets${TPath}`;
|
|
32
|
-
publicPath: `/assets${TPath}`;
|
|
33
|
-
transformFilename(originalFilename: string): string;
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
declare function createComponent<TPath extends `/${string}/`, TComponent extends ContentComponent>(createComponentFactory: (assetPath: TPath, locale: Locale) => TComponent): (assetPath: TPath, locale: Locale) => TComponent;
|
|
37
|
-
declare function createCollectionPaths<TPath extends `/${string}/`>(path: TPath, locale: Locale): {
|
|
38
|
-
readonly assetPath: `/content/${string}${TPath}`;
|
|
39
|
-
readonly contentPath: `./content/${string}${TPath}*/`;
|
|
40
|
-
};
|
|
41
|
-
declare function createSingletonPaths<TPath extends `/${string}/`>(path: TPath, locale: Locale): {
|
|
42
|
-
readonly assetPath: `/content/${string}${TPath}`;
|
|
43
|
-
readonly contentPath: `./content/${string}${TPath}`;
|
|
44
|
-
};
|
|
45
|
-
declare function createCollection<TPath extends `/${string}/`, TSchema extends Record<string, ComponentSchema>, TSlugField extends string>(path: TPath, createLocalisedCollectionFactory: (paths: ReturnType<typeof createCollectionPaths<TPath>>, locale: Locale) => Collection<TSchema, TSlugField>): (locale: Locale) => Collection<TSchema, TSlugField>;
|
|
46
|
-
declare function createSingleton<TPath extends `/${string}/`, Schema extends Record<string, ComponentSchema>>(path: TPath, createLocalisedSingletonFactory: (paths: ReturnType<typeof createSingletonPaths<TPath>>, locale: Locale) => Singleton<Schema>): (locale: Locale) => Singleton<Schema>;
|
|
47
|
-
declare function withI18nPrefix<TLabel extends string>(label: TLabel, locale: Locale): `${string}:${TLabel}`;
|
|
48
|
-
type WithoutI18nPrefix<T extends string> = T extends `${Locale}:${infer U}` ? U : T;
|
|
49
|
-
declare function createReader<TCollections extends Record<string, Collection<Record<string, ComponentSchema>, string>>, TSingletons extends Record<string, Singleton<Record<string, ComponentSchema>>>>(config: Config<TCollections, TSingletons>, getGitHubReaderConfig?: () => {
|
|
50
|
-
repo: `${string}/${string}`;
|
|
51
|
-
pathPrefix?: string;
|
|
52
|
-
ref?: string;
|
|
53
|
-
token?: string;
|
|
54
|
-
} | null): _keystatic_core_reader_github.Reader<TCollections, TSingletons>;
|
|
55
|
-
declare function createReaders<TCollections extends Record<string, Collection<Record<string, ComponentSchema>, string>>, TSingletons extends Record<string, Singleton<Record<string, ComponentSchema>>>, TMdxContent extends MDXModule>(config: Config<TCollections, TSingletons>, getMdxContent: (code: string, locale: Locale, baseUrl: URL) => Promise<TMdxContent>): {
|
|
56
|
-
createCollectionResource: <TKeys extends WithoutI18nPrefix<keyof TCollections & string>>(name: TKeys, locale: Locale) => {
|
|
57
|
-
all: () => Promise<{
|
|
58
|
-
collection: TKeys;
|
|
59
|
-
id: string;
|
|
60
|
-
data: TCollections[`${string}:${TKeys}`]["schema"] extends infer T extends Record<string, ComponentSchema> ? { [Key in keyof T]: TCollections[`${string}:${TKeys}`]["slugField"] extends infer T_1 ? T_1 extends TCollections[`${string}:${TKeys}`]["slugField"] ? T_1 extends Key ? TCollections[`${string}:${TKeys}`]["schema"][Key] extends _keystatic_core.SlugFormField<any, any, any, infer SlugSerializedValue> ? SlugSerializedValue : _keystatic_core.ValueForReadingDeep<TCollections[`${string}:${TKeys}`]["schema"][Key]> : _keystatic_core.ValueForReadingDeep<TCollections[`${string}:${TKeys}`]["schema"][Key]> : never : never; } : never;
|
|
61
|
-
compile(code: string): Promise<TMdxContent>;
|
|
62
|
-
}[]>;
|
|
63
|
-
baseUrl: (id: string) => url.URL;
|
|
64
|
-
compile: (id: string, code: string) => Promise<TMdxContent>;
|
|
65
|
-
list: () => Promise<string[]>;
|
|
66
|
-
read: (id: string) => Promise<{
|
|
67
|
-
collection: TKeys;
|
|
68
|
-
id: string;
|
|
69
|
-
data: TCollections[`${string}:${TKeys}`]["schema"] extends infer T extends Record<string, ComponentSchema> ? { [Key in keyof T]: TCollections[`${string}:${TKeys}`]["slugField"] extends infer T_1 ? T_1 extends TCollections[`${string}:${TKeys}`]["slugField"] ? T_1 extends Key ? TCollections[`${string}:${TKeys}`]["schema"][Key] extends _keystatic_core.SlugFormField<any, any, any, infer SlugSerializedValue> ? SlugSerializedValue : _keystatic_core.ValueForReadingDeep<TCollections[`${string}:${TKeys}`]["schema"][Key]> : _keystatic_core.ValueForReadingDeep<TCollections[`${string}:${TKeys}`]["schema"][Key]> : never : never; } : never;
|
|
70
|
-
compile(code: string): Promise<TMdxContent>;
|
|
71
|
-
}>;
|
|
72
|
-
};
|
|
73
|
-
createSingletonResource: <TKeys extends WithoutI18nPrefix<keyof TSingletons & string>>(name: TKeys, locale: Locale) => {
|
|
74
|
-
baseUrl: () => url.URL;
|
|
75
|
-
compile: (code: string) => Promise<TMdxContent>;
|
|
76
|
-
read: () => Promise<{
|
|
77
|
-
singleton: TKeys;
|
|
78
|
-
data: TSingletons[`${string}:${TKeys}`]["schema"] extends infer T extends Record<string, ComponentSchema> ? { readonly [Key in keyof T]: _keystatic_core.ValueForReadingDeep<TSingletons[`${string}:${TKeys}`]["schema"][Key]>; } : never;
|
|
79
|
-
compile: (code: string) => Promise<TMdxContent>;
|
|
80
|
-
}>;
|
|
81
|
-
};
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
export { type KeystaticConfig, type WithoutI18nPrefix, createAssetOptions, createCollection, createCollectionPaths, createComponent, createContentFieldOptions, createLabel, createReader, createReaders, createSingleton, createSingletonPaths, withI18nPrefix };
|
|
1
|
+
export { KeystaticConfig } from './config.js';
|
|
2
|
+
export { createAssetOptions } from './create-asset-options.js';
|
|
3
|
+
export { createComponent } from './create-component.js';
|
|
4
|
+
export { createContentFieldOptions } from './create-content-field-options.js';
|
|
5
|
+
export { createLabel } from './create-label.js';
|
|
6
|
+
export { createCollection, createCollectionPaths, createSingleton, createSingletonPaths } from './resources.js';
|
|
7
|
+
export { WithoutI18nPrefix, withI18nPrefix } from './with-i18n-prefix.js';
|
|
8
|
+
import '@keystatic/core/content-components';
|
|
9
|
+
import '@keystatic/core';
|
package/dist/index.js
CHANGED
|
@@ -1,141 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// src/index.ts
|
|
9
|
-
function createLabel(label, locale) {
|
|
10
|
-
return `${label} (${locale})`;
|
|
11
|
-
}
|
|
12
|
-
function createAssetOptions(path) {
|
|
13
|
-
return {
|
|
14
|
-
directory: `./public/assets${path}`,
|
|
15
|
-
publicPath: `/assets${path}`,
|
|
16
|
-
transformFilename(originalFilename) {
|
|
17
|
-
return slugify(originalFilename, { preserveCharacters: ["."] });
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
function createContentFieldOptions(assetPath) {
|
|
22
|
-
const assetPaths = createAssetOptions(assetPath);
|
|
23
|
-
const headingLevels = [2, 3, 4, 5];
|
|
24
|
-
return {
|
|
25
|
-
heading: headingLevels,
|
|
26
|
-
image: assetPaths
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
function createComponent(createComponentFactory) {
|
|
30
|
-
return function createComponent2(assetPath, locale) {
|
|
31
|
-
return createComponentFactory(assetPath, locale);
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
function createCollectionPaths(path, locale) {
|
|
35
|
-
return {
|
|
36
|
-
assetPath: `/content/${locale}${path}`,
|
|
37
|
-
contentPath: `./content/${locale}${path}*/`
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
function createSingletonPaths(path, locale) {
|
|
41
|
-
return {
|
|
42
|
-
assetPath: `/content/${locale}${path}`,
|
|
43
|
-
contentPath: `./content/${locale}${path}`
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
function createCollection(path, createLocalisedCollectionFactory) {
|
|
47
|
-
return function createLocalisedCollection(locale) {
|
|
48
|
-
const paths = createCollectionPaths(path, locale);
|
|
49
|
-
return createLocalisedCollectionFactory(paths, locale);
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
function createSingleton(path, createLocalisedSingletonFactory) {
|
|
53
|
-
return function createLocalisedSingleton(locale) {
|
|
54
|
-
const paths = createSingletonPaths(path, locale);
|
|
55
|
-
return createLocalisedSingletonFactory(paths, locale);
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
function withI18nPrefix(label, locale) {
|
|
59
|
-
return `${locale}:${label}`;
|
|
60
|
-
}
|
|
61
|
-
function createReader(config, getGitHubReaderConfig) {
|
|
62
|
-
const gitHubConfig = getGitHubReaderConfig?.();
|
|
63
|
-
if (gitHubConfig != null) {
|
|
64
|
-
return createGitHubReader(config, gitHubConfig);
|
|
65
|
-
}
|
|
66
|
-
return createReader$1(process.cwd(), config);
|
|
67
|
-
}
|
|
68
|
-
function createReaders(config, getMdxContent) {
|
|
69
|
-
function createCollectionResource(name, locale) {
|
|
70
|
-
const reader = createReader(config);
|
|
71
|
-
const collectionName = withI18nPrefix(name, locale);
|
|
72
|
-
const collectionReader = reader.collections[collectionName];
|
|
73
|
-
const collectionConfig = reader.config.collections?.[collectionName];
|
|
74
|
-
assert(collectionConfig?.path);
|
|
75
|
-
function baseUrl(id) {
|
|
76
|
-
return pathToFileURL(join(process.cwd(), collectionConfig.path.replace(/\*+/, id)));
|
|
77
|
-
}
|
|
78
|
-
async function compile(id, code) {
|
|
79
|
-
return getMdxContent(code, locale, baseUrl(id));
|
|
80
|
-
}
|
|
81
|
-
function list() {
|
|
82
|
-
return collectionReader.list();
|
|
83
|
-
}
|
|
84
|
-
async function read(id) {
|
|
85
|
-
const data = await collectionReader.readOrThrow(id, { resolveLinkedFiles: true });
|
|
86
|
-
return {
|
|
87
|
-
collection: name,
|
|
88
|
-
id,
|
|
89
|
-
data,
|
|
90
|
-
compile(code) {
|
|
91
|
-
return compile(id, code);
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
async function all() {
|
|
96
|
-
const ids = await list();
|
|
97
|
-
return Promise.all(ids.map(read));
|
|
98
|
-
}
|
|
99
|
-
return {
|
|
100
|
-
all,
|
|
101
|
-
baseUrl,
|
|
102
|
-
compile,
|
|
103
|
-
list,
|
|
104
|
-
read
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
function createSingletonResource(name, locale) {
|
|
108
|
-
const reader = createReader(config);
|
|
109
|
-
const i18nName = withI18nPrefix(name, locale);
|
|
110
|
-
const singletonReader = reader.singletons[i18nName];
|
|
111
|
-
const singletonConfig = reader.config.singletons?.[i18nName];
|
|
112
|
-
assert(singletonConfig?.path);
|
|
113
|
-
function baseUrl() {
|
|
114
|
-
return pathToFileURL(join(process.cwd(), singletonConfig.path));
|
|
115
|
-
}
|
|
116
|
-
async function compile(code) {
|
|
117
|
-
return getMdxContent(code, locale, baseUrl());
|
|
118
|
-
}
|
|
119
|
-
async function read() {
|
|
120
|
-
const data = await singletonReader.readOrThrow({ resolveLinkedFiles: true });
|
|
121
|
-
return {
|
|
122
|
-
singleton: name,
|
|
123
|
-
data,
|
|
124
|
-
compile
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
return {
|
|
128
|
-
baseUrl,
|
|
129
|
-
compile,
|
|
130
|
-
read
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
return {
|
|
134
|
-
createCollectionResource,
|
|
135
|
-
createSingletonResource
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export { createAssetOptions, createCollection, createCollectionPaths, createComponent, createContentFieldOptions, createLabel, createReader, createReaders, createSingleton, createSingletonPaths, withI18nPrefix };
|
|
1
|
+
export { createComponent } from './chunk-FVPLAXGT.js';
|
|
2
|
+
export { createContentFieldOptions } from './chunk-EAFZLNV4.js';
|
|
3
|
+
export { createAssetOptions } from './chunk-5ZKY25OZ.js';
|
|
4
|
+
export { createLabel } from './chunk-CI4JBTGG.js';
|
|
5
|
+
export { withI18nPrefix } from './chunk-M7J4ISS4.js';
|
|
6
|
+
export { createCollection, createCollectionPaths, createSingleton, createSingletonPaths } from './chunk-TQSIK35I.js';
|
|
140
7
|
//# sourceMappingURL=index.js.map
|
|
141
8
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":["createComponent","createLocalReader"],"mappings":";;;;;;;;AAwBO,SAAS,WAAA,CAAY,OAAe,MAAgB,EAAA;AAC1D,EAAO,OAAA,CAAA,EAAG,KAAK,CAAA,EAAA,EAAK,MAAM,CAAA,CAAA,CAAA,CAAA;AAC3B,CAAA;AAEO,SAAS,mBAAgD,IAAa,EAAA;AAC5E,EAAO,OAAA;AAAA,IACN,SAAA,EAAW,kBAAkB,IAAI,CAAA,CAAA;AAAA,IACjC,UAAA,EAAY,UAAU,IAAI,CAAA,CAAA;AAAA,IAC1B,kBAAkB,gBAA0B,EAAA;AAC3C,MAAA,OAAO,QAAQ,gBAAkB,EAAA,EAAE,oBAAoB,CAAC,GAAG,GAAG,CAAA,CAAA;AAAA,KAC/D;AAAA,GACD,CAAA;AACD,CAAA;AAEO,SAAS,0BAAuD,SAAkB,EAAA;AACxF,EAAM,MAAA,UAAA,GAAa,mBAAmB,SAAS,CAAA,CAAA;AAC/C,EAAA,MAAM,aAAgB,GAAA,CAAC,CAAG,EAAA,CAAA,EAAG,GAAG,CAAC,CAAA,CAAA;AAEjC,EAAO,OAAA;AAAA,IACN,OAAS,EAAA,aAAA;AAAA,IACT,KAAO,EAAA,UAAA;AAAA,GACR,CAAA;AACD,CAAA;AAEO,SAAS,gBACf,sBACC,EAAA;AACD,EAAO,OAAA,SAASA,gBAAgB,CAAA,SAAA,EAAkB,MAAgB,EAAA;AACjE,IAAO,OAAA,sBAAA,CAAuB,WAAW,MAAM,CAAA,CAAA;AAAA,GAChD,CAAA;AACD,CAAA;AAEO,SAAS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AY,EAAE,kBAAA,EAAoB,MAAM,CAAA,CAAA;AAE3E,MAAO,OAAA;AAAA,QACN,SAAW,EAAA,IAAA;AAAA,QACX,IAAA;AAAA,QACA,OAAA;AAAA,OACD,CAAA;AAAA,KACD;AAEA,IAAO,OAAA;AAAA,MACN,OAAA;AAAA,MACA,OAAA;AAAA,MACA,IAAA;AAAA,KACD,CAAA;AAAA,GACD;AAEA,EAAO,OAAA;AAAA,IACN,wBAAA;AAAA,IACA,uBAAA;AAAA,GACD,CAAA;AACD","file":"index.js","sourcesContent":["import assert from \"node:assert/strict\";\nimport { join } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\n\nimport type { Collection, ComponentSchema, Config, Singleton } from \"@keystatic/core\";\nimport type { ContentComponent } from \"@keystatic/core/content-components\";\nimport { createReader as createLocalReader } from \"@keystatic/core/reader\";\nimport { createGitHubReader } from \"@keystatic/core/reader/github\";\nimport slugify from \"@sindresorhus/slugify\";\nimport type { MDXModule } from \"mdx/types\";\n\n/**\n * Provide supported locales by augmenting the interface:\n *\n * ```ts\n * export interface KeystaticConfig {\n * locales: \"de\" | \"en\"\n * }\n * ```\n */\nexport interface KeystaticConfig {}\n\ntype Locale = KeystaticConfig extends { locales: string } ? KeystaticConfig[\"locales\"] : string;\n\nexport function createLabel(label: string, locale: Locale) {\n\treturn `${label} (${locale})`;\n}\n\nexport function createAssetOptions<TPath extends `/${string}/`>(path: TPath) {\n\treturn {\n\t\tdirectory: `./public/assets${path}` as const,\n\t\tpublicPath: `/assets${path}` as const,\n\t\ttransformFilename(originalFilename: string) {\n\t\t\treturn slugify(originalFilename, { preserveCharacters: [\".\"] });\n\t\t},\n\t};\n}\n\nexport function createContentFieldOptions<TPath extends `/${string}/`>(assetPath: TPath) {\n\tconst assetPaths = createAssetOptions(assetPath);\n\tconst headingLevels = [2, 3, 4, 5] as const;\n\n\treturn {\n\t\theading: headingLevels,\n\t\timage: assetPaths,\n\t};\n}\n\nexport function createComponent<TPath extends `/${string}/`, TComponent extends ContentComponent>(\n\tcreateComponentFactory: (assetPath: TPath, locale: Locale) => TComponent,\n) {\n\treturn function createComponent(assetPath: TPath, locale: Locale) {\n\t\treturn createComponentFactory(assetPath, locale);\n\t};\n}\n\nexport function createCollectionPaths<TPath extends `/${string}/`>(path: TPath, locale: Locale) {\n\treturn {\n\t\tassetPath: `/content/${locale}${path}`,\n\t\tcontentPath: `./content/${locale}${path}*/`,\n\t} as const;\n}\n\nexport function createSingletonPaths<TPath extends `/${string}/`>(path: TPath, locale: Locale) {\n\treturn {\n\t\tassetPath: `/content/${locale}${path}`,\n\t\tcontentPath: `./content/${locale}${path}`,\n\t} as const;\n}\n\nexport function createCollection<\n\tTPath extends `/${string}/`,\n\tTSchema extends Record<string, ComponentSchema>,\n\tTSlugField extends string,\n>(\n\tpath: TPath,\n\tcreateLocalisedCollectionFactory: (\n\t\tpaths: ReturnType<typeof createCollectionPaths<TPath>>,\n\t\tlocale: Locale,\n\t) => Collection<TSchema, TSlugField>,\n) {\n\treturn function createLocalisedCollection(locale: Locale) {\n\t\tconst paths = createCollectionPaths(path, locale);\n\t\treturn createLocalisedCollectionFactory(paths, locale);\n\t};\n}\n\nexport function createSingleton<\n\tTPath extends `/${string}/`,\n\tSchema extends Record<string, ComponentSchema>,\n>(\n\tpath: TPath,\n\tcreateLocalisedSingletonFactory: (\n\t\tpaths: ReturnType<typeof createSingletonPaths<TPath>>,\n\t\tlocale: Locale,\n\t) => Singleton<Schema>,\n) {\n\treturn function createLocalisedSingleton(locale: Locale) {\n\t\tconst paths = createSingletonPaths(path, locale);\n\t\treturn createLocalisedSingletonFactory(paths, locale);\n\t};\n}\n\nexport function withI18nPrefix<TLabel extends string>(label: TLabel, locale: Locale) {\n\treturn `${locale}:${label}` as const;\n}\n\nexport type WithoutI18nPrefix<T extends string> = T extends `${Locale}:${infer U}` ? U : T;\n\nexport function createReader<\n\tTCollections extends Record<string, Collection<Record<string, ComponentSchema>, string>>,\n\tTSingletons extends Record<string, Singleton<Record<string, ComponentSchema>>>,\n>(\n\tconfig: Config<TCollections, TSingletons>,\n\tgetGitHubReaderConfig?: () => {\n\t\trepo: `${string}/${string}`;\n\t\tpathPrefix?: string;\n\t\tref?: string;\n\t\ttoken?: string;\n\t} | null,\n) {\n\tconst gitHubConfig = getGitHubReaderConfig?.();\n\n\tif (gitHubConfig != null) {\n\t\treturn createGitHubReader(config, gitHubConfig);\n\t}\n\n\treturn createLocalReader(process.cwd(), config);\n}\n\nexport function createReaders<\n\tTCollections extends Record<string, Collection<Record<string, ComponentSchema>, string>>,\n\tTSingletons extends Record<string, Singleton<Record<string, ComponentSchema>>>,\n\tTMdxContent extends MDXModule,\n>(\n\tconfig: Config<TCollections, TSingletons>,\n\tgetMdxContent: (code: string, locale: Locale, baseUrl: URL) => Promise<TMdxContent>,\n) {\n\tfunction createCollectionResource<TKeys extends WithoutI18nPrefix<keyof TCollections & string>>(\n\t\tname: TKeys,\n\t\tlocale: Locale,\n\t) {\n\t\tconst reader = createReader(config);\n\t\tconst collectionName = withI18nPrefix(name, locale);\n\n\t\tconst collectionReader = reader.collections[collectionName];\n\t\tconst collectionConfig = reader.config.collections?.[collectionName];\n\n\t\tassert(collectionConfig?.path);\n\n\t\tfunction baseUrl(id: string) {\n\t\t\treturn pathToFileURL(join(process.cwd(), collectionConfig!.path!.replace(/\\*+/, id)));\n\t\t}\n\n\t\tasync function compile(id: string, code: string) {\n\t\t\treturn getMdxContent(code, locale, baseUrl(id));\n\t\t}\n\n\t\tfunction list() {\n\t\t\treturn collectionReader.list();\n\t\t}\n\n\t\tasync function read(id: string) {\n\t\t\tconst data = await collectionReader.readOrThrow(id, { resolveLinkedFiles: true });\n\n\t\t\treturn {\n\t\t\t\tcollection: name,\n\t\t\t\tid,\n\t\t\t\tdata,\n\t\t\t\tcompile(code: string) {\n\t\t\t\t\treturn compile(id, code);\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\n\t\tasync function all() {\n\t\t\tconst ids = await list();\n\n\t\t\treturn Promise.all(ids.map(read));\n\t\t}\n\n\t\treturn {\n\t\t\tall,\n\t\t\tbaseUrl,\n\t\t\tcompile,\n\t\t\tlist,\n\t\t\tread,\n\t\t};\n\t}\n\n\tfunction createSingletonResource<TKeys extends WithoutI18nPrefix<keyof TSingletons & string>>(\n\t\tname: TKeys,\n\t\tlocale: Locale,\n\t) {\n\t\tconst reader = createReader(config);\n\t\tconst i18nName = withI18nPrefix(name, locale);\n\n\t\tconst singletonReader = reader.singletons[i18nName];\n\t\tconst singletonConfig = reader.config.singletons?.[i18nName];\n\n\t\tassert(singletonConfig?.path);\n\n\t\tfunction baseUrl() {\n\t\t\treturn pathToFileURL(join(process.cwd(), singletonConfig!.path!));\n\t\t}\n\n\t\tasync function compile(code: string) {\n\t\t\treturn getMdxContent(code, locale, baseUrl());\n\t\t}\n\n\t\tasync function read() {\n\t\t\tconst data = await singletonReader.readOrThrow({ resolveLinkedFiles: true });\n\n\t\t\treturn {\n\t\t\t\tsingleton: name,\n\t\t\t\tdata,\n\t\t\t\tcompile,\n\t\t\t};\n\t\t}\n\n\t\treturn {\n\t\t\tbaseUrl,\n\t\t\tcompile,\n\t\t\tread,\n\t\t};\n\t}\n\n\treturn {\n\t\tcreateCollectionResource,\n\t\tcreateSingletonResource,\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
package/dist/reader.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as url from 'url';
|
|
2
|
+
import * as _keystatic_core from '@keystatic/core';
|
|
3
|
+
import { Collection, ComponentSchema, Singleton, Config } from '@keystatic/core';
|
|
4
|
+
import * as _keystatic_core_reader_github from '@keystatic/core/reader/github';
|
|
5
|
+
import { MDXModule } from 'mdx/types';
|
|
6
|
+
import { Locale } from './config.js';
|
|
7
|
+
import { WithoutI18nPrefix } from './with-i18n-prefix.js';
|
|
8
|
+
|
|
9
|
+
declare function createReader<TCollections extends Record<string, Collection<Record<string, ComponentSchema>, string>>, TSingletons extends Record<string, Singleton<Record<string, ComponentSchema>>>>(config: Config<TCollections, TSingletons>, getGitHubReaderConfig?: () => {
|
|
10
|
+
repo: `${string}/${string}`;
|
|
11
|
+
pathPrefix?: string;
|
|
12
|
+
ref?: string;
|
|
13
|
+
token?: string;
|
|
14
|
+
} | null): _keystatic_core_reader_github.Reader<TCollections, TSingletons>;
|
|
15
|
+
declare function createReaders<TCollections extends Record<string, Collection<Record<string, ComponentSchema>, string>>, TSingletons extends Record<string, Singleton<Record<string, ComponentSchema>>>, TLocale extends Locale, TMdxContent extends MDXModule>(config: Config<TCollections, TSingletons>, getMdxContent: (code: string, locale: TLocale, baseUrl: URL) => Promise<TMdxContent>): {
|
|
16
|
+
createCollectionResource: <TKeys extends WithoutI18nPrefix<keyof TCollections & string, TLocale>>(name: TKeys, locale: TLocale) => {
|
|
17
|
+
all: () => Promise<{
|
|
18
|
+
collection: TKeys;
|
|
19
|
+
id: string;
|
|
20
|
+
data: TCollections[`${TLocale}:${TKeys}`]["schema"] extends infer T extends Record<string, ComponentSchema> ? { [Key in keyof T]: TCollections[`${TLocale}:${TKeys}`]["slugField"] extends infer T_1 ? T_1 extends TCollections[`${TLocale}:${TKeys}`]["slugField"] ? T_1 extends Key ? TCollections[`${TLocale}:${TKeys}`]["schema"][Key] extends _keystatic_core.SlugFormField<any, any, any, infer SlugSerializedValue> ? SlugSerializedValue : _keystatic_core.ValueForReadingDeep<TCollections[`${TLocale}:${TKeys}`]["schema"][Key]> : _keystatic_core.ValueForReadingDeep<TCollections[`${TLocale}:${TKeys}`]["schema"][Key]> : never : never; } : never;
|
|
21
|
+
compile(code: string): Promise<TMdxContent>;
|
|
22
|
+
}[]>;
|
|
23
|
+
baseUrl: (id: string) => url.URL;
|
|
24
|
+
compile: (id: string, code: string) => Promise<TMdxContent>;
|
|
25
|
+
list: () => Promise<string[]>;
|
|
26
|
+
read: (id: string) => Promise<{
|
|
27
|
+
collection: TKeys;
|
|
28
|
+
id: string;
|
|
29
|
+
data: TCollections[`${TLocale}:${TKeys}`]["schema"] extends infer T extends Record<string, ComponentSchema> ? { [Key in keyof T]: TCollections[`${TLocale}:${TKeys}`]["slugField"] extends infer T_1 ? T_1 extends TCollections[`${TLocale}:${TKeys}`]["slugField"] ? T_1 extends Key ? TCollections[`${TLocale}:${TKeys}`]["schema"][Key] extends _keystatic_core.SlugFormField<any, any, any, infer SlugSerializedValue> ? SlugSerializedValue : _keystatic_core.ValueForReadingDeep<TCollections[`${TLocale}:${TKeys}`]["schema"][Key]> : _keystatic_core.ValueForReadingDeep<TCollections[`${TLocale}:${TKeys}`]["schema"][Key]> : never : never; } : never;
|
|
30
|
+
compile(code: string): Promise<TMdxContent>;
|
|
31
|
+
}>;
|
|
32
|
+
};
|
|
33
|
+
createSingletonResource: <TKeys extends WithoutI18nPrefix<keyof TSingletons & string, TLocale>>(name: TKeys, locale: TLocale) => {
|
|
34
|
+
baseUrl: () => url.URL;
|
|
35
|
+
compile: (code: string) => Promise<TMdxContent>;
|
|
36
|
+
read: () => Promise<{
|
|
37
|
+
singleton: TKeys;
|
|
38
|
+
data: TSingletons[`${TLocale}:${TKeys}`]["schema"] extends infer T extends Record<string, ComponentSchema> ? { readonly [Key in keyof T]: _keystatic_core.ValueForReadingDeep<TSingletons[`${TLocale}:${TKeys}`]["schema"][Key]>; } : never;
|
|
39
|
+
compile: (code: string) => Promise<TMdxContent>;
|
|
40
|
+
}>;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export { createReader, createReaders };
|
package/dist/reader.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { withI18nPrefix } from './chunk-M7J4ISS4.js';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { pathToFileURL } from 'node:url';
|
|
5
|
+
import { createReader as createReader$1 } from '@keystatic/core/reader';
|
|
6
|
+
import { createGitHubReader } from '@keystatic/core/reader/github';
|
|
7
|
+
|
|
8
|
+
function createReader(config, getGitHubReaderConfig) {
|
|
9
|
+
const gitHubConfig = getGitHubReaderConfig?.();
|
|
10
|
+
if (gitHubConfig != null) {
|
|
11
|
+
return createGitHubReader(config, gitHubConfig);
|
|
12
|
+
}
|
|
13
|
+
return createReader$1(process.cwd(), config);
|
|
14
|
+
}
|
|
15
|
+
function createReaders(config, getMdxContent) {
|
|
16
|
+
function createCollectionResource(name, locale) {
|
|
17
|
+
const reader = createReader(config);
|
|
18
|
+
const collectionName = withI18nPrefix(name, locale);
|
|
19
|
+
const collectionReader = reader.collections[collectionName];
|
|
20
|
+
const collectionConfig = reader.config.collections?.[collectionName];
|
|
21
|
+
assert(collectionConfig?.path);
|
|
22
|
+
function baseUrl(id) {
|
|
23
|
+
return pathToFileURL(join(process.cwd(), collectionConfig.path.replace(/\*+/, id)));
|
|
24
|
+
}
|
|
25
|
+
async function compile(id, code) {
|
|
26
|
+
return getMdxContent(code, locale, baseUrl(id));
|
|
27
|
+
}
|
|
28
|
+
function list() {
|
|
29
|
+
return collectionReader.list();
|
|
30
|
+
}
|
|
31
|
+
async function read(id) {
|
|
32
|
+
const data = await collectionReader.readOrThrow(id, { resolveLinkedFiles: true });
|
|
33
|
+
return {
|
|
34
|
+
collection: name,
|
|
35
|
+
id,
|
|
36
|
+
data,
|
|
37
|
+
compile(code) {
|
|
38
|
+
return compile(id, code);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
async function all() {
|
|
43
|
+
const ids = await list();
|
|
44
|
+
return Promise.all(ids.map(read));
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
all,
|
|
48
|
+
baseUrl,
|
|
49
|
+
compile,
|
|
50
|
+
list,
|
|
51
|
+
read
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function createSingletonResource(name, locale) {
|
|
55
|
+
const reader = createReader(config);
|
|
56
|
+
const i18nName = withI18nPrefix(name, locale);
|
|
57
|
+
const singletonReader = reader.singletons[i18nName];
|
|
58
|
+
const singletonConfig = reader.config.singletons?.[i18nName];
|
|
59
|
+
assert(singletonConfig?.path);
|
|
60
|
+
function baseUrl() {
|
|
61
|
+
return pathToFileURL(join(process.cwd(), singletonConfig.path));
|
|
62
|
+
}
|
|
63
|
+
async function compile(code) {
|
|
64
|
+
return getMdxContent(code, locale, baseUrl());
|
|
65
|
+
}
|
|
66
|
+
async function read() {
|
|
67
|
+
const data = await singletonReader.readOrThrow({ resolveLinkedFiles: true });
|
|
68
|
+
return {
|
|
69
|
+
singleton: name,
|
|
70
|
+
data,
|
|
71
|
+
compile
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
baseUrl,
|
|
76
|
+
compile,
|
|
77
|
+
read
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
createCollectionResource,
|
|
82
|
+
createSingletonResource
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export { createReader, createReaders };
|
|
87
|
+
//# sourceMappingURL=reader.js.map
|
|
88
|
+
//# sourceMappingURL=reader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/reader.ts"],"names":["createLocalReader"],"mappings":";;;;;;;AAYO,SAAS,YAAA,CAIf,QACA,qBAMC,EAAA;AACD,EAAA,MAAM,eAAe,qBAAwB,IAAA,CAAA;AAE7C,EAAA,IAAI,gBAAgB,IAAM,EAAA;AACzB,IAAO,OAAA,kBAAA,CAAmB,QAAQ,YAAY,CAAA,CAAA;AAAA,GAC/C;AAEA,EAAA,OAAOA,cAAkB,CAAA,OAAA,CAAQ,GAAI,EAAA,EAAG,MAAM,CAAA,CAAA;AAC/C,CAAA;AAEO,SAAS,aAAA,CAMf,QACA,aACC,EAAA;AACD,EAAS,SAAA,wBAAA,CAEP,MAAa,MAAiB,EAAA;AAC/B,IAAM,MAAA,MAAA,GAAS,aAAa,MAAM,CAAA,CAAA;AAClC,IA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":"reader.js","sourcesContent":["import assert from \"node:assert/strict\";\nimport { join } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\n\nimport type { Collection, ComponentSchema, Config, Singleton } from \"@keystatic/core\";\nimport { createReader as createLocalReader } from \"@keystatic/core/reader\";\nimport { createGitHubReader } from \"@keystatic/core/reader/github\";\nimport type { MDXModule } from \"mdx/types\";\n\nimport type { Locale } from \"./config\";\nimport { withI18nPrefix, type WithoutI18nPrefix } from \"./with-i18n-prefix\";\n\nexport function createReader<\n\tTCollections extends Record<string, Collection<Record<string, ComponentSchema>, string>>,\n\tTSingletons extends Record<string, Singleton<Record<string, ComponentSchema>>>,\n>(\n\tconfig: Config<TCollections, TSingletons>,\n\tgetGitHubReaderConfig?: () => {\n\t\trepo: `${string}/${string}`;\n\t\tpathPrefix?: string;\n\t\tref?: string;\n\t\ttoken?: string;\n\t} | null,\n) {\n\tconst gitHubConfig = getGitHubReaderConfig?.();\n\n\tif (gitHubConfig != null) {\n\t\treturn createGitHubReader(config, gitHubConfig);\n\t}\n\n\treturn createLocalReader(process.cwd(), config);\n}\n\nexport function createReaders<\n\tTCollections extends Record<string, Collection<Record<string, ComponentSchema>, string>>,\n\tTSingletons extends Record<string, Singleton<Record<string, ComponentSchema>>>,\n\tTLocale extends Locale,\n\tTMdxContent extends MDXModule,\n>(\n\tconfig: Config<TCollections, TSingletons>,\n\tgetMdxContent: (code: string, locale: TLocale, baseUrl: URL) => Promise<TMdxContent>,\n) {\n\tfunction createCollectionResource<\n\t\tTKeys extends WithoutI18nPrefix<keyof TCollections & string, TLocale>,\n\t>(name: TKeys, locale: TLocale) {\n\t\tconst reader = createReader(config);\n\t\tconst collectionName = withI18nPrefix(name, locale);\n\n\t\tconst collectionReader = reader.collections[collectionName];\n\t\tconst collectionConfig = reader.config.collections?.[collectionName];\n\n\t\tassert(collectionConfig?.path);\n\n\t\tfunction baseUrl(id: string) {\n\t\t\treturn pathToFileURL(join(process.cwd(), collectionConfig!.path!.replace(/\\*+/, id)));\n\t\t}\n\n\t\tasync function compile(id: string, code: string) {\n\t\t\treturn getMdxContent(code, locale, baseUrl(id));\n\t\t}\n\n\t\tfunction list() {\n\t\t\treturn collectionReader.list();\n\t\t}\n\n\t\tasync function read(id: string) {\n\t\t\tconst data = await collectionReader.readOrThrow(id, { resolveLinkedFiles: true });\n\n\t\t\treturn {\n\t\t\t\tcollection: name,\n\t\t\t\tid,\n\t\t\t\tdata,\n\t\t\t\tcompile(code: string) {\n\t\t\t\t\treturn compile(id, code);\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\n\t\tasync function all() {\n\t\t\tconst ids = await list();\n\n\t\t\treturn Promise.all(ids.map(read));\n\t\t}\n\n\t\treturn {\n\t\t\tall,\n\t\t\tbaseUrl,\n\t\t\tcompile,\n\t\t\tlist,\n\t\t\tread,\n\t\t};\n\t}\n\n\tfunction createSingletonResource<\n\t\tTKeys extends WithoutI18nPrefix<keyof TSingletons & string, TLocale>,\n\t>(name: TKeys, locale: TLocale) {\n\t\tconst reader = createReader(config);\n\t\tconst i18nName = withI18nPrefix(name, locale);\n\n\t\tconst singletonReader = reader.singletons[i18nName];\n\t\tconst singletonConfig = reader.config.singletons?.[i18nName];\n\n\t\tassert(singletonConfig?.path);\n\n\t\tfunction baseUrl() {\n\t\t\treturn pathToFileURL(join(process.cwd(), singletonConfig!.path!));\n\t\t}\n\n\t\tasync function compile(code: string) {\n\t\t\treturn getMdxContent(code, locale, baseUrl());\n\t\t}\n\n\t\tasync function read() {\n\t\t\tconst data = await singletonReader.readOrThrow({ resolveLinkedFiles: true });\n\n\t\t\treturn {\n\t\t\t\tsingleton: name,\n\t\t\t\tdata,\n\t\t\t\tcompile,\n\t\t\t};\n\t\t}\n\n\t\treturn {\n\t\t\tbaseUrl,\n\t\t\tcompile,\n\t\t\tread,\n\t\t};\n\t}\n\n\treturn {\n\t\tcreateCollectionResource,\n\t\tcreateSingletonResource,\n\t};\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ComponentSchema, Collection, Singleton } from '@keystatic/core';
|
|
2
|
+
import { Locale } from './config.js';
|
|
3
|
+
|
|
4
|
+
declare function createCollectionPaths<TPath extends `/${string}/`>(path: TPath, locale: Locale): {
|
|
5
|
+
readonly assetPath: `/content/${string}${TPath}`;
|
|
6
|
+
readonly contentPath: `./content/${string}${TPath}*/`;
|
|
7
|
+
};
|
|
8
|
+
declare function createSingletonPaths<TPath extends `/${string}/`>(path: TPath, locale: Locale): {
|
|
9
|
+
readonly assetPath: `/content/${string}${TPath}`;
|
|
10
|
+
readonly contentPath: `./content/${string}${TPath}`;
|
|
11
|
+
};
|
|
12
|
+
declare function createCollection<TPath extends `/${string}/`, TLocale extends Locale, TSchema extends Record<string, ComponentSchema>, TSlugField extends string>(path: TPath, createLocalisedCollectionFactory: (paths: ReturnType<typeof createCollectionPaths<TPath>>, locale: TLocale) => Collection<TSchema, TSlugField>): (locale: TLocale) => Collection<TSchema, TSlugField>;
|
|
13
|
+
declare function createSingleton<TPath extends `/${string}/`, TLocale extends Locale, TSchema extends Record<string, ComponentSchema>>(path: TPath, createLocalisedSingletonFactory: (paths: ReturnType<typeof createSingletonPaths<TPath>>, locale: TLocale) => Singleton<TSchema>): (locale: TLocale) => Singleton<TSchema>;
|
|
14
|
+
|
|
15
|
+
export { createCollection, createCollectionPaths, createSingleton, createSingletonPaths };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"resources.js"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Locale } from './config.js';
|
|
2
|
+
|
|
3
|
+
declare function withI18nPrefix<TLabel extends string, TLocale extends Locale>(label: TLabel, locale: TLocale): `${TLocale}:${TLabel}`;
|
|
4
|
+
type WithoutI18nPrefix<T extends string, TLocale extends Locale> = T extends `${TLocale}:${infer U}` ? U : T;
|
|
5
|
+
|
|
6
|
+
export { type WithoutI18nPrefix, withI18nPrefix };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"with-i18n-prefix.js"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acdh-oeaw/keystatic-lib",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "./dist/index.js",
|
|
7
6
|
"exports": {
|
|
8
|
-
".": "./dist/index.js"
|
|
7
|
+
".": "./dist/index.js",
|
|
8
|
+
"./reader": "./dist/reader.js"
|
|
9
9
|
},
|
|
10
10
|
"files": [
|
|
11
11
|
"dist"
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"pre-push": "pnpm run validate"
|
|
63
63
|
},
|
|
64
64
|
"scripts": {
|
|
65
|
-
"build": "tsup
|
|
65
|
+
"build": "tsup",
|
|
66
66
|
"changeset:add": "changeset add",
|
|
67
67
|
"changeset:status": "changeset status --verbose",
|
|
68
68
|
"ci:release": "changeset publish",
|
package/readme.md
CHANGED
|
@@ -16,7 +16,7 @@ provide the languages supported in your project via typescript module augmentati
|
|
|
16
16
|
// ./types/keystatic.d.ts
|
|
17
17
|
|
|
18
18
|
declare module "@acdh-oeaw/keystatic-lib" {
|
|
19
|
-
export interface
|
|
19
|
+
export interface KeystaticConfig {
|
|
20
20
|
locales: "de" | "en";
|
|
21
21
|
}
|
|
22
22
|
}
|
|
@@ -122,17 +122,60 @@ export default config({
|
|
|
122
122
|
|
|
123
123
|
### read and render entries
|
|
124
124
|
|
|
125
|
-
|
|
125
|
+
create resource readers by passing the keystatic config and a mdx compiler function to
|
|
126
|
+
`createReaders`:
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
// ./lib/keystatic/readers.ts
|
|
130
|
+
|
|
131
|
+
import { createReaders } from "@acdh-oeaw/keystatic-lib/reader";
|
|
132
|
+
import { createFormatAwareProcessors } from "@mdx-js/mdx/internal-create-format-aware-processors";
|
|
133
|
+
|
|
134
|
+
import config from "../../keystatic.config";
|
|
135
|
+
|
|
136
|
+
function getMdxContent(code: string, locale: Locale, baseUrl: URL) {
|
|
137
|
+
const processor = await createFormatAwareProcessors({
|
|
138
|
+
/** Set this to `html` in astro. */
|
|
139
|
+
// elementAttributeNameCase: "html",
|
|
140
|
+
format: "mdx",
|
|
141
|
+
outputFormat: "function-body",
|
|
142
|
+
providerImportSource: "#",
|
|
143
|
+
/** ... */
|
|
144
|
+
});
|
|
145
|
+
const file = await processor.process(code);
|
|
146
|
+
return run(file, { ...runtime, baseUrl, useMDXComponents });
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function useMDXComponents() {
|
|
150
|
+
/** Provide component mappings, which should be available to all mdx content. */
|
|
151
|
+
return {
|
|
152
|
+
// a: LocaleLink,
|
|
153
|
+
// Video,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const { createCollectionResource, createSingletonResource } = createReaders(config, getMdxContent);
|
|
158
|
+
|
|
159
|
+
export { createCollectionResource, createSingletonResource };
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
a reader has methods for reading a single resource entry (`read`), reading all resource entries
|
|
163
|
+
(`all`), and returning a list of entry identifiers (`list`).
|
|
164
|
+
|
|
165
|
+
a resource entry returns `id`, `collection`/`singleton`, and `data`, as well as a `compile` method,
|
|
166
|
+
which can be used to transform rich-text field content to a jsx component.
|
|
167
|
+
|
|
168
|
+
#### astro
|
|
126
169
|
|
|
127
170
|
```astro
|
|
128
171
|
---
|
|
129
172
|
// ./src/pages/[locale]/[id].astro
|
|
130
173
|
|
|
131
|
-
import { createCollectionResource } from "@acdh-ch/keystatic-lib";
|
|
132
174
|
import type { GetStaticPathsResult } from "astro";
|
|
133
175
|
|
|
134
176
|
import { locales } from "@/config/i18n.config";
|
|
135
177
|
import Layout from "@/layouts/page-layout.astro";
|
|
178
|
+
import { createCollectionResource } from "@/lib/keystatic/readers";
|
|
136
179
|
|
|
137
180
|
export async function getStaticPaths() {
|
|
138
181
|
return (
|
|
@@ -161,14 +204,13 @@ const { default: Content } = await page.compile(content);
|
|
|
161
204
|
</Layout>
|
|
162
205
|
```
|
|
163
206
|
|
|
164
|
-
|
|
207
|
+
#### next.js
|
|
165
208
|
|
|
166
209
|
```tsx
|
|
167
210
|
// ./app/[locale]/[id]/page.tsx
|
|
168
211
|
|
|
169
|
-
import { createCollectionResource } from "@acdh-ch/keystatic-lib";
|
|
170
|
-
|
|
171
212
|
import type { Locale } from "@/config/i18n.config";
|
|
213
|
+
import { createCollectionResource } from "@/lib/keystatic/readers";
|
|
172
214
|
|
|
173
215
|
interface PageProps {
|
|
174
216
|
params: {
|