From 28789e2d01945c4ad5813d339aae6848b6100acc Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Mon, 12 Dec 2022 00:49:11 +0100 Subject: [PATCH] Parse booleans from the frontmatter (fixes #79) --- src/collecting.ts | 7 +++++++ src/helper.ts | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/collecting.ts b/src/collecting.ts index 0f91aad..1f0325a 100644 --- a/src/collecting.ts +++ b/src/collecting.ts @@ -510,6 +510,13 @@ export function collectDataFromFrontmatterKey( renderInfo.textValueMap ); // console.log(retParse); + if (retParse.value === null) { + // Try parsing as a boolean: true means 1, false means 0. + if (deepValue === 'true' || deepValue === 'false') { + retParse.type = ValueType.Number; + retParse.value = deepValue === 'true' ? 1 : 0; + } + } if (retParse.value !== null) { if (retParse.type === ValueType.Time) { query.valueType = ValueType.Time; diff --git a/src/helper.ts b/src/helper.ts index 22aef7d..3c7fd36 100644 --- a/src/helper.ts +++ b/src/helper.ts @@ -316,7 +316,7 @@ export function deepValue(obj: any, str: string) { } if (typeof obj === "string" || Array.isArray(obj)) { return obj; - } else if (typeof obj === "number") { + } else if (typeof obj === "number" || typeof obj === "boolean") { return obj.toString(); } return null;