From 1016dc94ca463a55240bc41eeff9e3053712af45 Mon Sep 17 00:00:00 2001 From: Chris Swithinbank Date: Thu, 4 May 2023 22:14:41 +0200 Subject: Refactor collection helper to only return the schema (#28) --- docs/src/content/config.ts | 7 +++++-- packages/starbook/schema.ts | 41 ++++++++++++++++++----------------------- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/docs/src/content/config.ts b/docs/src/content/config.ts index aecf6840..22718619 100644 --- a/docs/src/content/config.ts +++ b/docs/src/content/config.ts @@ -1,5 +1,8 @@ -import { defineDocsCollection } from 'starbook/schema'; +import { defineCollection } from 'astro:content'; +import { docsSchema } from 'starbook/schema'; export const collections = { - docs: defineDocsCollection(), + docs: defineCollection({ + schema: docsSchema(), + }), }; diff --git a/packages/starbook/schema.ts b/packages/starbook/schema.ts index b66f92d8..3178ba16 100644 --- a/packages/starbook/schema.ts +++ b/packages/starbook/schema.ts @@ -1,28 +1,23 @@ -import { defineCollection, z } from 'astro:content'; +import { z } from 'astro:content'; -export function defineDocsCollection() { - return defineCollection({ - schema: z.object({ - /** The title of the current page. Required. */ - title: z.string(), +export function docsSchema() { + return z.object({ + /** The title of the current page. Required. */ + title: z.string(), - /** - * A short description of the current page’s content. Optional, but recommended. - * A good description is 150–160 characters long and outlines the key content - * of the page in a clear and engaging way. - */ - description: z.string().optional(), + /** + * A short description of the current page’s content. Optional, but recommended. + * A good description is 150–160 characters long and outlines the key content + * of the page in a clear and engaging way. + */ + description: z.string().optional(), - /** - * Custom URL where a reader can edit this page. - * Overrides the `editLink.baseUrl` global config if set. - * - * Can also be set to `false` to disable showing an edit link on this page. - */ - editUrl: z - .union([z.string().url(), z.boolean()]) - .optional() - .default(true), - }), + /** + * Custom URL where a reader can edit this page. + * Overrides the `editLink.baseUrl` global config if set. + * + * Can also be set to `false` to disable showing an edit link on this page. + */ + editUrl: z.union([z.string().url(), z.boolean()]).optional().default(true), }); } -- cgit