This is most solution I found:
/// nuxt.config.js
export default {
......
generate: {
routes: fs.readdirSync('markdownDir').map(filename => {
return {
route: `/articles/${path.basename(filename, '.md')}`,
content: fs.readFileSync(path.resolve('markdownDir', filename))
}
})
},
}
/// _articleDetail.vue
<template>
<div>
<div class='markdown' v-html='html'></div>
</div>
</template>
<script>
export default {
......
async asyncData({params, content}) {
return {id: params.id, html: processMarkdown(content)}
},
}
</script>
It will generate all Html with article id,but those Html file dosen't contains the real markdown content.It's just like:
......
<div class='markdown'>
(I need markdown content here,Not by js!)
</div>
<script src="/_nuxt/844cb81.js" defer></script>
/_nuxt/844cb81.js
has the real markdown content! I think it's will be bad in SEO.
So I want a solution that can directly generate html that contains origin markdown content.
target
set tostatic
(default isserver
) andssr
set totrue
(default value) ? One solution to debug this is to disable JS and check the source code of the page, you will be sure if it's properly generated ! :D – kissutarget
isstatic
,and tryssr
bothtrue
,false
,don't work! – injoker1npm run generate
– injoker1