diff --git a/keystatic.config.ts b/keystatic.config.ts index aa6a5db..0fe37d9 100644 --- a/keystatic.config.ts +++ b/keystatic.config.ts @@ -1,8 +1,12 @@ import { config } from '@keystatic/core'; +import AuthorsCollection from '@/keystatic/collections/taxonomy/authors'; + export default config({ storage: { kind: 'local', }, - collections: {}, + collections: { + authors: AuthorsCollection, + }, }); diff --git a/src/keystatic/collections/taxonomy/index.ts b/src/keystatic/collections/taxonomy/index.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/lib/readers/base.ts b/src/lib/readers/base.ts new file mode 100644 index 0000000..efcfba7 --- /dev/null +++ b/src/lib/readers/base.ts @@ -0,0 +1,6 @@ +import { createReader } from '@keystatic/core/reader'; +import { cache } from 'react'; +import keystaticConfig from '~/keystatic.config'; + +export const reader = createReader(process.cwd(), keystaticConfig); +export { cache }; diff --git a/src/lib/readers/taxonomy/authors.ts b/src/lib/readers/taxonomy/authors.ts new file mode 100644 index 0000000..2f26a3e --- /dev/null +++ b/src/lib/readers/taxonomy/authors.ts @@ -0,0 +1,8 @@ +import { cache, reader } from '@/lib/readers/base'; + +export const getAuthors = cache(async () => reader.collections.authors.all()); + +export const getAuthorBySlug = cache(async (slug: string) => { + const author = await reader.collections.authors.read(slug); + return author ? { ...author, slug } : null; +});