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

Improve sidebar user experience #124

Closed
imfing opened this issue Oct 3, 2023 Discussed in #120 · 7 comments · Fixed by #209
Closed

Improve sidebar user experience #124

imfing opened this issue Oct 3, 2023 Discussed in #120 · 7 comments · Fixed by #209
Labels
enhancement New feature or request
Milestone

Comments

@imfing
Copy link
Owner

imfing commented Oct 3, 2023

Discussed in #120

Originally posted by msavdert October 2, 2023

  1. Is it possible to hide the Sidebar at any time and expand it at any time? like:

https://www.docsy.dev/docs/adding-content/navigation/#section-menu-options

  1. Is it possible to publish a sub-article without showing it in the sidebar? like:
---
title: Configuration
sidebar:
  open: false
---

This option only works for _index.md. This option didn't work for other .md files under the same folder to not show them in the sidebar.

Summary:

  • Support expand and collapse sidebar
  • Support hide article or page in sidebar
  • Support hide sidebar in a page
@imfing imfing added the enhancement New feature or request label Oct 3, 2023
@imfing imfing added this to the Backlog milestone Oct 11, 2023
@mafendi
Copy link
Contributor

mafendi commented Nov 9, 2023

To hide the particular page from the sidebar, I added a frontmatter to the page excludeFromSidebar: true/false

Updated sidebar.html:

      {{- with .Params.excludeFromSidebar }}
        {{- $excludeFromSidebar := . | default false }}
        {{- if not $excludeFromSidebar }}
          <li class="{{ if $shouldOpen }}open{{ end }}">
            {{- template "sidebar-item-link" dict "active" $active "title" $title "link" .RelPermalink -}}
            {{- if and $toc $active -}}
              {{- template "sidebar-toc" dict "page" . -}}
            {{- end -}}
            {{- template "sidebar-tree" dict "context" . "page" $page "pageURL" $pageURL "level" (add $level 1) "toc" $toc -}}
          </li>
        {{- end }}
      {{- else }}
        <li class="{{ if $shouldOpen }}open{{ end }}">
          {{- template "sidebar-item-link" dict "active" $active "title" $title "link" .RelPermalink -}}
          {{- if and $toc $active -}}
            {{- template "sidebar-toc" dict "page" . -}}
          {{- end -}}
          {{- template "sidebar-tree" dict "context" . "page" $page "pageURL" $pageURL "level" (add $level 1) "toc" $toc -}}
        </li>
      {{- end }}
          {{- with .Params.excludeFromSidebar }}
            {{- $excludeFromSidebar := . | default false }}
            {{- if not $excludeFromSidebar }}
              <li class="flex flex-col {{ if $shouldOpen }}open{{ end }}">
                {{- template "sidebar-item-link" dict "context" . "active" $active "title" $title "link" .RelPermalink -}}
                {{- if and $toc $active -}}
                  {{- template "sidebar-toc" dict "page" . }}
                {{- end }}
                {{- template "sidebar-tree" dict "context" . "page" $page "pageURL" $pageURL "level" (add $level 1) "toc" $toc }}
              </li>
            {{- end }}
          {{- else }}
            <li class="flex flex-col {{ if $shouldOpen }}open{{ end }}">
              {{- template "sidebar-item-link" dict "context" . "active" $active "title" $title "link" .RelPermalink -}}
              {{- if and $toc $active -}}
                {{- template "sidebar-toc" dict "page" . }}
              {{- end }}
              {{- template "sidebar-tree" dict "context" . "page" $page "pageURL" $pageURL "level" (add $level 1) "toc" $toc }}
            </li>
          {{- end }}

@imfing
Copy link
Owner Author

imfing commented Nov 10, 2023

@mafendi thanks for sharing this, that's almost what I was planning to add in the theme

@jln-ho
Copy link

jln-ho commented Nov 16, 2023

I think it would be nice to have the option to prevent the sidebar from being generated for certain pages, or is this already possible?

@imfing
Copy link
Owner Author

imfing commented Nov 17, 2023

I think it would be nice to have the option to prevent the sidebar from being generated for certain pages, or is this already possible?

@jln-ho it should be trivial to add an optional like excludeFromSidebar suggested above to prevent the page showing up on sidebar.
I'll implement it these days.

@jln-ho
Copy link

jln-ho commented Nov 17, 2023

@imfing That would exclude a single page from the sidebar. I was talking about excluding the sidebar from a single page.

@imfing imfing modified the milestones: Backlog, v0.7.0 Nov 17, 2023
@imfing imfing linked a pull request Nov 17, 2023 that will close this issue
@imfing
Copy link
Owner Author

imfing commented Nov 17, 2023

@mafendi it's implemented in #209

essentially it's a one-line change: https://github.com/imfing/hextra/pull/209/files#diff-21c3ed4170b0e684f5c718a8b3bb28e73bb15d61a3f0f2301cafcc62ca5034f3R76

@imfing
Copy link
Owner Author

imfing commented Nov 17, 2023

@imfing That would exclude a single page from the sidebar. I was talking about excluding the sidebar from a single page.

@jln-ho I've added this in the PR #209 with the following frontmatter to hide the sidebar on a specific page:

---
title: Configuration
sidebar:
  hide: true
---

Please note, this feature is currently experimental and may change as part of performance enhancements for sidebar rendering (see issue #122).

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

Successfully merging a pull request may close this issue.

3 participants