|
|
@ -19,7 +19,12 @@ export function createMarkdownToVueRenderFn(
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
const md = createMarkdownRenderer(options)
|
|
|
|
const md = createMarkdownRenderer(options)
|
|
|
|
|
|
|
|
|
|
|
|
return (src: string, file: string, lastUpdated: number) => {
|
|
|
|
return (
|
|
|
|
|
|
|
|
src: string,
|
|
|
|
|
|
|
|
file: string,
|
|
|
|
|
|
|
|
lastUpdated: number,
|
|
|
|
|
|
|
|
injectData = true
|
|
|
|
|
|
|
|
) => {
|
|
|
|
file = path.relative(root, file)
|
|
|
|
file = path.relative(root, file)
|
|
|
|
const cached = cache.get(src)
|
|
|
|
const cached = cache.get(src)
|
|
|
|
if (cached) {
|
|
|
|
if (cached) {
|
|
|
@ -41,10 +46,9 @@ export function createMarkdownToVueRenderFn(
|
|
|
|
lastUpdated
|
|
|
|
lastUpdated
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const additionalBlocks = injectPageData(
|
|
|
|
const additionalBlocks = injectData
|
|
|
|
data.hoistedTags || [],
|
|
|
|
? injectPageData(data.hoistedTags || [], pageData)
|
|
|
|
pageData
|
|
|
|
: data.hoistedTags || []
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// double wrapping since tempalte root node is never hoisted or turned into
|
|
|
|
// double wrapping since tempalte root node is never hoisted or turned into
|
|
|
|
// a static node.
|
|
|
|
// a static node.
|
|
|
@ -61,11 +65,10 @@ export function createMarkdownToVueRenderFn(
|
|
|
|
|
|
|
|
|
|
|
|
const scriptRE = /<\/script>/
|
|
|
|
const scriptRE = /<\/script>/
|
|
|
|
|
|
|
|
|
|
|
|
function injectPageData(
|
|
|
|
function injectPageData(tags: string[], data: PageData) {
|
|
|
|
tags: string[],
|
|
|
|
const code = `\nexport const __pageData = ${JSON.stringify(
|
|
|
|
data: PageData
|
|
|
|
JSON.stringify(data)
|
|
|
|
) {
|
|
|
|
)}`
|
|
|
|
const code = `\nexport const __pageData = ${JSON.stringify(data)}`
|
|
|
|
|
|
|
|
const existingScriptIndex = tags.findIndex((tag) => scriptRE.test(tag))
|
|
|
|
const existingScriptIndex = tags.findIndex((tag) => scriptRE.test(tag))
|
|
|
|
if (existingScriptIndex > -1) {
|
|
|
|
if (existingScriptIndex > -1) {
|
|
|
|
tags[existingScriptIndex] = tags[existingScriptIndex].replace(
|
|
|
|
tags[existingScriptIndex] = tags[existingScriptIndex].replace(
|
|
|
|