madrilene / eleventy-excellent

Eleventy starter based on the workflow suggested by Andy Bell's buildexcellentwebsit.es.
https://eleventy-excellent.netlify.app/
Other
382 stars 69 forks source link

Draft Posts #10

Closed flamedfury closed 1 month ago

flamedfury commented 1 year ago

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

madrilene commented 1 year ago

I'm planning to optimize quite a lot in the coming weeks and will try and include that. I'll let you know!

httpsterio commented 10 months ago

@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.

madrilene commented 10 months ago

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?

httpsterio commented 10 months ago

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.

flamedfury commented 10 months ago

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

madrilene commented 1 month ago

I just added a drafts option:

https://github.com/madrilene/eleventy-excellent/commit/84b0ea9d9267f922bf57420dfe357da33198b6f4

In development (npm run start), you can preview posts that won't be published in production (npm run build) by setting draft: true in the front matter.

---
draft: true
---