diff options
| -rw-r--r-- | CHANGELOG.md | 3 | ||||
| -rw-r--r-- | archetypes/default.md | 3 | ||||
| -rw-r--r-- | exampleSite/content/documentation/index.md | 17 | ||||
| -rw-r--r-- | exampleSite/content/narratives/narrative.md | 18 | ||||
| -rw-r--r-- | i18n/en.toml | 3 | ||||
| -rw-r--r-- | i18n/ru.toml | 3 | ||||
| -rw-r--r-- | layouts/partials/sidebar-toc.html | 18 | ||||
| -rw-r--r-- | layouts/shortcodes/toc.html | 4 |
8 files changed, 32 insertions, 37 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a1d15a..68e5c9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 documentation - Global `site.Params.keywords` may be overridden by `.Params.keywords` or `.Params.tags` in the post front matter +- Use builtin `.TableOfContents` to generate table of contents in the sidebar +- Change the way you enable table of contents in the sidebar. Now you can + enable/disable it in the front matter using `toc: true` or `toc: false` ### Fixed diff --git a/archetypes/default.md b/archetypes/default.md index 3612ee8..28e0450 100644 --- a/archetypes/default.md +++ b/archetypes/default.md @@ -10,6 +10,5 @@ editor: "" source: "" tags: - "" -toc: - - "" +toc: false --- diff --git a/exampleSite/content/documentation/index.md b/exampleSite/content/documentation/index.md index 6992c52..bb4c362 100644 --- a/exampleSite/content/documentation/index.md +++ b/exampleSite/content/documentation/index.md @@ -4,7 +4,6 @@ author: Alex Gil featured_image: screenshot-home.png --- -## Contents {{< toc >}} --- @@ -251,6 +250,8 @@ You will find three kinds of Tables of Content in Ed. The first example is in th </div> ~~~ +To override this list, create file `mini-toc.html` inside `layouts/partials` folder. + As you can see, the templating tags `{{ }}` are embedded into the HTML. These tags often use programmatic logic, as is the case here. However, another use of these tags is pull data from your project. In the example above it pulls the `Title` from each allowed post type. As you may have noticed already, we are basically adapting the blogging features of Hugo to our own ends, what Cuban designer and theorist Ernesto Oroza would call "[technological dissobedience](http://www.ernestooroza.com/)." @@ -258,24 +259,20 @@ As you may have noticed already, we are basically adapting the blogging features The second kind of table of content is exemplified in this documentation. If you open the source file for the documentation, you will notice at the top this snippet: ~~~ markdown -## Contents {{</* toc */>}} ~~~ This is the Hugo way. The shortcode, `{{</* toc */>}}` tells the processor to create a table of contents based on headers in the document. You can use this syntax in any page on the site that uses headers. -The third way is slightly more involved, but very useful for long texts. If we add the table of contents to the YAML front matter of a page, Ed will activate the optional table of content sidebar (`layouts/partials/sidebar-toc.html` in Ed) and move the table of contents to a special sidebar for that page. *Narrative of the Life* uses this method for its table of content. If you would like to replicate this functionality in your own long texts, make sure to use the same syntax: +The third way is simple as the previous one, but very useful for long texts. If we enable the table of contents in the YAML front matter of a page: ~~~ yaml -toc: -- Title Page -- Preface -- Letter From Wendell Phillips -- Chapter I -- Chapter II +toc: true ~~~ -The internal links pointing to the right sections in your document are generated from the title names automatically. In order for the links to work the names on section headings must contain the same words as the section headers. The punctuation and capitalization is irrelevant. If you can figure out how Ed accomplishes this trick, you have graduated from the Ed school of minimal editions. +Ed will activate the optional table of content sidebar (`layouts/partials/sidebar-toc.html` in Ed) and move the table of contents to a special sidebar for that page. *Narrative of the Life* uses this method for its table of content. + +The internal links pointing to the right sections in your document are generated from the title names automatically. If you can figure out how Ed accomplishes this trick, you have graduated from the Ed school of minimal editions. --- diff --git a/exampleSite/content/narratives/narrative.md b/exampleSite/content/narratives/narrative.md index c6d123e..a0fab24 100644 --- a/exampleSite/content/narratives/narrative.md +++ b/exampleSite/content/narratives/narrative.md @@ -6,23 +6,7 @@ author: Frederick Douglass editor: Alex Gil source: Project Guttenberg rights: Public Domain -toc: - - Title Page - - Preface - - Letter from Wendell Phillips, Esq. - - Chapter I - - Chapter II - - Chapter III - - Chapter IV - - Chapter V - - Chapter VI - - Chapter VII - - Chapter VIII - - Chapter IX - - Chapter X - - Chapter XI - - Appendix - - A Parody +toc: true --- --- diff --git a/i18n/en.toml b/i18n/en.toml index 0ee2188..4e776b7 100644 --- a/i18n/en.toml +++ b/i18n/en.toml @@ -48,3 +48,6 @@ [publications_tagged] other = 'Publications tagged "{{ . }}"' + +[table_of_contents] + other = 'Contents' diff --git a/i18n/ru.toml b/i18n/ru.toml index f3d13d4..4dcc4a5 100644 --- a/i18n/ru.toml +++ b/i18n/ru.toml @@ -48,3 +48,6 @@ [publications_tagged] other = 'Публикации с тегом "{{ . }}"' + +[table_of_contents] + other = 'Содержание' diff --git a/layouts/partials/sidebar-toc.html b/layouts/partials/sidebar-toc.html index 692643d..6306ec4 100644 --- a/layouts/partials/sidebar-toc.html +++ b/layouts/partials/sidebar-toc.html @@ -7,15 +7,17 @@ <p>{{ .Title }}</p> </div> - <nav class="sidebar-nav"> - <a class="sidebar-nav-item" href="{{ site.Home.RelPermalink }}">{{ i18n "home" }}</a> - <a class="sidebar-nav-item" href="#" data-proofer-ignore>{{ i18n "top" }}</a> + {{ $toc := .Page.TableOfContents }} + {{ $home := printf `<a class="sidebar-nav-item" href="%s">%s</a>` site.Home.RelPermalink (i18n "home") | safeHTML }} + {{ $top := printf `<a class="sidebar-nav-item" href="#" data-proofer-ignore>%s</a>` (i18n "top") | safeHTML }} - {{ range $item := .Params.toc }} - {{/* TODO: Add 'active' class for curent section */}} - <a class="sidebar-nav-item sidebar-nav-item-toc" href="#{{ . | anchorize }}">{{ . }}</a> - {{ end }} - </nav> + {{ $toc = $toc | replaceRE `id="TableOfContents"` `class="sidebar-nav"` | safeHTML }} + {{ $toc = $toc | replaceRE "(<[/]?ul>|<[/]?ol>|<[/]?li>)" "" | safeHTML }} + {{ $toc = $toc | replaceRE `<a href="(.*)">(.*)</a>` `<a class="sidebar-nav-item sidebar-nav-item-toc" href="$1">$2</a>` | safeHTML }} + {{ $toc = $toc | replaceRE `<nav class="sidebar-nav">` (printf `<nav class="sidebar-nav">%s` $top) | safeHTML }} + {{ $toc = $toc | replaceRE `<nav class="sidebar-nav">` (printf `<nav class="sidebar-nav">%s` $home) | safeHTML }} + + {{ $toc }} {{ partial "footer" . }} </aside> diff --git a/layouts/shortcodes/toc.html b/layouts/shortcodes/toc.html index ba789ee..cc23ebf 100644 --- a/layouts/shortcodes/toc.html +++ b/layouts/shortcodes/toc.html @@ -1 +1,5 @@ +<h2 class="no_toc" id="contents"> + {{ i18n "table_of_contents" }} +</h2> + {{ .Page.TableOfContents }} |
