Jieiku / abridge

Fast & Lightweight Zola Theme
https://abridge.pages.dev/
MIT License
147 stars 41 forks source link

Hide "About" when marked as Draft #92

Closed ms-ati closed 1 year ago

ms-ati commented 1 year ago

Hi @Jieiku, thank you again for this amazing theme! Is it possible to change the logic in the templates, so that when About or another Page is marked as Draft, then it will not be rendered in the navigation menu?

Thank you!

Jieiku commented 1 year ago

Yes, I think this should be easy enough to add. Will try to add this feature today.

Jieiku commented 1 year ago

This is trickier than I thought it would be, there are some ways of doing this such as changing this in config.toml:

menu = [
    {url = "/about/", name = "About", slash = true, blank = false},
    {url = "/posts/", name = "Posts", slash = true, blank = false},
    {url = "/categories/", name = "Categories", slash = true, blank = false},
    {url = "/tags/", name = "Tags", slash = true, blank = false},
]

to this:

menu = [
    {url = "/about/", name = "About", slash = true, blank = false, draft = true},
    {url = "/posts/", name = "Posts", slash = true, blank = false, draft = false},
    {url = "/categories/", name = "Categories", slash = true, blank = false, draft = false},
    {url = "/tags/", name = "Tags", slash = true, blank = false, draft = false},
]

This would however have the affect of having to set draft status both in the about.md and in the config.toml for the menus. This solution would be simple to implement but is not as convenient when it comes to managing a site/blog.

I do not really consider this a good solution because you can just as easily comment out a line for whatever menu item from config.toml and I know what your really looking for is a way for this to happen automatically when a page.md is marked as draft.

I am reviewing the tera/zola documentation for a good way of doing this.

EDIT: I think I found a more dynamic way of doing this, testing now.

ms-ati commented 1 year ago

Cool cool -- as a workaround, for anyone else reading this, it's just as easy to simply comment out the {url = "/about/", name = "About", slash = true, blank = false}, lines in config.toml for the time being while working on a draft About page -- but excited to see if you come up with a dynamic way!

Jieiku commented 1 year ago

I think the best way for now is just to comment out menu items.

I tried with a variation of get_page() as well as get_section() which as far as I know is the only way to get the variables to check if a page is marked as draft or not. https://www.getzola.org/documentation/templates/overview/

I opened a report in the zola github issue tracker so if somebody comes up with a clever way of checking if a page is a draft, or a new feature gets added to zola then I will reopen this and implement it.