Skip to content

Instantly share code, notes, and snippets.

@kieranbarker
Last active October 18, 2020 14:12
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/95b1535449624efc834ab96dd288cfa4 to your computer and use it in GitHub Desktop.
Save kieranbarker/95b1535449624efc834ab96dd288cfa4 to your computer and use it in GitHub Desktop.
Prevent draft and scheduled posts from being written to output in Eleventy
module.exports = {
layout: 'layouts/post.html',
eleventyComputed: {
permalink(data) {
if (!data.draft && new Date(data.date) <= new Date()) {
return data.permalink || '/blog/{{ title | slug }}/index.html';
}
return false;
}
}
};
@kieranbarker
Copy link
Author

kieranbarker commented Oct 18, 2020

Line 6 assumes you're using Nunjucks and/or Liquid as your template language(s).

This directory data should be used in conjunction with the following collection in your Eleventy config file:

https://gist.github.com/kieranbarker/01e960ffa36ebeffc14e244414eb8270

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