Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple feeds + fix permalink bug #59

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

robb-j
Copy link

@robb-j robb-j commented Nov 2, 2024

Hey, I was wondering how hard it would be to support generating multiple feeds using the newer feedPlugin rather than having to manually create each feed template. I also found a bug that is fixed here but doesn't have to be tied to this.

Multiple feeds

My thinking is that you would pass feeds in your options which is an array of the previous "options" objects and it would add a virtual template for each. So you could have multiple types of feed or feeds for different content types.

This wasn't too hard to achieve but does change how it works internally a touch, the current plugin is split between eleventyFeedPlugin and the new addTemplate where that adds a single virtual template for a feed and the plugin does the things that should only happen once.

the bug

In exploring this I found the feed plugin crashes if you have an item with permalink set to false, which I'd been using to turn-off pages without deleting them. Is this still a recommended thing to do? My solution was to add a namespaced filter eleventyFeedActive to each of the feed types that filters out any collection items that have a falsey url.

testing

For my garden project I was using my local version of the plugin with this setup:

I added a test for it too

export default function (eleventyConfig) {
  eleventyConfig.addPlugin(feedPlugin, {
    feeds: [
      {
        type: 'json',
        outputPath: '/films.json',
        collection: { name: 'film', limit: 0 },
        metadata: {
          language: 'en',
          title: "Rob's Films",
          subtitle: "The films I've watched recently",
          base: 'https://garden.r0b.tech/',
          author: { name: 'Rob Anderson' },
        },
      },
      {
        type: 'json',
        outputPath: '/photos.json',
        collection: { name: 'photo', limit: 0 },
        metadata: {
          language: 'en',
          title: "Rob's Pics",
          subtitle: "Nice pictures I've take for you",
          base: 'https://garden.r0b.tech/',
          author: { name: 'Rob Anderson' },
        },
      },
      {
        type: 'json',
        outputPath: '/notes.json',
        collection: { name: 'note', limit: 0 },
        metadata: {
          language: 'en',
          title: "Rob's Notes",
          subtitle: "Thoughts I've had that might be interesting",
          base: 'https://garden.r0b.tech/',
          author: { name: 'Rob Anderson' },
        },
      },
    ]
  })
}

@pepelsbey
Copy link

pepelsbey commented Nov 13, 2024

I was just looking for a way to output multiple feeds (Atom and JSON) with the virtual template. So I’d like to see something like this implemented. Great work!

In my case, if you want to output multiple formats of your feed, you most likely will have the same options, apart from the type and the outputPath ones. I wonder if it would be possible to make it like this:

{
  type: [ // string or array for single/multiple formats
    'atom',
    'json',
  ],
  outputPath: [ // string or matching array for output paths
    '/feed.xml',
    '/feed.json',
  ],
  collection: {
    name: 'articles',
    limit: 0,
  }
}

With your use case, it might look something like this:

{
  type: 'json',
  outputPath: [
    '/films.json',
    '/photos.json',
    '/notes.json',
  ],
  collection: [
    { name: 'film', limit: 0 },
    { name: 'photo', limit: 0 },
    { name: 'note', limit: 0 },
  ],
  metadata: {
    language: 'en',
    title: "Rob's Films",
    subtitle: [
      "The films I've watched recently",
      "Nice pictures I've take for you",
      "Thoughts I've had that might be interesting",
    ],
    base: 'https://garden.r0b.tech/',
    author: { name: 'Rob Anderson' },
  },
}

@robb-j
Copy link
Author

robb-j commented Nov 14, 2024

Another option might be to use JavaScript based composition outside of the extension e.g.

const feed = {
  collection: { name: 'all', limit: 0 },
  metadata: {
    language: 'en',
    title: "Rob's feed",
    subtitle: "All the cool things",
    base: 'https://garden.r0b.tech/',
    author: { name: 'Rob Anderson' },
  },
}

// then

eleventyConfig.addPlugin(feedPlugin, {
  feeds: [
    { type: "json", outputPath: '/feed.json',  ...feed  },
    { type: "atom", outputPath: '/feed.xml', ...feed  },
  }
})

Its probably best not to bike-shed the syntax though and leave it up to @zachleat to align it with the other Eleventy APIs.

@pepelsbey
Copy link

Its probably best not to bike-shed the syntax though and leave it up to @zachleat to align it with the other Eleventy APIs.

Of course! Mostly sharing my use case here :) Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants