vjeantet / hugo-theme-docdock

Declination of @matcornic Learn theme to Hugo
https://docdock.netlify.com/
MIT License
585 stars 315 forks source link

Can you please add support multiple tutorials? #105

Open toplist2048 opened 7 years ago

toplist2048 commented 7 years ago

Current the menu is a big one to include every thing, it is ok if there is one tutorial in this website, but consider we have 100 tutorials, the big menu will be too big for every single html page. Would you guys consider a new feature to support two level menus? when in main page, show the first level menu, only show tutorial names, no table of contents, when click a tutorial name, show the second level menu, only table of contents of this tutorail, no anything of other tutorails in menu, this will help reduce the size of the pages. please consider this feature. Thanks. I tried to implement this feature, but my hugo and golang is suck, so I come here for help.

vjeantet commented 6 years ago

can you provide a visual example of you expectation ?

Your idea seems good to be implemented

toplist2048 commented 6 years ago

Hi, Thanks for response! :) I did some patch by myself. it is not a perfect fix, only the first level menus are removed. for example L1 ll1 ll2 L2 ll1 ll2 in ll1 page, the sub menu will be L1 ll1 ll2 L2 so the sub menu in L2 is removed, space saved. It saves lots of space if you have more than 100 items in L2.

the code is simple, please check.

============================================================

{{ $currentNode := . }}
{{ $showvisitedlinks := .Site.Params.showVisitedLinks }}

{{ if eq .Site.Params.ordersectionsby "title" }}
 {{ range .Site.Home.Sections.ByTitle }}
  {{ template "section-tree-nav" dict "sect" . "currentnode" $currentNode "showvisitedlinks" $showvisitedlinks }}
 {{ end }}
{{ else }}
 {{ range .Site.Home.Sections.ByWeight }}
  {{ template "section-tree-nav" dict "sect" . "currentnode" $currentNode "showvisitedlinks" $showvisitedlinks }}
 {{ end }}
{{ end }}


{{ define "section-tree-nav" }}
{{ $showvisitedlinks := .showvisitedlinks }}
{{ $currentNode := .currentnode }}
 {{ with .sect }}
  {{if and .IsSection (or (not .Params.hidden) $.showhidden)}}
    {{safeHTML .Params.head}}
    
  • {{safeHTML .Params.Pre}}{{.Title}}{{safeHTML .Params.Post}} {{$numberOfPages := (add (len .Pages) (len .Sections)) }} {{if eq .Section $currentNode.Section}} {{if ne $numberOfPages 0 }} {{if or (.IsAncestor $currentNode) (.Params.alwaysopen) }} {{else}} {{end}} {{end}} {{end}} {{if $showvisitedlinks}}{{end}} {{if eq .Section $currentNode.Section}} {{if ne $numberOfPages 0 }}
      {{.Scratch.Set "pages" .Pages }} {{if .Sections}} {{.Scratch.Set "pages" (.Pages | union .Sections) }} {{end}} {{$pages := (.Scratch.Get "pages") }} {{if eq .Site.Params.ordersectionsby "title"}} {{range $pages.ByTitle }} {{if and .Params.hidden (not $.showhidden) }} {{else}} {{template "section-tree-nav" dict "sect" . "currentnode" $currentNode "showvisitedlinks" $showvisitedlinks }} {{end}} {{end}} {{else}} {{range $pages.ByWeight }} {{if and .Params.hidden (not $.showhidden) }} {{else}} {{template "section-tree-nav" dict "sect" . "currentnode" $currentNode "showvisitedlinks" $showvisitedlinks }} {{end}} {{end}} {{end}}
    {{end}} {{end}}
  • {{else}} {{if not .Params.Hidden }}
  • {{safeHTML .Params.Pre}}{{.Title}}{{safeHTML .Params.Post}} {{if $showvisitedlinks}}{{end}}
  • {{end}} {{end}} {{end}} {{end}}

    =================================================

    some thought, if we can do something support remove more menu, like L1 ll1 lll1 ll2 lll1 L2 ll2 in ll1-> ll1 page, the sub menu will be L1 ll1 lll1 ll2 L2 ll2 Not sure if clear to you. thansk for consider my suggestion!

    btw, a new suggestion. when click next page, or input one page in url, can we let the menu move to the corresponding page? How to do it?