Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft Posts #10

Open
flamedfury opened this issue Apr 18, 2023 · 5 comments
Open

Draft Posts #10

flamedfury opened this issue Apr 18, 2023 · 5 comments
Labels
enhancement New feature or request

Comments

@flamedfury
Copy link
Contributor

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
Copy link
Owner

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

@httpsterio
Copy link
Contributor

@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
Copy link
Owner

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
Copy link
Contributor

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
Copy link
Contributor Author

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 madrilene added the enhancement New feature or request label Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants