Fix frontmatter indexing error when a tag is a number (#830)

* Fix indexing error by always treating frontmatter tags as strings

* Only try escaping html in actual strings
pull/832/head
Justyn Shull 2024-03-26 15:04:34 -05:00 committed by GitHub
parent e7eba107c6
commit 331d526f52
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 2 deletions

View File

@ -115,8 +115,18 @@ export async function extractFrontmatter(
return undefined;
});
// Strip # from tags
data.tags = [...new Set([...tags.map((t) => t.replace(/^#/, ""))])];
try {
data.tags = [
...new Set([...tags.map((t) => {
// Always treat tags as strings
const tagAsString = String(t);
// Strip # from tags
return tagAsString.replace(/^#/, "");
})]),
];
} catch (e) {
console.error("Error while processing tags", e);
}
// console.log("Extracted tags", data.tags);
// Expand property names (e.g. "foo.bar" => { foo: { bar: true } })

View File

@ -7,6 +7,10 @@ export type Tag = {
} | string;
function htmlEscape(s: string): string {
if (typeof s !== "string") {
return s;
}
s = s.replace(/&/g, "&")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")