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 })