From e70d0acfa416ec1acbd0aa89f879f9937853cb95 Mon Sep 17 00:00:00 2001 From: HiDeoo <494699+HiDeoo@users.noreply.github.com> Date: Tue, 4 Jun 2024 10:43:39 +0200 Subject: [PATCH] fix: fixes an issue preventing to read Obsidian frontmatter when it included a `null` value --- fixtures/basics/Supported properties.md | 1 + packages/starlight-obsidian/libs/obsidian.ts | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/fixtures/basics/Supported properties.md b/fixtures/basics/Supported properties.md index aed7e8c..313c9c5 100644 --- a/fixtures/basics/Supported properties.md +++ b/fixtures/basics/Supported properties.md @@ -1,6 +1,7 @@ --- description: This is a custom description permalink: custom-slug +aliases: --- Test diff --git a/packages/starlight-obsidian/libs/obsidian.ts b/packages/starlight-obsidian/libs/obsidian.ts index 1d19b00..54307fa 100644 --- a/packages/starlight-obsidian/libs/obsidian.ts +++ b/packages/starlight-obsidian/libs/obsidian.ts @@ -23,16 +23,18 @@ const obsidianFrontmatterSchema = z.object({ aliases: z .array(z.string()) .optional() + .nullable() .transform((aliases) => aliases?.map((alias) => slug(alias))), - cover: z.string().optional(), - description: z.string().optional(), - image: z.string().optional(), - permalink: z.string().optional(), + cover: z.string().optional().nullable(), + description: z.string().optional().nullable(), + image: z.string().optional().nullable(), + permalink: z.string().optional().nullable(), publish: z .union([z.boolean(), z.literal('true'), z.literal('false')]) .optional() + .nullable() .transform((publish) => publish === undefined || publish === 'true' || publish === true), - tags: z.array(z.string()).optional(), + tags: z.array(z.string()).optional().nullable(), }) const imageFileFormats = new Set(['.avif', '.bmp', '.gif', '.jpeg', '.jpg', '.png', '.svg', '.webp'])