https://github.com/acdh-oeaw/keystatic-lib

Utilities for Keystatic CMS

https://github.com/acdh-oeaw/keystatic-lib

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (7.1%) to scientific vocabulary

Keywords

frontend
Last synced: 6 months ago · JSON representation

Repository

Utilities for Keystatic CMS

Basic Info
  • Host: GitHub
  • Owner: acdh-oeaw
  • License: mit
  • Language: TypeScript
  • Default Branch: main
  • Homepage:
  • Size: 280 KB
Statistics
  • Stars: 2
  • Watchers: 6
  • Forks: 0
  • Open Issues: 1
  • Releases: 15
Topics
frontend
Created over 1 year ago · Last pushed 6 months ago
Metadata Files
Readme Changelog License Codeowners

readme.md

keystatic lib

utilities for working with multi-language keystatic collections.

how to install

bash npm i @acdh-oeaw/keystatic-lib

how to use

provide the languages supported in your project via typescript module augmentation:

```ts // ./types/keystatic.d.ts

declare module "@acdh-oeaw/keystatic-lib" { export interface KeystaticConfig { locales: "de" | "en"; } } ```

create components (rich text editor widgets)

```ts // ./lib/keystatic/components.ts

import { createComponent } from "@acdh-oeaw/keystatic-lib"; import { wrapper } from "@keystatic/core/content-components";

export const Video = createComponent((paths, locale) => { return wrapper({ label: "Video", schema: { /** ... */ }, }); }); ```

create collections and singletons

```ts // ./lib/keystatic/resources.ts

import { createAssetOptions, createCollection, createContentFieldOptions, createSingleton, createLabel, } from "@acdh-oeaw/keystatic-lib"; import { collection, singleton } from "@keystatic/core";

import { Video } from "./lib/keystatic/components";

export const pages = createCollection("/pages/", (paths, locale) => { return collection({ label: createLabel("Pages", locale), path: paths.contentPath, slugField: "title", format: { contentField: "content" }, entryLayout: "content", columns: ["title"], schema: { title: fields.slug({ name: { label: "Title", validation: { isRequired: true }, }, }), image: fields.image({ label: "Image", validation: { isRequired: false }, ...createAssetOptions(paths.assetPath), }), content: fields.mdx({ label: "Content", options: createContentFieldOptions(paths), components: { Video: Video(paths, locale), }, }), }, }); });

export const metadata = createSingleton("/metadata/", (paths, locale) => { return singleton({ label: createLabel("Metadata", locale), path: paths.contentPath, format: { data: "json" }, entryLayout: "form", schema: { /** ... */ }, }); }); ```

```ts // ./keystatic.config.ts

import { withI18nPrefix } from "@acdh-oeaw/keystatic-lib"; import { config } from "@keystatic/core";

import { metadata, pages } from "./lib/keystatic/resources";

export default config({ collections: { [withI18nPrefix("pages", "de")]: pages("de"), [withI18nPrefix("pages", "en")]: pages("en"), }, singletons: { [withI18nPrefix("metadata", "de")]: metadata("de"), [withI18nPrefix("metadata", "en")]: metadata("en"), }, }); ```

read and render entries

create resource readers by passing the keystatic config and a mdx compiler function to createReaders:

```ts // ./lib/keystatic/readers.ts

import { createReaders } from "@acdh-oeaw/keystatic-lib/reader"; import { createFormatAwareProcessors } from "@mdx-js/mdx/internal-create-format-aware-processors";

import config from "../../keystatic.config";

function getMdxContent(code: string, locale: Locale, baseUrl: URL) { const processor = await createFormatAwareProcessors({ /** Set this to html in astro. / // elementAttributeNameCase: "html", format: "mdx", outputFormat: "function-body", providerImportSource: "#", /* ... */ }); const file = await processor.process(code); return run(file, { ...runtime, baseUrl, useMDXComponents }); }

function useMDXComponents() { /** Provide component mappings, which should be available to all mdx content. */ return { // a: LocaleLink, // Video, }; }

const { createCollectionResource, createSingletonResource } = createReaders(config, getMdxContent);

export { createCollectionResource, createSingletonResource }; ```

a reader has methods for reading a single resource entry (read), reading all resource entries (all), and returning a list of entry identifiers (list).

a resource entry returns id, collection/singleton, and data, as well as a compile method, which can be used to transform rich-text field content to a jsx component.

