Skip to content

Commit

Permalink
Support Infinity with recentPostCount and postCount options (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
HiDeoo authored Dec 22, 2024
1 parent d9ded04 commit 4ce050c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
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>

0 comments on commit 4ce050c

Please sign in to comment.