helltraitor / nuxt-feedme

The RSS feed module for Nuxt web framework
MIT License
17 stars 2 forks source link

How to use Nuxt Feedme #6

Closed danvega closed 1 year ago

danvega commented 1 year ago

Sorry if this is a dumb question but I have a question on how to use this module. I have 2 content folders /newsletter & /blog. I want to create an rss2 feed for my blog. I tried a few different configurations but this is the latest.

  feedme: {
    feeds: {
      '/rss.xml': { revisit: '6h', type: 'rss2', content: true },

    },
    content: {
      item: {
        templateRoots: ['blog', 'blog']
      }
    }
  },

When I try and run a build I am getting the following error. What am I missing here?

image
helltraitor commented 1 year ago

First, that I'm noticed, was templateRoots field. This field accept the list of unique strings (or true) and use it for generation mappings. So you can leave just blog.

At the second glance, I can't say, that this is nuxt-feedme issue. When you are using blog template root, this module creates mapping like:

blog.date => date
blog.title => title

And so on. When you use content without query parameters, the content handle quires all available items. And fetch all data automatically via mappings. So your items (e.g. article in md) must include blog item with feed fields (same as Feed object in feed package).

---
blog:
    title: How it works
    description: Site structure description
    date: 2023-07-27
---

So, I can advice you, to use templateRoots: [true, 'blog'] instead (if you even use that blog field for RSS).

The second advice is to try query specific path.

  feedme: {
    content: {
      item: {
        query: {
          limit: 100,
          where: [
            // Mine _path setup, try to make all work with one of yours, then add the second one with regex or |
            { _path: /^\/posts\/[^\/]+$/ },
          ],
        },
      },
    },
  },

The third advice is checkout, which routes are taken for generation and what is going on inside. This can be done via log in handle: https://github.com/helltraitor/nuxt-feedme/blob/main/playground/server/plugins/feed.ts

Use different content hooks: feedme:handle:content:before and feedme:handle:content:item to see what's going on.

Also, if your project is public, you can create branch (if not exist and if this is not main branch) with this defect - I will take a look.

As for now, I think that the problem is somewhere around available content paths and template roots, good luck

danvega commented 1 year ago

Thanks for responding! I put this in a branch at https://github.com/danvega/danvega-dev-nuxt/tree/feedme

I made the changes you suggested and now it builds! When this is complete should there be a static rss.xml file in the public/ folder?

danvega commented 1 year ago

nvm, I see the following in the build logs...

ℹ Prerendering 5 routes nitro 3:45:06 PM ├─ /feed.json (9934ms) nitro 3:45:16 PM ├─ /feed.xml (9935ms) nitro 3:45:16 PM ├─ /rss.xml (9937ms) nitro 3:45:16 PM ├─ /feed.atom (9939ms) nitro 3:45:16 PM ├─ /api/_content/cache.1697485499233.json (10123ms)

danvega commented 1 year ago

At least they are they now, empty but making progress!

<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
    <channel>
        <title></title>
        <link>undefined</link>
        <description>undefined</description>
        <lastBuildDate>Mon, 16 Oct 2023 19:46:16 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <ttl>360</ttl>
    </channel>
</rss>
helltraitor commented 1 year ago

When this is complete should there be a static rss.xml file in the public/ folder?

This is up to your requirements. As for me, I'm using GitHub Pages for hosting my site. You can setup cache with same or less update time - as you want.

nvm, I see the following in the build logs...

This module was designed to work with SSR primarily - because I was using it for my own purpose (mentioned in this comment already). But I don't see any reason for this not to work this in runtime

At least they are they now, empty but making progress!

Just fill required fields in feedme options (channel meta): https://github.com/helltraitor/helltraitor.github.io/blob/nuxt/nuxt.config.ts

I will checkout your project soon, if you will not manage something to fix it

danvega commented 1 year ago

Thanks, I got the defaults setup. I also moved everything to the main branch now that it's not causing build errors

https://github.com/danvega/danvega-dev-nuxt

helltraitor commented 1 year ago

The root of problem is your field published, that is used by feed package, that my module use. This field must be date, but you are using it for your own purpose. That why I couldn't figure out, what happened from the beginning.

  feedme: {
    feeds: {
      '/feed.atom': { content: true },
      '/feed.json': { content: true },
      '/feed.xml': { content: true },
      '/rss.xml': { revisit: '1h', type: 'rss2', content: true },
    },
    content: {
      feed: {
        defaults: {
          title: 'Dan Vega',
          description: 'Personal site of Dan Vega',
          copyright: '2023 by Dan Vega',
          link: urlBase,
          id: urlBase,
          author: { email: 'danvega@gmail.com', name: 'Dan Vega' },
        },
      },
      item: {
        defaults: {
          author: [
            { email: 'danvega@gmail.com', name: 'Dan Vega' },
          ],
        },
        mapping: [
          // Description is used in Feed, so you point Feed object field to yours post field
          ['description', 'excerpt'],
          // Same
          ['link', '_path'],
          // Taking published from date, wrapping value by Date object as described in Readme
          ['published', 'date', value => value ? new Date(value) : value],
        ],
        query: {
          limit: 100,
//          where: [
//            Seems like this regex and its simple version is the path that you have. You can ignore it and use common scheme for news and post 
//            { _path: /^\/(blog|newsletter)\/[^\/]+$/ },
//          ],
        },
      }
    }
  },

Also, it seems like your site is broken. I recommend to rewrite its internals, but for know you can plate it with

  nitro: {
    baseUrl: urlBase,
    prerender: {
      crawlLinks: true,
      failOnError: false,
    },
  },

And all must work:

image

With this, my job is done, issue is closed. All is up to you (again), good luck

danvega commented 1 year ago

Thank you so much for the wonderful project and all of your help. Appreciate it 👏🏻