You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is it possible to tell mkdocs to build pages but not have them show up in the side bar? If it is possible, an example of how to do this in the documentation would be great.
Reacted by Stephen Drew, Mikey Lombardi (He/Him), oxyc, Colin MacCreery, Jack Ma, Carlos Rueda, Marco Labarile, csnyulas, Pedro Melo, Feryandi Nurdiantoro and 2 more
No this is not possible as this time. I am not aware that it is on the road-map either, although I am not the one to make such a decision. I would suggest that if such a feature was to be implemented, it would use the page meta-data to define a page as "hidden" (perhaps by adding a hidden: true key-value pair to the meta-data for the page). Then, when building the nav, it would simply be skipped.
I've ran across this same exact issue a few weeks ago, and adopted the same method that Docker used for their docs (they recently adopted Hugo):
Set the Page Title in the mkdocs.yml file to a special value (they used HIDDEN).
Update the Template to not include a pages with the above special value.
It feels very hacky, but it's working well enough for me right now. The docs base I'm maintaining is far smaller than Docker's so it's OK for now. I can imagine if you have a larger documentation base it might get annoying to maintain.
@waylan From trying to figure out how to get around this limitation, and reading older issues people opened on this topic it doesn't seem to be something that plans to be supported by mkdocs; and I would agree. mkdocs is intended to be used for simple documentation. Having dozens of hidden pages to be used for links only is a step above simple. Personally, I'd rather see this handled via a extension once API support is added.
According to a recent edit to the first comment on #689 this is addressed by the work there. That said, it is not clear to me how or when that work will be merged in.
In any event, I agree that this seems more like a feature for a plugin API.
Thanks for the input @robodude666 and @waylan. I went ahead and modified the read-the-docs theme to exclude nav items == 'hidden'. That seems to be working locally and on read-the-docs.
This solution came from @martinzugnoni and works like a charm, albeit a bit hackish...
# Pages not available to end users
- 'hidden': 'internal_endpoints.md'
base.html
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation"><ul class="current">{% for nav_item in nav %}{% if nav_item.title != "hidden" %} <=== this is the important line<li>{% include "toc.html" %}<li>{% endif %}{% endfor %}</ul></div>
Given that this was pretty easy to implement, and has nothing to do with the complexity of the site, I would still like to see this become part of the larger package.
Reacted by raknjak, Jorge Escobar, Rei Vilo and NILADRI DAS
Neat, good to see that you found a work around for this. I would like to see this work with the Markdown metadata. For example, you might add "hidden: true" to the top of the file and then it will be excluded from the nav. I am not sure how #689 is looking to add this. @tomchristie?
Rather than having to include them in the nav with 'hidden' it'd make more sense to just build all .md pages irrespective of if they're in 'pages' or not.
@tomchristie If pages is being used by a project I'd rather see mkdocs warn when a page is built but not in pages, and then add the ability to list only the filename/globs w/o a name.
This makes it explicit that these files are intended to be hidden, as no title is given to them (title can be extracted from filename/metadata in these cases).
It'll also help catch cases where the author or contributor creates a new file but forgets to update pages. This way they'll get a warning, which they can explicitly silence by adding it to the pages list.
It also makes it possible for extensions to generate pages that will be included, though albeit extensions would probably have access to modify the pages config...
Reacted by Guo, Joram van den Boezem and Abhishek Munagekar
This makes it explicit that these files are intended to be hidden, as no title is given to them (title can be extracted from filename/metadata in these cases).
My preference would be to always define the Title in the meta-data and never in the config. But according to the above proposal, that would make all my pages "hidden" which is not what I want.
All "hidden" means is that the page is excluded from the nav menu. Interestingly, if no pages config is provided, all pages are auto-discovered and included in the nav menu. All the pages config gives you is a clear way to define order and nesting of the nav menu (I see the ability to define a title as a convenient side effect). It would follow quite naturally then, that any pages not listed in the pages config would then not be listed in the nav menu. As #689 gives us this already (albeit with a warning), I don't see much room for improvement.
My preference would be to always define the Title in the meta-data and never in the config.
I would agree with you, as I don't personally like my recommendation of excluding the title; it was just a simply example to illustrate explicitly hiding pages without having to add a whole bunch of new config options. If we would rather have a boolean flag in the metadata of a page, that would be fine too.
As #689 gives us this already (albeit with a warning), I don't see much room for improvement.
The improvement I'm suggesting is to only give warnings for pages that weren't explicitly hidden. If I have 100 API docs that I'm trying to hide from the navigation I don't want to see 100 warnings when I build my docs. That will make the warnings meaningless if I'm always going to ignore them as it makes it very easy for an important warning to go unnoticed.
I don't want to see 100 warnings when I build my docs.
Right, and as @tomchristie stated, those warnings should be able to be turned off. I assumed that that was clear and didn't restate it. Sounds like we are on the same page here.
I'm trying to point out that they should only be turned off for specific pages, not all. If I mark 5 pages as hidden, and create a new *.md file I should get 1 warning. If that's understood then I'm okay 😄.
I found the same need to hide pages from the sidebar nav, as our docs have ~200 pages, and we don't want all of them present in the sidebar menu (if collapsible nav were available per #588, that may remove the need for hiding, or perhaps still not).
What I ended up doing (in a custom theme override of toc.html) is this, inspired by comment #699 (comment) above, but replacing the word hidden with underscores ________ so it's easy to see in my mkdocs.yml which pages are hidden, it looks like this:
{% if nav_item.title != "________" %}
<li class="toctree-l1 {% if nav_item.active%}current{%endif%}">
<a class="{% if nav_item.active%}current{%endif%}" href="{{ nav_item.url }}">{{ nav_item.title }}</a>
...
</li>
{% endif %}
{% endif %}
The reason I prefer this approach to using markdown metadata is that I'd rather specify what is hidden or included in the same place where I'm organizing the menu layout. If it had to be in the metadata, it would be spread across individual markdown files. That would be useful if I didn't have to list out all the pages in mkdocs.yml, but that only works if pages is omitted altogether, in which case I cannot control the menu layout at all (undesired for my project with lots of files and structure).
If you'd like the underscores hack upstream in readthedocs theme, I'm happy to put up a 2-line PR (plus documentation). Perhaps by now there is a better solution for what I'm doing, if so please advise. I couldn't tell what behavior would be delivered by the referenced #689.
This way you can easily enable / disable headings, and you don't need to count the number of "_" used.
Reacted by Mark Allasread, raknjak, Patrick Kastner, Filis Futsarov, Vitali Lobanov, Marco Labarile, Esteban Echeverry, Pedro Melo, Saiprasad Balasubramanian and rbq
Ok, let's keep the conversation on topic please. As it stands, this feature is definitely going to be added and more "me too" comments will only add to the noise. As stated in a previous comment, it is a work in progress. We are volunteers working on this in our spare time and more noise here doesn't give us more spare time.
Reacted by Souf G, Frank Brückner, mistresseve666, Patrick, Mark Allasread, Michell Stuttgart, Jonah Snider and rbq
Activity
keelii commentedon Jul 27, 2015
I have the same question
mkdocs only build specified .md files in yml. Sometimes i use relative path to reference md file, but it not working for me .
if there is a
glob patternto set, It would be better ^!^ :waylan commentedon Jul 27, 2015
No this is not possible as this time. I am not aware that it is on the road-map either, although I am not the one to make such a decision. I would suggest that if such a feature was to be implemented, it would use the page meta-data to define a page as "hidden" (perhaps by adding a
hidden: truekey-value pair to the meta-data for the page). Then, when building the nav, it would simply be skipped.jhamman commentedon Jul 27, 2015
Thanks @waylan - Good to know.
Any thoughts on how difficult this feature would be to add? The
hidden: trueapi is exactly what I was envisioning.mistresseve666 commentedon Jul 29, 2015
I've ran across this same exact issue a few weeks ago, and adopted the same method that Docker used for their docs (they recently adopted Hugo):
It feels very hacky, but it's working well enough for me right now. The docs base I'm maintaining is far smaller than Docker's so it's OK for now. I can imagine if you have a larger documentation base it might get annoying to maintain.
@waylan From trying to figure out how to get around this limitation, and reading older issues people opened on this topic it doesn't seem to be something that plans to be supported by mkdocs; and I would agree. mkdocs is intended to be used for simple documentation. Having dozens of hidden pages to be used for links only is a step above simple. Personally, I'd rather see this handled via a extension once API support is added.
waylan commentedon Jul 29, 2015
According to a recent edit to the first comment on #689 this is addressed by the work there. That said, it is not clear to me how or when that work will be merged in.
In any event, I agree that this seems more like a feature for a plugin API.
jhamman commentedon Jul 29, 2015
Thanks for the input @robodude666 and @waylan. I went ahead and modified the read-the-docs theme to exclude nav items == 'hidden'. That seems to be working locally and on read-the-docs.
This solution came from @martinzugnoni and works like a charm, albeit a bit hackish...
mkdocs.yml
base.html
Given that this was pretty easy to implement, and has nothing to do with the complexity of the site, I would still like to see this become part of the larger package.
d0ugal commentedon Jul 30, 2015
Neat, good to see that you found a work around for this. I would like to see this work with the Markdown metadata. For example, you might add "hidden: true" to the top of the file and then it will be excluded from the nav. I am not sure how #689 is looking to add this. @tomchristie?
lovelydinosaur commentedon Jul 30, 2015
Rather than having to include them in the nav with 'hidden' it'd make more sense to just build all .md pages irrespective of if they're in 'pages' or not.
At the moment that'd build all md files, and warn if any of them are not in pages. For this behavior we'd simply want to turn that warning off.
mistresseve666 commentedon Jul 31, 2015
@tomchristie If
pagesis being used by a project I'd rather see mkdocs warn when a page is built but not inpages, and then add the ability to list only the filename/globs w/o a name.For example:
This makes it explicit that these files are intended to be hidden, as no title is given to them (title can be extracted from filename/metadata in these cases).
It'll also help catch cases where the author or contributor creates a new file but forgets to update pages. This way they'll get a warning, which they can explicitly silence by adding it to the pages list.
It also makes it possible for extensions to generate pages that will be included, though albeit extensions would probably have access to modify the
pagesconfig...waylan commentedon Aug 3, 2015
My preference would be to always define the Title in the meta-data and never in the config. But according to the above proposal, that would make all my pages "hidden" which is not what I want.
All "hidden" means is that the page is excluded from the nav menu. Interestingly, if no pages config is provided, all pages are auto-discovered and included in the nav menu. All the pages config gives you is a clear way to define order and nesting of the nav menu (I see the ability to define a title as a convenient side effect). It would follow quite naturally then, that any pages not listed in the pages config would then not be listed in the nav menu. As #689 gives us this already (albeit with a warning), I don't see much room for improvement.
mistresseve666 commentedon Aug 3, 2015
I would agree with you, as I don't personally like my recommendation of excluding the title; it was just a simply example to illustrate explicitly hiding pages without having to add a whole bunch of new config options. If we would rather have a boolean flag in the metadata of a page, that would be fine too.
The improvement I'm suggesting is to only give warnings for pages that weren't explicitly hidden. If I have 100 API docs that I'm trying to hide from the navigation I don't want to see 100 warnings when I build my docs. That will make the warnings meaningless if I'm always going to ignore them as it makes it very easy for an important warning to go unnoticed.
waylan commentedon Aug 3, 2015
Right, and as @tomchristie stated, those warnings should be able to be turned off. I assumed that that was clear and didn't restate it. Sounds like we are on the same page here.
mistresseve666 commentedon Aug 4, 2015
I'm trying to point out that they should only be turned off for specific pages, not all. If I mark 5 pages as hidden, and create a new *.md file I should get 1 warning. If that's understood then I'm okay 😄.
dmehra commentedon Nov 18, 2015
I found the same need to hide pages from the sidebar nav, as our docs have ~200 pages, and we don't want all of them present in the sidebar menu (if collapsible nav were available per #588, that may remove the need for hiding, or perhaps still not).
What I ended up doing (in a custom theme override of toc.html) is this, inspired by comment #699 (comment) above, but replacing the word
hiddenwith underscores________so it's easy to see in my mkdocs.yml which pages are hidden, it looks like this:This is the salient part of my toc.html:
The reason I prefer this approach to using markdown metadata is that I'd rather specify what is hidden or included in the same place where I'm organizing the menu layout. If it had to be in the metadata, it would be spread across individual markdown files. That would be useful if I didn't have to list out all the pages in mkdocs.yml, but that only works if
pagesis omitted altogether, in which case I cannot control the menu layout at all (undesired for my project with lots of files and structure).If you'd like the underscores hack upstream in readthedocs theme, I'm happy to put up a 2-line PR (plus documentation). Perhaps by now there is a better solution for what I'm doing, if so please advise. I couldn't tell what behavior would be delivered by the referenced #689.
jberkel commentedon Nov 18, 2015
@dmehra a bit more flexible approach is simply to check for a title beginning with '_':
This way you can easily enable / disable headings, and you don't need to count the number of "_" used.
37 remaining items
gsouf commentedon Jan 17, 2018
Not sure that's the subject of the ticket
waylan commentedon Jan 17, 2018
Ok, let's keep the conversation on topic please. As it stands, this feature is definitely going to be added and more "me too" comments will only add to the noise. As stated in a previous comment, it is a work in progress. We are volunteers working on this in our spare time and more noise here doesn't give us more spare time.
Allow "hidden" pages
Allow "hidden" pages
Update mkdocs.yml
Add fix for toc.html partial from the Material template:
ojacques commentedon Mar 13, 2020
Side note, but helpful for some:
mkdocs-awesome-pages-pluginallows to build, but hide an entire directory.matchavez commentedon Jan 11, 2021
Can you just make it a "" in the nav?
matchavez commentedon Jan 12, 2021
Well, turns out this was updated with #1504 - all pages are now built; just leave them out of the nav structure.
Internal Refactor of Pages, Files, and Navigation (mkdocs#1504)