Skip to content
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

Hide toc or navigation seems not work #39

Closed
zclab opened this issue Mar 2, 2022 · 11 comments · Fixed by #40
Closed

Hide toc or navigation seems not work #39

zclab opened this issue Mar 2, 2022 · 11 comments · Fixed by #40
Assignees

Comments

@zclab
Copy link

zclab commented Mar 2, 2022

When I try to hide table of contents sidebars or navigation, it did not work. I add the following line in markdown files

---
hide:
  - navigation
  - toc
---

Is this the right method to hide table of contents sidebars or navigation? Thanks.

@zclab
Copy link
Author

zclab commented Mar 2, 2022

After I modified the following code at nav_adapt.py, the toc or navigation can be hidded,

page = dict(
        title=page_title,
        is_homepage=(pagename == context["master_doc"]),
        toc=local_toc,
        meta={"hide": meta.get("hide", []), "revision_date": context.get("last_updated")},
        content=context.get("body"),
    )

@2bndy5
Copy link
Collaborator

2bndy5 commented Mar 2, 2022

Is this the right method to hide table of contents sidebars or navigation?

No. This is not mkdocs. This theme is for sphinx which generally uses rst (restructuredText) files. If you're using md files then you're likely using a sphinx extension to do so. In which case the meta data that can be used in mkdocs-material is not always supported in sphinx-immaterial. On that note, all the markdown extensions used by mkdocs-material are not used by sphinx-immaterial.

You can have a look at this theme's docs to see how to customize it.

I don't think that hiding the sidebars are a supported feature in this theme.

@2bndy5
Copy link
Collaborator

2bndy5 commented Mar 2, 2022

In rst files, adding meta data would be done at the top of the file like so:

:hide: toc, navigation

.. or

:hide: toc
:hide: navigation

I have not tested this.

What sphinx extension are you using to use md files?

@2bndy5
Copy link
Collaborator

2bndy5 commented Mar 2, 2022

I misread this comment. You're welcome to submit a PR with your changes, but I'd ask that there be some addition to this theme's docs on how to use the metadata (in RST files).

@zclab
Copy link
Author

zclab commented Mar 2, 2022

Thanks for your answering. Great help.

You can have a look at this theme's docs to see how to customize it.

I double checked the docs, there is no guidance to hide toc or navigation. I think I use the theme incorrectly, I did not notice the meta data that can be used in mkdocs-material is not always supported in sphinx-immaterial.

:hide: toc, navigation

.. or

:hide: toc
:hide: navigation

I have tested it, seems not work. I think the code meta={"hide": [], "revision_date": context.get("last_updated")} at nav_adapt.py gives an empty hide meta data, it seems the meta 'hide' are not caught.

I am not familiar with Sphinx, I am not sure if this is the reason.

What sphinx extension are you using to use md files?

I am using myst_parser extension which allows to write MyST Markdown in Sphinx.

@2bndy5
Copy link
Collaborator

2bndy5 commented Mar 2, 2022

From looking at the nav_adapt.py, I see that you can hide the toc by using

:tocdepth: 0

..
    I'm not sure what this would look like in MD.

but I don't see support for hiding the navigation.

@2bndy5
Copy link
Collaborator

2bndy5 commented Mar 2, 2022

I was able to add support for hiding navigation by changing

if meta and meta.get("tocdepth") == 0:
page["meta"]["hide"].append("toc")

to

    if meta:
        if meta.get("tocdepth") == 0:
            page["meta"]["hide"].append("toc")
        if meta.get("hide") == "navigation":
            page["meta"]["hide"].append("navigation")

This means the following metadata would need to be used to hide the toc and the navigation:

:tocdepth: 0
:hide: navigation

This is a worthy contribution opportunity. Remember, the docs would need to be updated as well (preferrably after the :hero: description because it is metadata).

@2bndy5
Copy link
Collaborator

2bndy5 commented Mar 3, 2022

@zclab Please update your install of sphinx-immaterial in a few hours. v0.4 has added support for this issue. Thank you for bringing this to our attention.

After more discussion (in #40) about how to implement this, we've settled on

:hide-navigation:
:hide-toc:

Additionally, the following will still work to hide the toc

:tocdepth: 0

I had a look at the MyST parser extension, and I didn't see any explicit mention of supporting metadata. However, given the discussion in executablebooks/MyST-Parser#286 , you could try using

---
hide-navigation: true
hide-toc: true
---

or optionally (to just hide the toc)

---
tocdepth: 0
---

@zclab
Copy link
Author

zclab commented Mar 3, 2022

Cool 👍, thanks !

@2bndy5
Copy link
Collaborator

2bndy5 commented Mar 3, 2022

Is that confirming that it works with MyRST parser?

@zclab
Copy link
Author

zclab commented Mar 3, 2022

Is that confirming that it works with MyRST parser?

---
hide-navigation: true
hide-toc: true
---

Yes, it works very well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants