Added Author reader

This commit is contained in:
2025-11-11 13:18:37 +01:00
parent b30b77e6fd
commit ae1cabeb97
4 changed files with 19 additions and 1 deletions

6
src/lib/readers/base.ts Normal file
View File

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

View File

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