Added Taxonomy Collections & Readers
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
import { config } from '@keystatic/core';
|
||||
|
||||
import taxonomyCollections from '@/keystatic/collections/taxonomy';
|
||||
|
||||
export default config({
|
||||
storage: {
|
||||
kind: 'local',
|
||||
},
|
||||
collections: {},
|
||||
collections: {
|
||||
...taxonomyCollections,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { makeRouteHandler } from '@keystatic/next/route-handler';
|
||||
import { config } from '~/keystatic.config';
|
||||
import config from '~/keystatic.config';
|
||||
|
||||
export const { POST, GET } = makeRouteHandler({
|
||||
config,
|
||||
23
src/keystatic/collections/taxonomy/authors.ts
Normal file
23
src/keystatic/collections/taxonomy/authors.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { collection, fields } from '@keystatic/core';
|
||||
|
||||
export default collection({
|
||||
label: 'Authors',
|
||||
slugField: 'name',
|
||||
path: 'content/taxonomy/authors/*',
|
||||
schema: {
|
||||
name: fields.slug({
|
||||
name: {
|
||||
label: 'Name',
|
||||
},
|
||||
}),
|
||||
avatar: fields.image({
|
||||
label: 'Avatar',
|
||||
directory: 'public/images/authors',
|
||||
publicPath: '/images/authors',
|
||||
}),
|
||||
description: fields.text({
|
||||
label: 'Description',
|
||||
multiline: true,
|
||||
}),
|
||||
},
|
||||
});
|
||||
9
src/keystatic/collections/taxonomy/index.ts
Normal file
9
src/keystatic/collections/taxonomy/index.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import tags from '@/keystatic/collections/taxonomy/tags';
|
||||
import authors from '@/keystatic/collections/taxonomy/authors';
|
||||
|
||||
const taxonomyCollection = {
|
||||
tags: tags,
|
||||
authors: authors,
|
||||
};
|
||||
|
||||
export default taxonomyCollection;
|
||||
21
src/keystatic/collections/taxonomy/tags.ts
Normal file
21
src/keystatic/collections/taxonomy/tags.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
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: 'Description',
|
||||
multiline: true,
|
||||
}),
|
||||
},
|
||||
});
|
||||
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