astro

```astro

// ./src/pages/[locale]/[id].astro

import type { GetStaticPathsResult } from "astro";

import { locales } from "@/config/i18n.config"; import Layout from "@/layouts/page-layout.astro"; import { createCollectionResource } from "@/lib/keystatic/readers";

export async function getStaticPaths() { return ( await Promise.all( locales.map(async (locale) => { const ids = await createCollectionResource("pages", locale).list(); return ids.map((id) => { return { params: { id, locale } }; }); }), ) ).flat() satisfies GetStaticPathsResult; }

const { id, locale } = Astro.params;

const page = await createCollectionResource("pages", locale).read(id); const { content, image, title } = page.data;

const { default: Content } = await page.compile(content);

```

next.js

```tsx // ./app/[locale]/[id]/page.tsx

import type { Locale } from "@/config/i18n.config"; import { createCollectionResource } from "@/lib/keystatic/readers";

interface PageProps { params: { id: string; locale: Locale; }; }

export const dynamicParams = false;

export async function generateStaticParams(props: PageProps) { const { locale } = props.params; const ids = await createCollectionResource("pages", locale).list(); return ids.map((id) => { return { id }; }); }

export default async function Page(props: PageProps) { const { id, locale } = props.params;

const page = await createCollectionResource("pages", locale).read(id);
const { title, image, content } = page.data;
const { default: Content } = await page.compile(content);

return (
    <main>
        <Content />
    </main>
);

} ```

Owner

  • Name: Austrian Centre for Digital Humanities & Cultural Heritage
  • Login: acdh-oeaw
  • Kind: organization
  • Email: acdh@oeaw.ac.at
  • Location: Vienna, Austria

GitHub Events

Total
  • Release event: 8
  • Delete event: 10
  • Issue comment event: 1
  • Push event: 24
  • Pull request event: 20
  • Create event: 19
Last Year
  • Release event: 8
  • Delete event: 10
  • Issue comment event: 1
  • Push event: 24
  • Pull request event: 20
  • Create event: 19

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 0
  • Total pull requests: 21
  • Average time to close issues: N/A
  • Average time to close pull requests: about 3 hours
  • Total issue authors: 0
  • Total pull request authors: 2
  • Average comments per issue: 0
  • Average comments per pull request: 0.1
  • Merged pull requests: 19
  • Bot issues: 0
  • Bot pull requests: 15
Past Year
  • Issues: 0
  • Pull requests: 21
  • Average time to close issues: N/A
  • Average time to close pull requests: about 3 hours
  • Issue authors: 0
  • Pull request authors: 2
  • Average comments per issue: 0
  • Average comments per pull request: 0.1
  • Merged pull requests: 19
  • Bot issues: 0
  • Bot pull requests: 15
Top Authors
Issue Authors
Pull Request Authors
  • github-actions[bot] (25)
  • stefanprobst (6)
Top Labels
Issue Labels
Pull Request Labels

Dependencies

.github/workflows/release.yml actions
  • actions/checkout v4 composite
  • actions/setup-node v4 composite
  • changesets/action v1 composite
  • pnpm/action-setup v4 composite
package.json npm
  • @acdh-oeaw/commitlint-config ^1.0.0 development
  • @acdh-oeaw/eslint-config ^2.0.1 development
  • @acdh-oeaw/eslint-config-node ^2.0.1 development
  • @acdh-oeaw/prettier-config ^2.0.0 development
  • @acdh-oeaw/tsconfig-lib ^1.1.0 development
  • @changesets/changelog-github ^0.5.0 development
  • @changesets/cli ^2.27.8 development
  • @commitlint/cli ^18.6.1 development
  • @keystatic/core ^0.5.34 development
  • @types/node ^22.5.4 development
  • eslint ^9.10.0 development
  • eslint-config-flat-gitignore ^0.3.0 development
  • globals ^15.9.0 development
  • is-ci ^3.0.1 development
  • lint-staged ^15.2.10 development
  • npm-run-all2 ^6.2.2 development
  • prettier ^3.3.3 development
  • simple-git-hooks ^2.11.1 development
  • tsup ^8.2.4 development
  • tsx ^4.19.0 development
  • typescript ^5.6.2 development
  • @sindresorhus/slugify ^2.2.1
  • @types/mdx ^2.0.13
pnpm-lock.yaml npm
  • 284 dependencies