Added taxonomy/tags + reader

This commit is contained in:
2025-11-11 13:32:41 +01:00
parent ae1cabeb97
commit abb694bf5b
3 changed files with 29 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
import { config } from '@keystatic/core'; import { config } from '@keystatic/core';
import AuthorsCollection from '@/keystatic/collections/taxonomy/authors'; import AuthorsCollection from '@/keystatic/collections/taxonomy/authors';
import TagsCollection from '@/keystatic/collections/taxonomy/tags';
export default config({ export default config({
storage: { storage: {
@@ -8,5 +9,6 @@ export default config({
}, },
collections: { collections: {
authors: AuthorsCollection, authors: AuthorsCollection,
tags: TagsCollection,
}, },
}); });

View File

@@ -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,
}),
},
});

View File

@@ -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;
});