Added Taxonomy Collections & Readers
This commit is contained in:
7
src/lib/readers/base.ts
Normal file
7
src/lib/readers/base.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { createReader } from '@keystatic/core/reader';
|
||||
import { cache } from 'react';
|
||||
import keystaticConfig from '~/keystatic.config';
|
||||
|
||||
export const reader = createReader(process.cwd(), keystaticConfig);
|
||||
|
||||
export { cache };
|
||||
8
src/lib/readers/taxonomy/authors.ts
Normal file
8
src/lib/readers/taxonomy/authors.ts
Normal 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;
|
||||
});
|
||||
8
src/lib/readers/taxonomy/tags.ts
Normal file
8
src/lib/readers/taxonomy/tags.ts
Normal 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;
|
||||
});
|
||||
Reference in New Issue
Block a user