Created
October 18, 2020 08:30
-
-
Save kieranbarker/01e960ffa36ebeffc14e244414eb8270 to your computer and use it in GitHub Desktop.
Filter out draft and scheduled posts from blog collection in Eleventy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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