-
First of all, this is a great plugin; thank you for making this available to the community. I'm working on a project where we'd like to use this plugin with a lightweight soft of "feature flags" system to show or hide certain parts of our user documentation based on the presence of these flags. For the content, defining our own is_enabled macro works great. However, we're not sure on the best way to conditionally modify the navigation. Currently we have this in the mkdocs.yml -- and we'd like to check the flags to determine if certain pages should be excluded nav:
- "Introduction": "introduction.md"
- "Feature One": "feature-one.md"
{% if is_enabled("feature-two") %}
- "Feature Two": "feature-two.md"
{% endif %} This does not work as-is, unsurprisingly. Is there another strategy to achieve this? Is the best option to subclass the plugin and override on_nav ? Or perhaps the easiest option is to just make a new plugin locally that does this one thing? I also noticed that on_nav implementation in this plugin does store off the original navigation object as "navigation" var. Is there a hook that this plugin supports where that nav structure could be modified? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Thanks a lot for your appreciation! I had not thought about your use case, but it makes a lot of sense. Indeed, Mkdocs-Macros plugin won't work directly with the snippet above, since the plugin renders only the markdown files. You could take a number of approaches, depending on your use case and circumstances. 🤔 You wish to make this choice at build/serve time, right? In that case, why don't follow your idea through, but without the plugin? A simple solution could be: you create source config file called, e.g. You could write a Python utility that does more or less this:
Then you would create a script that does this:
I hope this helps. |
Beta Was this translation helpful? Give feedback.
Thanks a lot for your appreciation! I had not thought about your use case, but it makes a lot of sense.
Indeed, Mkdocs-Macros plugin won't work directly with the snippet above, since the plugin renders only the markdown files.
You could take a number of approaches, depending on your use case and circumstances. 🤔 You wish to make this choice at build/serve time, right?
In that case, why don't follow your idea through, but without the plugin? A simple solution could be: you create source config file called, e.g.
mkdocs_source.yaml
which contains exactly the code you suggested.You could write a Python utility that does more or less this:
doc…