43
loading...
This website collects cookies to deliver better user experience
nuxt-content
component. This component gets the Markdown document that should be rendered, and then applies big magic to make a beautiful blog page out of it 😊.<template>
<nuxt-content :document="post" />
</template>
bodyHtml
field to all markdown documents. It reproduces the Nuxt Content Markdown pipeline to generate it and also uses the Remark and Rehype plugins from the module config, so it outputs the same HTML as the component. The good thing is, we can just drop it in and abstracts away the logic of generating the HTML code, so that we can concentrate on the feed creation.npm install nuxt-content-body-html
. Then we add it to our nuxt.config.js
:export default {
modules: [
'nuxt-content-body-html',
'@nuxt/content',
},
}
post.bodyHtml
on a blog page and it should contain the HTML code.export default {
modules: [
'nuxt-content-body-html',
'@nuxt/content',
'@nuxtjs/feed',
],
feed: [
{
create: async feed => {
const $content = require('@nuxt/content').$content
feed.options = {
title: 'My Blog',
link: 'https://me.com/blog',
description: "It's all about programming!",
}
const posts = await $content('posts')
.sortBy('createdAt', 'desc')
.fetch()
posts.forEach(post => {
const url = `https://me.com/blog/${post.slug}`
feed.addItem({
author: post.authors,
content: post.bodyHtml,
date: new Date(post.createdAt),
description: post.description,
id: url,
link: url,
title: post.title,
})
})
},
path: '/feed',
type: 'rss2',
},
],
}
// images at static/blog/<slug>/banner.png
posts.forEach(post => {
const url = `https://me.com/blog/${post.slug}`
feed.addItem({
// ...
content: `
<p>
<img
alt="Cover image"
src="https://me.com/blog/${post.slug}/teaser.png"
>
</p>
${post.bodyHtml}
`,
})
})
bodyHtml
field to documents that can be used in the feed creation function. I hope it's of some use for you! If you like it, feel free to leave a star at star at GitHub 🌟. Thanks for reading!