Draft Posts
flamedfury opened this issue · 6 comments
Hi Lene,
Can draft post support to be added to eleventy-excellent?
I've had a look at Draft Posts and Scheduled and draft 11ty posts, but their configuration is slightly different — enough to trip me up.
Let me know what you think and if there is anything else that I could provide to support you.
~fLaMEd
I'm planning to optimize quite a lot in the coming weeks and will try and include that. I'll let you know!
@flamedfury
I solved this by editing the getAllPosts
const in /config/collections/index.js
like this
const getAllPosts = collection => {
const now = new Date();
const publishedPost = post => post.date <= now && !post.data.draft;
const projects = collection.getFilteredByGlob('./src/posts/*.md').filter(publishedPost);
return projects.reverse();
};
This also stops building posts that have a date set in the future, ie. it schedules their publish date.
The question is, do we want a draft system that still allows a preview of the article in development mode, or is it enough not to build the draft article at all, as is the case here?
this was just an example how I made it for my usecase so that Flamed can decide how they want to possibly implement it on their end :)
for a more general solution for the starter, I think it makes sense to build draft posts during development.
Perhaps by setting an environment variable in the dotenv file or directly into the package.json dev script would make sense.
Another option would be to check if eleventy is running using --serve and then show/hide based on that. Personally I'd prefer some option that is easy to turn on/off for development so that I can confirm that drafts are indeed excluded before pushing the site for build.
Thanks looking into this. I admit that I hadn’t put aside time to look into this myself so I appreciate it.
I do like the idea of drafts that are previewed during development but not published when built