Default frontmatter header for all pages

Hello,

I started testing the Feed plugin and it works great so far. I’m running into an issue though: by default, I don’t want all of my pages to be included in my feed. This can be added to the frontmatter header to skip a particular page:

feed:
    skip: true

However, I have over 200 pages (and that’ll only increase as time goes on) that this will affect, so I’m looking for a faster way to do this. I could modify the plugin and change the logic so that if a page doesn’t have skip explicitly set to false then it’s automatically skipped, but I’d rather not modify the plugin if I can solve this an easier way.

Is there a way to automatically have all of my pages inherit a frontmatter header? I looked into blueprints, but this doesn’t look like what I want. As far as I understand, blueprints only work for new pages created through Admin, which I don’t use for creating or editing pages.

So, I’d like for this to be the default on all pages:

feed:
    skip: true

And then I’d override it with this on the pages I’d like to include in the feed:

feed:
    skip: false

Is this possible? Or is there an alternative that would solve this another way?

Probably would require one more option in the plugin for the default behavior if the header is missing. Maybe worth creating a feature request

@haihige, AFAIK, there is no way to define a common frontmatter that will be inherited by all pages and can be overridden by a page.

As @Karmalakas notes, it would require a change in the Feed plugin.

In the meantime, you could try the following two options I can think of:

  1. Exclude all existing items using the following shell script:

    $ find user/pages/01.blog -type f -exec sed -zi 's/\n---/\nfeed:\n  skip: true\n---/g' {} +
    

    No, it does not check:

    • if there are more occurences of \n---
    • if there is no frontmatter
    • if there is already a feed or feed: skip variable in frontmatter
    • etc.
  2. Alternatively, you could copy feed.rss.twig from the plugin into your theme and add something like {% if item.header.feed.noSkip == true %} inside the loop.

    {% for item in collection %}
       {% if item.header.feed.noSkip == true %}
       // rest of loop
       {% endif %}
    {% endfor %}
    

    Then add the following to your page:

    feed:
      noSkip: true
    

@pamtbaau, As for 1., I thought about that, but I didn’t want to add it explicitly to all of my pages, in case I forget to add it to a new one in the future.

As for 2., I tried it out and it works! Thank you.

My only concern with modifying the template in my theme is that if the plugin gets an update, I don’t want it to break my customization. I may look at how best to modify the code for a pull request.

i didnt test but i want to tell a possibility
adding a field to interface that we face when creating a page in Pages
or the interface that we face when we enter content at Pages
similar to page.title, that field will set page.feed.skip
by default it may be false
we can even just use a checkbox for that
like i said this is just an idea, need to be tested
ofc if someone knows the result already, i hope s/he would share
have a nice day :slight_smile:

I looked at the code for the Feed plugin and it wasn’t difficult to change how the skip function works. I have to test it some more and clean up my modifications, but I’ll post the PR on GitHub and link to it here when it’s ready.