nuxt-community / feed-module

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

If using Apollo instead of Axios? #5

Open adamkhan opened 6 years ago

adamkhan commented 6 years ago

For those of us unable to figure it out, could you explain how we'd gain access to our data for feeds if using Apollo instead of Axios?

manniL commented 6 years ago

I'm sorry but I don’t have experience with Apollo/GraphQL. 😕

But essentially it should work similar to the axios setup (import the package of the „connection agent“, make the request, use the data“). However you have to use plain NPM packages

adamkhan commented 6 years ago

Thanks for the quick response. I'm just not sure how to go about doing this within nuxt.config.js rather than in a .vue component file. Well, if I figure it out I'll post here.

manniL commented 6 years ago

You are welcome!

Yeah, that's a bit tricky. But there is likely a node apollo client you could use for that, right? :thinking:

adamkhan commented 6 years ago

I'll look into that.

What might be simpler for me as well, coming from a monolithic CMS background, is the completely different approach of creating a new layout for feeds. Though I'm not sure yet how much of the <head> tag and whether the doctype can be overridden in Nuxt...

manniL commented 6 years ago

Well, you have to provide the feeds somehow :man_shrugging:

With this module, nuxt will take over this job. Attaching feeds into your metadata is not covered but should be easy as you can control the URLs :+1:

adamkhan commented 6 years ago

Right now this alternative approach to your feed module looks to me not possible in Nuxt, because the doctype is set in the the View, and only one View can be set it seems, ie, the one that shows the web pages, else no web site! See https://nuxtjs.org/guide/views/.

So in order to output a feed without your module, a whole new instance of Nuxt would seem to be required!

mimbo119 commented 3 years ago

Here's an example:

async create (feed) {
        feed.options = {
          title: 'Something',
          description: 'A RSS news feed containing the latest news of Something.',
          link: 'https://www.Something.com/rss.xml',
          feedLinks: {
            atom: 'https://www.Something.com/rss.xml'
          },
          language: 'bn-bd',
          copyright: 'Copyright 2021, Something  Limited',
          creator: 'John Doe',
          author: {
            name: 'Something (digital@Something.com)'
          },
          dc: {
            language: 'bn-bd',
          }
        }
        const feedData = []
        const fetch = require('cross-fetch')
        await fetch(process.env.GQL_API + '/graphql', {
          method: 'POST',
          headers: { 'Content-Type': 'application/json' },
          body: JSON.stringify({
            query: ` query {
              news {
                news{
                  slug
                  updatedAt
                  title
                  description
                  subtitle
                  author {
                    nameBn
                  }
                  category{
                    name
                  }
                  coverImage
                }
              }
            }`,
            variables: {}
          })
        }).then(res => res.json())
          .then((data) => {
            data.data..forEach((blog) => {
              feedData.push(blog)
            })
          })
        feedData.forEach((blog) => {
          feed.addItem({
            title: blog.title,
            link: process.env.BASEURL + `/news/${new Intl.DateTimeFormat('fr-ca').format(blog.updatedAt).replace('/', '-').replace('/', '-')}/${blog.slug}`,
            description: blog.subtitle + blog.description.replace(/(<([^>]+)>)/ig, '').trim(),
            // description: blog.description,
            published: new Date(parseInt(blog.updatedAt)),
            id: blog.slug,
            source: 'Something Limited',
            creator: blog.author.nameBn,
            content: blog.description,
            image: blog.coverImage,
            media: {
              content: blog.coverImage
            },
            author: [
              {
                name: blog.author.nameBn
              }
            ],
            category: blog.category.name
          })
        })
      },

But the problem is the feed doesnt show in a xml format version, and dc elements dont show.

adamkhan commented 3 years ago

https://jsonfeed.org/ is a standard that more readers are handling.