Skip to content

Building hidden pages #699

Closed
Closed

Description

@jhamman

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.

I asked this question here as well: https://groups.google.com/forum/#!topic/mkdocs/ILW9-SIdERs

Activity

  1. keelii commented on Jul 27, 2015

    @keelii

    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 pattern to set, It would be better ^!^ :

    mdFiles: docs/*/*.md
    
  2. waylan commented on Jul 27, 2015

    @waylan
    Contributor

    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.

  3. jhamman commented on Jul 27, 2015

    @jhamman
    Author

    Thanks @waylan - Good to know.

    Any thoughts on how difficult this feature would be to add? The hidden: true api is exactly what I was envisioning.

  4. mistresseve666 commented on Jul 29, 2015

    @mistresseve666

    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.

  5. waylan commented on Jul 29, 2015

    @waylan
    Contributor

    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.

  6. jhamman commented on Jul 29, 2015

    @jhamman
    Author

    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...

    This is the original "base.html" file:
    https://github.com/mkdocs/mkdocs/blob/master/mkdocs/themes/readthedocs/base.html

    mkdocs.yml

    # 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.

  7. d0ugal commented on Jul 30, 2015

    @d0ugal
    Contributor

    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?

  8. lovelydinosaur commented on Jul 30, 2015

    @lovelydinosaur
    Collaborator

    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.

    I am not sure how #689 is looking to add this

    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.

  9. mistresseve666 commented on Jul 31, 2015

    @mistresseve666

    @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.

    For example:

    pages:
    - 'Introduction': 'index.md'
    - 'User Guide': 'user-guide.md'
    - 'About': 'about.md'
    - hidden_file.md
    - hidden/folder/*.md
    - extension/generated/apis/*.md
    

    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...

  10. waylan commented on Aug 3, 2015

    @waylan
    Contributor

    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.

  11. mistresseve666 commented on Aug 3, 2015

    @mistresseve666

    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.

  12. waylan commented on Aug 3, 2015

    @waylan
    Contributor

    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.

  13. mistresseve666 commented on Aug 4, 2015

    @mistresseve666

    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 😄.

  14. dmehra commented on Nov 18, 2015

    @dmehra

    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:

    pages:
    - Concepts:
       - 'Overview': 'concepts/overview.md'
       - '________': 'concepts/quick_ref.md'
       - '________': 'concepts/hello_world.md'
    - Modules:
      - 'String': 'modules/string.md'
      - '________': 'modules/string_intro.md'
    

    This is the salient part of my toc.html:

      {% 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.

  15. jberkel commented on Nov 18, 2015

    @jberkel

    @dmehra a bit more flexible approach is simply to check for a title beginning with '_':

    {% if not nav_item.title.startswith("_") %}
    
    pages:
    - Concepts:
       - 'Overview': 'concepts/overview.md'
       - '_QuickRef': 'concepts/quick_ref.md'

    This way you can easily enable / disable headings, and you don't need to count the number of "_" used.

  16. 37 remaining items

  17. gsouf commented on Jan 17, 2018

    @gsouf

    Not sure that's the subject of the ticket

  18. waylan commented on Jan 17, 2018

    @waylan
    Contributor

    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.

  19. added a commit that references this issue on Jan 27, 2018
  20. added a commit that references this issue on Apr 4, 2018
  21. added a commit that references this issue on May 9, 2018
  22. ojacques commented on Mar 13, 2020

    @ojacques

    Side note, but helpful for some: mkdocs-awesome-pages-plugin allows to build, but hide an entire directory.

    image

  23. matchavez commented on Jan 11, 2021

    @matchavez

    Can you just make it a "" in the nav?

  24. matchavez commented on Jan 12, 2021

    @matchavez

    Well, turns out this was updated with #1504 - all pages are now built; just leave them out of the nav structure.

  25. locked as resolved and limited conversation to collaborators on Jan 12, 2021
  26. added a commit that references this issue on Jan 18, 2025
    34ef3ca
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions