diff --git a/keystatic.config.ts b/keystatic.config.ts index 0fe37d9..6a41a53 100644 --- a/keystatic.config.ts +++ b/keystatic.config.ts @@ -1,6 +1,7 @@ import { config } from '@keystatic/core'; import AuthorsCollection from '@/keystatic/collections/taxonomy/authors'; +import TagsCollection from '@/keystatic/collections/taxonomy/tags'; export default config({ storage: { @@ -8,5 +9,6 @@ export default config({ }, collections: { authors: AuthorsCollection, + tags: TagsCollection, }, }); diff --git a/src/keystatic/collections/taxonomy/tags.ts b/src/keystatic/collections/taxonomy/tags.ts new file mode 100644 index 0000000..8878441 --- /dev/null +++ b/src/keystatic/collections/taxonomy/tags.ts @@ -0,0 +1,19 @@ +import { collection, fields } from '@keystatic/core'; + +export default collection({ + label: 'Tags', + slugField: 'name', + path: 'content/taxonomy/tags/*', + format: { data: 'json' }, + schema: { + name: fields.slug({ + name: { + label: 'Name', + }, + }), + description: fields.text({ + label: 'Descriptions', + multiline: true, + }), + }, +}); diff --git a/src/lib/readers/taxonomy/tags.ts b/src/lib/readers/taxonomy/tags.ts new file mode 100644 index 0000000..0455683 --- /dev/null +++ b/src/lib/readers/taxonomy/tags.ts @@ -0,0 +1,8 @@ +import { cache, reader } from '@/lib/readers/base'; + +export const getTags = cache(async () => reader.collections.tags.all()); + +export const getTagBySlug = cache(async (slug: string) => { + const tag = await reader.collections.tags.read(slug); + return tag ? { ...tag, slug } : null; +});