qwik-cms/libs/externalContext.js

20 lines
669 B
JavaScript
Raw Normal View History

export function parseExternalContext(externalContext) {
// 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, "")
2021-08-07 10:46:48 +02:00
let parsedContext = {}
externalContext.split("\n").forEach(line => {
// If the line is falsey; leave.
if (!line) return
2021-08-07 10:46:48 +02:00
// Assign properties to parsedContext and give them their corresponding values.
line = line.split(/:/)
parsedContext[line[0]] = line[1].replace(/^\s/, "")
})
return parsedContext
}