Skip to content

Commit

Permalink
Refactor collection helper to only return the schema (withastro#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
delucis authored May 4, 2023
1 parent 7b9f273 commit 1016dc9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
7 changes: 5 additions & 2 deletions docs/src/content/config.ts
Original file line number Diff line number Diff line change
@@ -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(),
}),
};
41 changes: 18 additions & 23 deletions packages/starbook/schema.ts
Original file line number Diff line number Diff line change
@@ -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),
});
}

0 comments on commit 1016dc9

Please sign in to comment.