Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Infinity with recentPostCount and postCount options #105

Merged
merged 1 commit into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/green-llamas-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'starlight-blog': patch
---

Adds support for passing [`Infinity`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Infinity) to the [`postCount`](https://starlight-blog-docs.vercel.app/configuration#postcount) and [`recentPostCount`](https://starlight-blog-docs.vercel.app/configuration#recentpostcount) configuration options.
8 changes: 6 additions & 2 deletions packages/starlight-blog/libs/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ const configSchema = z
/**
* The number of blog posts to display per page in the blog post list.
*/
postCount: z.number().min(1).default(5),
postCount: z.number().min(1).default(5).transform(infinityToMax),
/**
* The number of recent blog posts to display in the sidebar.
*/
recentPostCount: z.number().min(1).default(10),
recentPostCount: z.number().min(1).default(10).transform(infinityToMax),
/**
* The title of the blog.
*
Expand Down Expand Up @@ -71,5 +71,9 @@ ${Object.entries(errors.fieldErrors)
return config.data
}

function infinityToMax(value: number): number {
return value === Infinity ? Number.MAX_SAFE_INTEGER : value
}

export type StarlightBlogUserConfig = z.input<typeof configSchema>
export type StarlightBlogConfig = z.output<typeof configSchema>
Loading