zola icon indicating copy to clipboard operation
zola copied to clipboard

get_page() fails if a page is marked as draft, not sure how else to check if a page is a draft while building menu

Open Jieiku opened this issue 2 years ago • 8 comments

Bug Report

Environment

Zola version: 0.16.0

Expected Behavior

This function is probably working as originally intended, so what I am asking for may actually be a new feature unless there is another way to accomplish this?

Current Behavior

This started with a feature request to not show certain menu items if those pages are marked as draft. https://github.com/Jieiku/abridge/issues/92

I created a solution:

https://github.com/Jieiku/abridge/commit/bca64259827edb25a19c4b910ab28907b0b29d93

but if I set draft = true for about.md then zola no longer builds/serves the site.

Building site...
Checking all internal links with anchors.
> Successfully checked 1 internal link(s) with anchors.
-> Creating 12 pages (2 orphan) and 2 sections
Error: Failed to serve the site
Error: Failed to render section '/home/jieiku/.dev/abridge/content/posts/_index.md'
Error: Reason: Failed to render 'posts.html' (error happened in a parent template)
Error: Reason: Function call 'get_page' failed
Error: Reason: Page `pages/about.md` not found.

Step to reproduce

git clone -b menu-draft-check https://github.com/Jieiku/abridge
cd abridge
zola serve

The site will serve/build if you set draft = false in content/pages/about.md

If there is another way of doing this that I have not figured out then I appologize for the report, I did review the zola and tera documentation first and spent a couple of days thinking about the issue.

Jieiku avatar Sep 19 '22 18:09 Jieiku

We could add a param to get_page to include drafts

Keats avatar Sep 28 '22 20:09 Keats

That sounds awesome, I am still new to rust but could give it a try, I am almost half way through the book.

Jieiku avatar Sep 28 '22 20:09 Jieiku

Anyone interested in taking that issue?

Keats avatar Jan 17 '23 22:01 Keats

Life threw me a curve ball, have not had time to try myself :( I should have came back and said so, sorry about that. No idea when I will have some free time again.

Jieiku avatar Jan 17 '23 22:01 Jieiku

No worries, it's fine. I'll take it if no one asks for it.

Keats avatar Jan 17 '23 22:01 Keats

I can give this a shot, if this is still available?

One possibly silly question (apologies, I'm very new to Zola): it looks to me like during the initial directory walk that if include_drafts is false, that the library will entirely skip over recording those pages.

Would the solution here be to include another AHashMap<PathBuf, Page> just for drafts in Library, and then have GetPage check that instead if its draft param is set?

pqcfox avatar Feb 12 '23 09:02 pqcfox

Hmm I forgot we were not loading them at all. I'll focus on releasing 0.17 and then we can figure out what we want to do here. So far only one person needing it so maybe it's not that important.

Keats avatar Feb 12 '23 12:02 Keats

Poking around through similar issues while wanting to work on a related change, I think I might be able to solve this at the same time. Adding a flag for allowing drafts seems simple enough, although we'd also probably want to add a flag to the template metadata that lets you check if a post is a draft when loading it too.

clarfonthey avatar Dec 21 '23 22:12 clarfonthey