From 4529f395fd478694175ca542817b3502941c2eb6 Mon Sep 17 00:00:00 2001 From: BurnyLlama Date: Sun, 8 Aug 2021 19:00:30 +0200 Subject: [PATCH] Fixed crash on no 'externalContext' in md files. --- libs/externalContext.js | 8 ++++++-- libs/siteRenderer.js | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/libs/externalContext.js b/libs/externalContext.js index dc82a1a..0268290 100644 --- a/libs/externalContext.js +++ b/libs/externalContext.js @@ -1,6 +1,10 @@ export function parseExternalContext(externalContext) { - // Remove start and end tag - externalContext = externalContext.replace(/%%-\n|-%%\n/g, "") + // If there's no external context, return nothing. + if (!externalContext) + return {} + + // Remove start and end tag ↓ Only care about the first "externalConext" + externalContext = externalContext[0].replace(/%%-\n|-%%\n/g, "") let parsedContext = {} externalContext.split("\n").forEach(line => { diff --git a/libs/siteRenderer.js b/libs/siteRenderer.js index e86e008..984fc01 100644 --- a/libs/siteRenderer.js +++ b/libs/siteRenderer.js @@ -24,7 +24,7 @@ export function mdRenderer(path) { // Separate the actual markdown from potential 'externalContext' const externalMarkdown = externalMarkdownFile.replace(/^%%-\n[\S\s]*-%%\n/, "").replace(/```\w*[\s\S]*?```/g, match => match.replace(/ /g, "•")) - const externalContext = externalMarkdownFile.match(/^%%-\n[\S\s]*-%%\n/)[0] + const externalContext = externalMarkdownFile.match(/^%%-\n[\S\s]*-%%\n/) // Pre-render the template for analysis during context generation. const prerenderedNjk = njk.renderString(njkFile, { externalMarkdown })