nuxt-community / feed-module

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

Prismic instead of axios? #94

Open asencis opened 3 years ago

asencis commented 3 years ago

Does anyone have a solution for using $primsic (the official nuxt plugin version) with the async create (feed) {} call?

olvap commented 3 years ago

Did you found a solution for this?

haghdk commented 2 years ago

I made it work with this in my nuxt.config.js

import Prismic from '@prismicio/client'

feed: [
    // A default feed configuration object
    {
      path: '/feed.xml',
      async create(feed) {
        feed.options = {
          title: 'My Title',
          link: 'https://www.domain.com/feed.xml',
          description: 'My description',
        }

        const api = await Prismic.getApi('https://domain.cdn.prismic.io/api/v2')
        const blogposts = await api.query(Prismic.Predicates.at('document.type', 'blogpost'))

        blogposts.results.forEach((post) => {
          feed.addItem({
            title: post.data.meta_title,
            id: `https://www.domain.com/${post.uid}/`,
            link: `https://www.domain.com/${post.uid}/`,
            description: post.data.meta_description,
            date: new Date(post.data.post_date),
          })
        })
      },
      cacheTime: 1000 * 60 * 15,
      type: 'rss2',
    },
  ],