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 Table Of Contents when theres only 1 item #46

Open
christianseel opened this issue Apr 18, 2019 · 7 comments
Open

Hide Table Of Contents when theres only 1 item #46

christianseel opened this issue Apr 18, 2019 · 7 comments

Comments

@christianseel
Copy link
Contributor

Summary

When showing the TOC, we should make sure there is more than 1 item. I'd propose to hide when there's only 1 heading

Why?

Not helpful for such small pages

@Mark-H
Copy link
Collaborator

Mark-H commented Apr 18, 2019

Got an example link of a page where this happens?

@christianseel
Copy link
Contributor Author

@Mark-H
Copy link
Collaborator

Mark-H commented Apr 29, 2019

Rather than fixing this in the app, I think we can fix this in the documentation sources, by simply removing that one heading.

@christianseel
Copy link
Contributor Author

I'd say a single heading in a document is still important and helps structuring text visually and helps the human eye scanning a document. So I'd say single headlines should be kept!

In the case of that maintenance page the headline below the title is of course useless.
But there might be valid examples like this: https://docs.modx.org/current/en/building-sites/client-proofing/dashboards/usergroups

@Ibochkarev
Copy link
Contributor

@Mark-H Can do this:

            {% if toc is not empty %}
                <div class="l-main__toc">
                    <nav class="c-toc" aria-labelledby="toc-title">
                        <div class="c-toc__wrapper">
                            <span class="c-toc__title" id="toc-title">
                                {{ lang.in_this_document }}
                            </span>
                            {{ toc|raw }}
                        </div>
                    </nav>
                </div>
            {% endif %}

Change to

            {% if toc|length > 1 %}
                <div class="l-main__toc">
                    <nav class="c-toc" aria-labelledby="toc-title">
                        <div class="c-toc__wrapper">
                            <span class="c-toc__title" id="toc-title">
                                {{ lang.in_this_document }}
                            </span>
                            {{ toc|raw }}
                        </div>
                    </nav>
                </div>
            {% endif %}

@Mark-H
Copy link
Collaborator

Mark-H commented Mar 3, 2021

The toc variable contains the rendered (HTML) table of contents, not the number of results unfortunately.. So checking the length will only tell you that it has a value.

In Model/Page->getTableOfContents it parses the body to get the menu:

            return $tocGenerator->getHtmlMenu(
                $this->getRenderedBody(),
                $topLevel,
                $depth,
                $renderer
            );

From TocGenerator::getHtmlMenu:

        $menu = $this->getMenu($markup, $topLevel, $depth);
        return $renderer->render($menu);

So in Page->getTableOfContents I think we'll need to change getHtmlMenu to getMenu, check if it has at least 2 items, and if so render it.

@Ibochkarev
Copy link
Contributor

Well then check for JS and hide this section

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

No branches or pull requests

3 participants