diff --git a/.changeset/grumpy-bears-sleep.md b/.changeset/grumpy-bears-sleep.md new file mode 100644 index 0000000..e922ad2 --- /dev/null +++ b/.changeset/grumpy-bears-sleep.md @@ -0,0 +1,5 @@ +--- +'pliny': patch +--- + +fix bleed full mode diff --git a/.changeset/hot-olives-tease.md b/.changeset/hot-olives-tease.md new file mode 100644 index 0000000..8642967 --- /dev/null +++ b/.changeset/hot-olives-tease.md @@ -0,0 +1,5 @@ +--- +'pliny': patch +--- + +Improve typing of contentlayer utility functions and filter posts only in prod diff --git a/.changeset/pre.json b/.changeset/pre.json index a1c738b..ca341f1 100644 --- a/.changeset/pre.json +++ b/.changeset/pre.json @@ -12,6 +12,8 @@ "good-cheetahs-tap", "good-knives-tan", "great-chairs-warn", + "grumpy-bears-sleep", + "hot-olives-tease", "metal-coats-grab", "mighty-garlics-appear", "modern-planes-end", diff --git a/packages/pliny/CHANGELOG.md b/packages/pliny/CHANGELOG.md index e883006..324fa7b 100644 --- a/packages/pliny/CHANGELOG.md +++ b/packages/pliny/CHANGELOG.md @@ -1,5 +1,12 @@ # pliny +## 0.1.0-beta.12 + +### Patch Changes + +- 75533d5: fix bleed full mode +- c41211e: Improve typing of contentlayer utility functions and filter posts only in prod + ## 0.1.0-beta.11 ### Patch Changes diff --git a/packages/pliny/package.json b/packages/pliny/package.json index d30ad65..882bb64 100644 --- a/packages/pliny/package.json +++ b/packages/pliny/package.json @@ -2,7 +2,7 @@ "name": "pliny", "description": "Main entry point for pliny components", "homepage": "https://github.com/timlrx/pliny", - "version": "0.1.0-beta.11", + "version": "0.1.0-beta.12", "type": "module", "exports": { "./*": "./*", diff --git a/packages/pliny/src/ui/Bleed.tsx b/packages/pliny/src/ui/Bleed.tsx index 0a99bcc..6371853 100644 --- a/packages/pliny/src/ui/Bleed.tsx +++ b/packages/pliny/src/ui/Bleed.tsx @@ -9,7 +9,7 @@ const Bleed = ({ full, children }: BleedProps) => { return (
{children} diff --git a/packages/pliny/src/utils/contentlayer.ts b/packages/pliny/src/utils/contentlayer.ts index ea57c6d..57b2bd6 100644 --- a/packages/pliny/src/utils/contentlayer.ts +++ b/packages/pliny/src/utils/contentlayer.ts @@ -1,5 +1,7 @@ import type { Document, MDX } from 'contentlayer/core' +const isProduction = process.env.NODE_ENV === 'production' + export type MDXDocument = Document & { body: MDX } export type MDXDocumentDate = MDXDocument & { date: string @@ -19,8 +21,26 @@ export function dateSortDesc(a: string, b: string) { return 0 } +/** + * Sorts a list of MDX documents by date in descending order + * + * @param {MDXDocumentDate[]} allBlogs + * @param {string} [dateKey='date'] + * @return {*} + */ +export function sortPosts(allBlogs: MDXDocumentDate[], dateKey: string = 'date') { + return allBlogs.sort((a, b) => dateSortDesc(a[dateKey], b[dateKey])) +} + +/** + * Kept for backwards compatibility + * Please use `sortPosts` instead + * @deprecated + * @param {MDXBlog[]} allBlogs + * @return {*} + */ export function sortedBlogPost(allBlogs: MDXDocumentDate[]) { - return allBlogs.sort((a, b) => dateSortDesc(a.date, b.date)) + return sortPosts(allBlogs) } type ConvertUndefined = OrNull<{ @@ -68,10 +88,26 @@ export const omit = (obj: Obj, keys: Keys[]): Omit< export type CoreContent = Omit -export function coreContent(content: T) { +/** + * Omit body, _raw, _id from MDX document and return only the core content + * + * @param {T} content + * @return {*} {CoreContent} + */ +export function coreContent(content: T): CoreContent { return omit(content, ['body', '_raw', '_id']) } -export function allCoreContent(contents: T[]) { - return contents.map((c) => coreContent(c)).filter((c) => !('draft' in c && c.draft === true)) +/** + * Omit body, _raw, _id from a list of MDX documents and returns only the core content + * If `NODE_ENV` === "production", it will also filter out any documents with draft: true. + * + * @param {T[]} contents + * @return {*} {CoreContent[]} + */ +export function allCoreContent(contents: T[]): CoreContent[] { + const coreContent = contents.map((c) => coreContent(c)) + if (isProduction) + return coreContent.filter((c: CoreContent) => !('draft' in c && c.draft === true)) + return coreContent }