Merge pull request #1543 from saberzero1/draft-publish-string

feat(filters): support "true" as valid for frontmatter filters
This commit is contained in:
Emile Bangma 2024-10-22 22:38:16 +02:00 committed by GitHub
commit d98a3a088a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 5 additions and 4 deletions

View file

@ -3,7 +3,8 @@ import { QuartzFilterPlugin } from "../types"
export const RemoveDrafts: QuartzFilterPlugin<{}> = () => ({ export const RemoveDrafts: QuartzFilterPlugin<{}> = () => ({
name: "RemoveDrafts", name: "RemoveDrafts",
shouldPublish(_ctx, [_tree, vfile]) { shouldPublish(_ctx, [_tree, vfile]) {
const draftFlag: boolean = vfile.data?.frontmatter?.draft === true const draftFlag: boolean =
vfile.data?.frontmatter?.draft === true || vfile.data?.frontmatter?.draft === "true"
return !draftFlag return !draftFlag
}, },
}) })

View file

@ -3,6 +3,6 @@ import { QuartzFilterPlugin } from "../types"
export const ExplicitPublish: QuartzFilterPlugin = () => ({ export const ExplicitPublish: QuartzFilterPlugin = () => ({
name: "ExplicitPublish", name: "ExplicitPublish",
shouldPublish(_ctx, [_tree, vfile]) { shouldPublish(_ctx, [_tree, vfile]) {
return vfile.data?.frontmatter?.publish === true return vfile.data?.frontmatter?.publish === true || vfile.data?.frontmatter?.publish === "true"
}, },
}) })

View file

@ -88,8 +88,8 @@ declare module "vfile" {
tags: string[] tags: string[]
aliases: string[] aliases: string[]
description: string description: string
publish: boolean publish: boolean | string
draft: boolean draft: boolean | string
lang: string lang: string
enableToc: string enableToc: string
cssclasses: string[] cssclasses: string[]