nuxt-community / feed-module

Everyone deserves RSS, ATOM and JSON feeds!
MIT License
227 stars 36 forks source link

Documentation on integrating nuxt/feed with nuxt/content? #86

Closed jackdomleo7 closed 4 years ago

jackdomleo7 commented 4 years ago

I currently have a blog on my website that is generated with nuxt/content. I've been trying o add nuxt/feed with this configuration:

feed: [
  {
    path: '/feed.xml', // The route to your feed.
    async create (feed) {
      feed.options = {
        title: 'Jack Domleo - blog',
        link: 'https://jackdomleo.dev/feed.xml',
        description: 'Feed for Jack Domleo\'s blog.'
      }

      const posts = await this.$content('blog', { deep: true }).only(['title', 'body', 'date', 'slug', 'description', 'readingTime', 'hashtags']).sortBy('date', 'desc').fetch();
      posts.forEach(post => {
        feed.addItem({
          title: post.title,
          id: post.slug,
          link: post.slug,
          description: post.description,
          content: post.body
        })
      })

      feed.addCategory('Nuxt.js')

      feed.addContributor({
        name: 'Jack Domleo',
        link: 'https://jackdomleo.dev'
      })
    },
    cacheTime: 1000 * 60 * 15, // How long should the feed be cached
    type: 'rss2', // Can be: rss2, atom1, json1
    data: [''] // Will be passed as 2nd argument to `create` function
  }
]

When serving the website locally, it fails with ERROR this.$content is not a function. However, the nuxt/content documentation states that this method is the way to fetch the content.

Can you offer any guidance? Thank you in advance!!

manniL commented 4 years ago

Take a look at the programmatic usage part in the nuxt content docs 😋

That could help!

jackdomleo7 commented 4 years ago

Of course, thank you!!

I stumbled into another issue where the error was cdata.replace is not a function. I finally resolved this by removing content: post.body - no idea why it worked but it did 😅

leon0399 commented 4 years ago

@jackdomleo7 what you did, you just removed content from your feed

you could fetch your content by passing text: true option ($content(..., { text: true })), and then converting it into HTML using something like https://github.com/nuxt/markdown

const content = (await md.toMarkup(article.text)).html
jillesca commented 3 years ago

Had the same error, cdata.replace is not a function in my case the title of my post had an individual number (as I was testing) which somehow was breaking the feed. I just added additional strings so the title was considered a string which fixed the issue in my case.