From e2188136e102ca7790f0b9e5efec65b49face6f1 Mon Sep 17 00:00:00 2001 From: Alex Shpak Date: Wed, 9 Oct 2019 01:00:26 +0200 Subject: [PATCH] #51, Add experimental bookCollapseSection page param to hide nested sections --- README.md | 14 ++++++---- exampleSite/config.toml | 2 +- exampleSite/config.yaml | 6 ++--- .../example/table-of-contents/3rd/4th/5th.md | 1 + .../table-of-contents/3rd/4th/_index.md | 26 +++++++++++++++++++ .../example/table-of-contents/3rd/_index.md | 22 ++++++++++++++++ layouts/partials/docs/menu-filetree.html | 16 ++++++++---- 7 files changed, 73 insertions(+), 14 deletions(-) create mode 100644 exampleSite/content/docs/example/table-of-contents/3rd/4th/5th.md create mode 100644 exampleSite/content/docs/example/table-of-contents/3rd/4th/_index.md create mode 100644 exampleSite/content/docs/example/table-of-contents/3rd/_index.md diff --git a/README.md b/README.md index 388469b..6e59f90 100644 --- a/README.md +++ b/README.md @@ -179,6 +179,9 @@ weight = 10 # (Optional) Set to mark page as flat section in file-tree menu (if BookMenuBundle not set) bookFlatSection = true +# (Optional, Experimental) Set to hide nested sections or pages at that level. Works only with file-tree menu mode +bookCollapseSection = true + # (Optional) Set true to hide page or section from side menu (if BookMenuBundle not set) bookHidden = true @@ -200,11 +203,12 @@ There are few empty partials you can override in `layouts/partials/` ### Extra Customisation -| File | Description | -| --------------------- | ------------------------------------------------------------------------------------- | -| `static/favicon.png` | Override default favicon | -| `assets/_custom.scss` | Customise or override scss styles | -| `assets/_fonts.scss` | Replace default font with custom fonts (e.g. local files or remote like google fonts) | +| File | Description | +| ------------------------ | ------------------------------------------------------------------------------------- | +| `static/favicon.png` | Override default favicon | +| `assets/_custom.scss` | Customise or override scss styles | +| `assets/_variables.scss` | Override default SCSS variables | +| `assets/_fonts.scss` | Replace default font with custom fonts (e.g. local files or remote like google fonts) | ### Hugo Internal Templates diff --git a/exampleSite/config.toml b/exampleSite/config.toml index da4ac19..32ab022 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -26,7 +26,7 @@ pygmentsCodeFences = true # (Optional, default none) Set leaf bundle to render as side menu # When not specified file structure and weights will be used - BookMenuBundle = '/menu' + # BookMenuBundle = '/menu' # (Optional, default docs) Specify section of content to render as menu # You can also set value to '*' to render all sections to menu diff --git a/exampleSite/config.yaml b/exampleSite/config.yaml index 691af01..8719742 100644 --- a/exampleSite/config.yaml +++ b/exampleSite/config.yaml @@ -16,17 +16,17 @@ pygmentsCodeFences: true params: # (Optional, default 6) Set how many table of contents levels to be showed on page. - # Use false/off to hide ToC, note that 0 will default to 6 (https://gohugo.io/functions/default/) + # Use false to hide ToC, note that 0 will default to 6 (https://gohugo.io/functions/default/) # You can also specify this parameter per page in front matter BookToC: 3 # (Optional, default none) Set the path to a logo for the book. If the logo is - # /static/logo.png then the path would be /logo.png + # /static/logo.png then the path would be logo.png # BookLogo: /logo.png # (Optional, default none) Set leaf bundle to render as side menu # When not specified file structure and weights will be used - BookMenuBundle: /menu + # BookMenuBundle: /menu # (Optional, default docs) Specify section of content to render as menu # You can also set value to '*' to render all sections to menu diff --git a/exampleSite/content/docs/example/table-of-contents/3rd/4th/5th.md b/exampleSite/content/docs/example/table-of-contents/3rd/4th/5th.md new file mode 100644 index 0000000..d956236 --- /dev/null +++ b/exampleSite/content/docs/example/table-of-contents/3rd/4th/5th.md @@ -0,0 +1 @@ +# 5th diff --git a/exampleSite/content/docs/example/table-of-contents/3rd/4th/_index.md b/exampleSite/content/docs/example/table-of-contents/3rd/4th/_index.md new file mode 100644 index 0000000..031efc8 --- /dev/null +++ b/exampleSite/content/docs/example/table-of-contents/3rd/4th/_index.md @@ -0,0 +1,26 @@ +# Locus fuit caecis + +Nefas discordemque domino montes numen tum humili nexilibusque exit, Iove. Quae +miror esse, scelerisque Melaneus viribus. Miseri laurus. Hoc est proposita me +ante aliquid, aura inponere candidioribus quidque accendit bella, sumpta. +Intravit quam erat figentem hunc, motus de fontes parvo tempestate. + + iscsi_virus = pitch(json_in_on(eupViral), + northbridge_services_troubleshooting, personal( + firmware_rw.trash_rw_crm.device(interactive_gopher_personal, + software, -1), megabit, ergonomicsSoftware(cmyk_usb_panel, + mips_whitelist_duplex, cpa))); + if (5) { + managementNetwork += dma - boolean; + kilohertz_token = 2; + honeypot_affiliate_ergonomics = fiber; + } + mouseNorthbridge = byte(nybble_xmp_modem.horse_subnet( + analogThroughputService * graphicPoint, drop(daw_bit, dnsIntranet), + gateway_ospf), repository.domain_key.mouse(serverData(fileNetwork, + trim_duplex_file), cellTapeDirect, token_tooltip_mashup( + ripcordingMashup))); + module_it = honeypot_driver(client_cold_dvr(593902, ripping_frequency) + + coreLog.joystick(componentUdpLink), windows_expansion_touchscreen); + bashGigabit.external.reality(2, server_hardware_codec.flops.ebookSampling( + ciscNavigationBacklink, table + cleanDriver), indexProtocolIsp); diff --git a/exampleSite/content/docs/example/table-of-contents/3rd/_index.md b/exampleSite/content/docs/example/table-of-contents/3rd/_index.md new file mode 100644 index 0000000..350b1e8 --- /dev/null +++ b/exampleSite/content/docs/example/table-of-contents/3rd/_index.md @@ -0,0 +1,22 @@ +--- +bookCollapseSection: true +--- + +# Caput vino delphine in tamen vias + +## Cognita laeva illo fracta + +Lorem markdownum pavent auras, surgit nunc cingentibus libet **Laomedonque que** +est. Pastor [An](http://est.org/ire.aspx) arbor filia foedat, ne [fugit +aliter](http://www.indiciumturbam.org/moramquid.php), per. Helicona illas et +callida neptem est *Oresitrophos* caput, dentibus est venit. Tenet reddite +[famuli](http://www.antro-et.net/) praesentem fortibus, quaeque vis foret si +frondes *gelidos* gravidae circumtulit [inpulit armenta +nativum](http://incurvasustulit.io/illi-virtute.html). + +1. Te at cruciabere vides rubentis manebo +2. Maturuit in praetemptat ruborem ignara postquam habitasse +3. Subitarum supplevit quoque fontesque venabula spretis modo +4. Montis tot est mali quasque gravis +5. Quinquennem domus arsit ipse +6. Pellem turis pugnabant locavit diff --git a/layouts/partials/docs/menu-filetree.html b/layouts/partials/docs/menu-filetree.html index c8dd86b..c917828 100644 --- a/layouts/partials/docs/menu-filetree.html +++ b/layouts/partials/docs/menu-filetree.html @@ -11,19 +11,19 @@ {{/* If there is only one section to render then render its children, else render all sections */}} {{ if eq (len $sections) 1 }} {{ with index $sections 0 }} - {{ template "book-section-children" (dict "Section" . "CurrentPage" $.Permalink) }} + {{ template "book-section-children" (dict "Section" . "CurrentPage" $) }} {{ end }} {{ else }} {{ end }} {{ define "book-section" }} {{ with .Section }} -
  • +
  • {{ if .Content }} {{ template "book-page-link" (dict "Page" . "CurrentPage" $.CurrentPage) }} {{ else }} @@ -36,7 +36,11 @@ {{ end }} {{ define "book-section-children" }} -{{ with .Section }} +{{ $ancestor := .Section.IsAncestor .CurrentPage }} +{{ $collapsed := .Section.Params.bookCollapseSection }} + +{{ if or $ancestor (not $collapsed) }} + {{ with .Section }} + {{ end }} {{ end }} + {{ end }} {{ define "book-page-link" }} {{ with .Page }} - + {{ partial "docs/title" . }} {{ end }}