-
Notifications
You must be signed in to change notification settings - Fork 990
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
page toc does not work in shortcodes. #584
Comments
Shortcodes are rendered before the markdown is parsed so the toc isn't available yet. |
Is this something that can be added in a later version? Having the TOC generated by the template is not ideal since the position is always fixed whereas with a shortcode we can have content (introduction, updates, etc) before the TOC as well. |
Having it in a shortcode is unlikely to happen right now, it would require going through the markdown parser twice. |
The |
You can work around this issue by using the
Now you can put |
This ToC is only shown when the screen is too small for the sticky sidebar ToC. We use a `<!-- toc -->` comment and the `replace` function to allow inserting the ToC at well defined points of the page. We don't use the shortcode feature of Zola because of getzola/zola#584.
@phil-opp Thanks, that's a nice workaround. |
It seems the workaround is broken with zola v0.6.0
|
The From the changelog:
|
@Keats Could you update this in the documentation at https://www.getzola.org/documentation/content/table-of-contents/? |
Done, sorry about that! |
That was quick, thanks! |
@shalzz can this be closed? |
@Keats This still doesn't work with shortcodes so If you want to accept the workaround as a solution then sure, we can close this but this might need to be mentioned in the docs as yet another caveat, with a brief of the workaround? |
let's update the docs, I don't believe the toc will be coming to shortcodes anytime soon. |
OK, closing issue. |
Sorry to reply to such an old issue but I cannot find it in the docs. Can you add a link to where it is in the docs please? |
https://www.getzola.org/documentation/content/shortcodes/#writing-a-shortcode in the last paragraph |
Thanks, I thought the workaround was somewhere in the docs and I'd missed it. Will look into the tera docs for more on macros. On another but related note, I've been thinking that a list of examples would be useful. Like an example of how to do the various things in the documentation (so I guess this work around wouldn't be in that list). But basically somewhere people can go to get an example rather than just trying to read and apply the documentation. It's not difficult to apply what you find in the documentation to be fair but it's also not trivial and takes longer than working from an example. I'd be happy to contribute examples for the ones I've used if that would be helpful. Or maybe the examples could all be on one "site" and use a different page in the site for each example IDK what's the best way but I think it would be helpful. |
I'm planning to rewrite the documentation almost entirely as part of 0.17, and there will be a "how to" section. Don't expect that anytime soon though. |
It's far from urgent, no worries. Let me know if I can help in that regard. I'm not the best at writing docs for things I understand (usually takes more effort because I forget what I didn't know when I started) but still pretty new to zola so hopefully I should be able to help. If possible try to include code snippets, I've realized the value in them over time. They really make the overview concrete and easy to test that you can get it to work so you can modify to see what effect it will have. |
Do you have somewhere you are documenting things to modify during the rewrite? I just remembered I wanted to make a pull request to update the documentation for resize_image as I had some issues when I started using it that were not captured in the documentation. I can look up the details if that's helpful, don't remember them off hand. As well as the documentation regarding setting up automated builds on github (it was something to do with secrets, based on my notes that I just saw). |
Not really, I'm hoping people will contribute to the "how to" section. Please do send PR for documentation changes now, 0.17 is not happening anytime soon. |
Ok thanks I'll leave it on my list of things to do. Want to write it up and make sure it's clear so I'll do it when I have a bit more time. And I'd be very happy to contribute to the how-to section |
This helped a lot, thank you. Instead of putting |
Bug Report
The page.toc Array is empty when used in a shortcode but works in a template.
Environment
Linux
Zola version: 0.5.1
Expected Behavior
page.toc should not be empty inside a shortcode.
Current Behavior
page.toc is empty when used in a shortcode
Step to reproduce
The text was updated successfully, but these errors were encountered: