Skip to content

Instantly share code, notes, and snippets.

@kieranbarker
Created October 18, 2020 08:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kieranbarker/01e960ffa36ebeffc14e244414eb8270 to your computer and use it in GitHub Desktop.
Save kieranbarker/01e960ffa36ebeffc14e244414eb8270 to your computer and use it in GitHub Desktop.
Filter out draft and scheduled posts from blog collection in Eleventy
// Returns a collection of blog posts in reverse date order
config.addCollection('blog', collection => {
const isLive = post => !post.data.draft && post.date <= new Date();
return collection.getFilteredByGlob('./src/posts/*.md').filter(isLive).reverse();
});
@kieranbarker
Copy link
Author

This should go inside your Eleventy config file, and must be used in conjunction with the following directory data:

https://gist.github.com/kieranbarker/95b1535449624efc834ab96dd288cfa4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment