@acdh-oeaw/keystatic-lib 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +53 -0
- package/dist/index.js +68 -0
- package/dist/index.js.map +1 -0
- package/license +18 -0
- package/package.json +79 -0
- package/readme.md +121 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import * as _keystatic_core_reader_github from '@keystatic/core/reader/github';
|
|
2
|
+
import { ComponentSchema, Collection, Singleton, Config } from '@keystatic/core';
|
|
3
|
+
import { ContentComponent } from '@keystatic/core/content-components';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Provide supported locales by augmenting the interface:
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* export interface KeystaticConfig {
|
|
10
|
+
* locales: "de" | "en"
|
|
11
|
+
* }
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
interface KeystaticConfig {
|
|
15
|
+
}
|
|
16
|
+
type Locale = KeystaticConfig extends {
|
|
17
|
+
locales: string;
|
|
18
|
+
} ? KeystaticConfig["locales"] : string;
|
|
19
|
+
declare function createLabel(label: string, locale: Locale): string;
|
|
20
|
+
declare function createAssetOptions<TPath extends `/${string}/`>(path: TPath): {
|
|
21
|
+
directory: `./public/assets${TPath}`;
|
|
22
|
+
publicPath: `/assets${TPath}`;
|
|
23
|
+
transformFilename(originalFilename: string): string;
|
|
24
|
+
};
|
|
25
|
+
declare function createContentFieldOptions<TPath extends `/${string}/`>(assetPath: TPath): {
|
|
26
|
+
heading: readonly [2, 3, 4, 5];
|
|
27
|
+
image: {
|
|
28
|
+
directory: `./public/assets${TPath}`;
|
|
29
|
+
publicPath: `/assets${TPath}`;
|
|
30
|
+
transformFilename(originalFilename: string): string;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
declare function createComponent<TPath extends `/${string}/`, TComponent extends ContentComponent>(createComponentFactory: (assetPath: TPath, locale: Locale) => TComponent): (assetPath: TPath, locale: Locale) => TComponent;
|
|
34
|
+
declare function createCollectionPaths<TPath extends `/${string}/`>(path: TPath, locale: Locale): {
|
|
35
|
+
readonly assetPath: `/content/${string}${TPath}`;
|
|
36
|
+
readonly contentPath: `./content/${string}${TPath}*/`;
|
|
37
|
+
};
|
|
38
|
+
declare function createSingletonPaths<TPath extends `/${string}/`>(path: TPath, locale: Locale): {
|
|
39
|
+
readonly assetPath: `/content/${string}${TPath}`;
|
|
40
|
+
readonly contentPath: `./content/${string}${TPath}`;
|
|
41
|
+
};
|
|
42
|
+
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>;
|
|
43
|
+
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>;
|
|
44
|
+
declare function withI18nPrefix<TLabel extends string, TLocale extends Locale>(label: TLabel, locale: TLocale): `${TLocale}:${TLabel}`;
|
|
45
|
+
type WithoutI18nPrefix<T extends string> = T extends `${Locale}:${infer U}` ? U : T;
|
|
46
|
+
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?: () => {
|
|
47
|
+
repo: `${string}/${string}`;
|
|
48
|
+
pathPrefix?: string;
|
|
49
|
+
ref?: string;
|
|
50
|
+
token?: string;
|
|
51
|
+
} | null): _keystatic_core_reader_github.Reader<TCollections, TSingletons>;
|
|
52
|
+
|
|
53
|
+
export { type KeystaticConfig, type WithoutI18nPrefix, createAssetOptions, createCollection, createCollectionPaths, createComponent, createContentFieldOptions, createLabel, createReader, createSingleton, createSingletonPaths, withI18nPrefix };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { createReader as createReader$1 } from '@keystatic/core/reader';
|
|
2
|
+
import { createGitHubReader } from '@keystatic/core/reader/github';
|
|
3
|
+
import slugify from '@sindresorhus/slugify';
|
|
4
|
+
|
|
5
|
+
// src/index.ts
|
|
6
|
+
function createLabel(label, locale) {
|
|
7
|
+
return `${label} (${locale})`;
|
|
8
|
+
}
|
|
9
|
+
function createAssetOptions(path) {
|
|
10
|
+
return {
|
|
11
|
+
directory: `./public/assets${path}`,
|
|
12
|
+
publicPath: `/assets${path}`,
|
|
13
|
+
transformFilename(originalFilename) {
|
|
14
|
+
return slugify(originalFilename, { preserveCharacters: ["."] });
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function createContentFieldOptions(assetPath) {
|
|
19
|
+
const assetPaths = createAssetOptions(assetPath);
|
|
20
|
+
const headingLevels = [2, 3, 4, 5];
|
|
21
|
+
return {
|
|
22
|
+
heading: headingLevels,
|
|
23
|
+
image: assetPaths
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function createComponent(createComponentFactory) {
|
|
27
|
+
return function createComponent2(assetPath, locale) {
|
|
28
|
+
return createComponentFactory(assetPath, locale);
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function createCollectionPaths(path, locale) {
|
|
32
|
+
return {
|
|
33
|
+
assetPath: `/content/${locale}${path}`,
|
|
34
|
+
contentPath: `./content/${locale}${path}*/`
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function createSingletonPaths(path, locale) {
|
|
38
|
+
return {
|
|
39
|
+
assetPath: `/content/${locale}${path}`,
|
|
40
|
+
contentPath: `./content/${locale}${path}`
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function createCollection(path, createLocalisedCollectionFactory) {
|
|
44
|
+
return function createLocalisedCollection(locale) {
|
|
45
|
+
const paths = createCollectionPaths(path, locale);
|
|
46
|
+
return createLocalisedCollectionFactory(paths, locale);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function createSingleton(path, createLocalisedSingletonFactory) {
|
|
50
|
+
return function createLocalisedSingleton(locale) {
|
|
51
|
+
const paths = createSingletonPaths(path, locale);
|
|
52
|
+
return createLocalisedSingletonFactory(paths, locale);
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function withI18nPrefix(label, locale) {
|
|
56
|
+
return `${locale}:${label}`;
|
|
57
|
+
}
|
|
58
|
+
function createReader(config, getGitHubReaderConfig) {
|
|
59
|
+
const gitHubConfig = getGitHubReaderConfig?.();
|
|
60
|
+
if (gitHubConfig != null) {
|
|
61
|
+
return createGitHubReader(config, gitHubConfig);
|
|
62
|
+
}
|
|
63
|
+
return createReader$1(process.cwd(), config);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export { createAssetOptions, createCollection, createCollectionPaths, createComponent, createContentFieldOptions, createLabel, createReader, createSingleton, createSingletonPaths, withI18nPrefix };
|
|
67
|
+
//# sourceMappingURL=index.js.map
|
|
68
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["createComponent","createLocalReader"],"mappings":";;;;;AAmBO,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,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,CAKf,MACA,gCAIC,EAAA;AACD,EAAO,OAAA,SAAS,0BAA0B,MAAgB,EAAA;AACzD,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,CAIf,MACA,+BAIC,EAAA;AACD,EAAO,OAAA,SAAS,yBAAyB,MAAgB,EAAA;AACxD,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,CAAA;AAEO,SAAS,cAAA,CACf,OACA,MACC,EAAA;AACD,EAAO,OAAA,CAAA,EAAG,MAAM,CAAA,CAAA,EAAI,KAAK,CAAA,CAAA,CAAA;AAC1B,CAAA;AAIO,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,OAAOC,cAAkB,CAAA,OAAA,CAAQ,GAAI,EAAA,EAAG,MAAM,CAAA,CAAA;AAC/C","file":"index.js","sourcesContent":["import 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\";\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, TLocale extends Locale>(\n\tlabel: TLabel,\n\tlocale: TLocale,\n) {\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"]}
|
package/license
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Austrian Centre for Digital Humanities & Cultural Heritage
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
|
6
|
+
associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
7
|
+
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
|
8
|
+
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
12
|
+
portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
|
15
|
+
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
16
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
|
|
17
|
+
OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
18
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/package.json
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@acdh-oeaw/keystatic-lib",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"sideEffects": false,
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=22",
|
|
16
|
+
"pnpm": "9.x"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@sindresorhus/slugify": "^2.2.1"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"@keystatic/core": "0.x"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@acdh-oeaw/commitlint-config": "^1.0.0",
|
|
26
|
+
"@acdh-oeaw/eslint-config": "^2.0.1",
|
|
27
|
+
"@acdh-oeaw/eslint-config-node": "^2.0.1",
|
|
28
|
+
"@acdh-oeaw/prettier-config": "^2.0.0",
|
|
29
|
+
"@acdh-oeaw/tsconfig-lib": "^1.1.0",
|
|
30
|
+
"@changesets/changelog-github": "^0.5.0",
|
|
31
|
+
"@changesets/cli": "^2.27.8",
|
|
32
|
+
"@commitlint/cli": "^18.6.1",
|
|
33
|
+
"@keystatic/core": "^0.5.34",
|
|
34
|
+
"@types/node": "^22.5.4",
|
|
35
|
+
"eslint": "^9.10.0",
|
|
36
|
+
"eslint-config-flat-gitignore": "^0.3.0",
|
|
37
|
+
"globals": "^15.9.0",
|
|
38
|
+
"is-ci": "^3.0.1",
|
|
39
|
+
"lint-staged": "^15.2.10",
|
|
40
|
+
"npm-run-all2": "^6.2.2",
|
|
41
|
+
"prettier": "^3.3.3",
|
|
42
|
+
"simple-git-hooks": "^2.11.1",
|
|
43
|
+
"tsup": "^8.2.4",
|
|
44
|
+
"tsx": "^4.19.0",
|
|
45
|
+
"typescript": "^5.6.2",
|
|
46
|
+
"uvu": "^0.5.6"
|
|
47
|
+
},
|
|
48
|
+
"commitlint": {
|
|
49
|
+
"extends": "@acdh-oeaw/commitlint-config"
|
|
50
|
+
},
|
|
51
|
+
"lint-staged": {
|
|
52
|
+
"*.ts": [
|
|
53
|
+
"eslint --cache --fix",
|
|
54
|
+
"prettier --cache --cache-location ./.prettiercache --write"
|
|
55
|
+
],
|
|
56
|
+
"*.!(ts)": "prettier --cache --cache-location ./.prettiercache --ignore-unknown --write"
|
|
57
|
+
},
|
|
58
|
+
"prettier": "@acdh-oeaw/prettier-config",
|
|
59
|
+
"simple-git-hooks": {
|
|
60
|
+
"commit-msg": "pnpm exec commitlint --edit",
|
|
61
|
+
"pre-commit": "pnpm exec lint-staged",
|
|
62
|
+
"pre-push": "pnpm run validate"
|
|
63
|
+
},
|
|
64
|
+
"scripts": {
|
|
65
|
+
"build": "tsup",
|
|
66
|
+
"changeset:add": "changeset add",
|
|
67
|
+
"changeset:status": "changeset status --verbose",
|
|
68
|
+
"ci:release": "changeset publish",
|
|
69
|
+
"ci:version": "changeset version && prettier \"**/CHANGELOG.md\" --write",
|
|
70
|
+
"format:check": "prettier . --cache --cache-location ./.prettiercache --check --ignore-path ./.gitignore",
|
|
71
|
+
"format:fix": "pnpm run format:check --write",
|
|
72
|
+
"lint:check": "eslint . --cache",
|
|
73
|
+
"lint:fix": "pnpm run lint:check --fix",
|
|
74
|
+
"setup": "is-ci || simple-git-hooks",
|
|
75
|
+
"test": "NODE_OPTIONS=\"--import tsx\" uvu",
|
|
76
|
+
"types:check": "tsc --noEmit",
|
|
77
|
+
"validate": "run-p format:check lint:check types:check test"
|
|
78
|
+
}
|
|
79
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# keystatic lib
|
|
2
|
+
|
|
3
|
+
utilities for working with multi-language [`keystatic`](https://keystatic.com) collections.
|
|
4
|
+
|
|
5
|
+
## how to install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm i @acdh-oeaw/keystatic-lib
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## how to use
|
|
12
|
+
|
|
13
|
+
provide the languages supported in your project via typescript module augmentation:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
// ./types/keystatic.d.ts
|
|
17
|
+
|
|
18
|
+
declare module "@acdh-oeaw/keystatic-lib" {
|
|
19
|
+
export interface Config {
|
|
20
|
+
locales: "de" | "en";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### create components (rich text editor widgets)
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
// ./lib/keystatic/components.ts
|
|
29
|
+
|
|
30
|
+
import { createComponent } from "@acdh-oeaw/keystatic-lib";
|
|
31
|
+
import { wrapper } from "@keystatic/core/content-components";
|
|
32
|
+
|
|
33
|
+
export const Video = createComponent((assetPath, locale) => {
|
|
34
|
+
return wrapper({
|
|
35
|
+
label: "Video",
|
|
36
|
+
schema: {
|
|
37
|
+
/** ... */
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### create collections and singletons
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
// ./lib/keystatic/resources.ts
|
|
47
|
+
|
|
48
|
+
import {
|
|
49
|
+
createAssetOptions,
|
|
50
|
+
createCollection,
|
|
51
|
+
createContentFieldOptions,
|
|
52
|
+
createSingleton,
|
|
53
|
+
createLabel,
|
|
54
|
+
} from "@acdh-oeaw/keystatic-lib";
|
|
55
|
+
import { collection, singleton } from "@keystatic/core";
|
|
56
|
+
|
|
57
|
+
import { Video } from "./lib/keystatic/components";
|
|
58
|
+
|
|
59
|
+
export const pages = createCollection("/pages/", (paths, locale) => {
|
|
60
|
+
return collection({
|
|
61
|
+
label: createLabel("Pages", locale),
|
|
62
|
+
path: paths.contentPath,
|
|
63
|
+
slugField: "title",
|
|
64
|
+
format: { contentField: "content" },
|
|
65
|
+
entryLayout: "content",
|
|
66
|
+
columns: ["title"],
|
|
67
|
+
schema: {
|
|
68
|
+
title: fields.slug({
|
|
69
|
+
name: {
|
|
70
|
+
label: "Title",
|
|
71
|
+
validation: { isRequired: true },
|
|
72
|
+
},
|
|
73
|
+
}),
|
|
74
|
+
image: fields.image({
|
|
75
|
+
label: "Image",
|
|
76
|
+
validation: { isRequired: false },
|
|
77
|
+
...createAssetOptions(paths.assetPath),
|
|
78
|
+
}),
|
|
79
|
+
content: fields.mdx({
|
|
80
|
+
label: "Content",
|
|
81
|
+
options: createContentFieldOptions(paths.assetPath),
|
|
82
|
+
components: {
|
|
83
|
+
Video: Video(paths.assetPath, locale),
|
|
84
|
+
},
|
|
85
|
+
}),
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
export const metadata = createSingleton("/metadata/", (paths, locale) => {
|
|
91
|
+
return singleton({
|
|
92
|
+
label: createLabel("Metadata", locale),
|
|
93
|
+
path: paths.contentPath,
|
|
94
|
+
format: { data: "json" },
|
|
95
|
+
entryLayout: "form",
|
|
96
|
+
schema: {
|
|
97
|
+
/** ... */
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
// ./keystatic.config.ts
|
|
105
|
+
|
|
106
|
+
import { withI18nPrefix } from "@acdh-oeaw/keystatic-lib";
|
|
107
|
+
import { config } from "@keystatic/core";
|
|
108
|
+
|
|
109
|
+
import { metadata, pages } from "./lib/keystatic/resources";
|
|
110
|
+
|
|
111
|
+
export default config({
|
|
112
|
+
collections: {
|
|
113
|
+
[withI18nPrefix("pages", "de")]: pages("de"),
|
|
114
|
+
[withI18nPrefix("pages", "en")]: pages("en"),
|
|
115
|
+
},
|
|
116
|
+
singletons: {
|
|
117
|
+
[withI18nPrefix("metadata", "de")]: metadata("de"),
|
|
118
|
+
[withI18nPrefix("metadata", "en")]: metadata("en"),
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
```
|