Add before and after partials for toc (#296)

Closes #257
This commit is contained in:
Tiger Oakes 2021-01-26 09:45:08 -08:00 committed by GitHub
parent a12baf0e01
commit 012ccee53d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 25 additions and 19 deletions

View File

@ -69,12 +69,12 @@ hugo server --minify --theme book
### File tree menu (default) ### File tree menu (default)
By default, the theme will render pages from the `content/docs` section as a menu in a tree structure. By default, the theme will render pages from the `content/docs` section as a menu in a tree structure.
You can set `title` and `weight` in the front matter of pages to adjust the order and titles in the menu. You can set `title` and `weight` in the front matter of pages to adjust the order and titles in the menu.
### Leaf bundle menu ### Leaf bundle menu
You can also use leaf bundle and the content of its `index.md` file as menu. You can also use leaf bundle and the content of its `index.md` file as menu.
Given you have the following file structure: Given you have the following file structure:
``` ```
@ -108,14 +108,14 @@ And Enable it by setting `BookMenuBundle: /menu` in Site configuration.
## Blog ## Blog
A simple blog is supported in the section `posts`. A simple blog is supported in the section `posts`.
A blog is not the primary usecase of this theme, so it has only minimal features. A blog is not the primary usecase of this theme, so it has only minimal features.
## Configuration ## Configuration
### Site Configuration ### Site Configuration
There are a few configuration options that you can add to your `config.toml` file. There are a few configuration options that you can add to your `config.toml` file.
You can also see the `yaml` example [here](https://github.com/alex-shpak/hugo-book/blob/master/exampleSite/config.yaml). You can also see the `yaml` example [here](https://github.com/alex-shpak/hugo-book/blob/master/exampleSite/config.yaml).
```toml ```toml
@ -234,15 +234,17 @@ bookSearchExclude = true
There are few empty partials you can override in `layouts/partials/` There are few empty partials you can override in `layouts/partials/`
| Partial | Placement | | Partial | Placement |
| -------------------------------------------------- | -------------------------------------- | | -------------------------------------------------- | ------------------------------------------- |
| `layouts/partials/docs/inject/head.html` | Before closing `<head>` tag | | `layouts/partials/docs/inject/head.html` | Before closing `<head>` tag |
| `layouts/partials/docs/inject/body.html` | Before closing `<body>` tag | | `layouts/partials/docs/inject/body.html` | Before closing `<body>` tag |
| `layouts/partials/docs/inject/footer.html` | After page footer content | | `layouts/partials/docs/inject/footer.html` | After page footer content |
| `layouts/partials/docs/inject/menu-before.html` | At the beginning of `<nav>` menu block | | `layouts/partials/docs/inject/menu-before.html` | At the beginning of `<nav>` menu block |
| `layouts/partials/docs/inject/menu-after.html` | At the end of `<nav>` menu block | | `layouts/partials/docs/inject/menu-after.html` | At the end of `<nav>` menu block |
| `layouts/partials/docs/inject/content-before.html` | Before page content | | `layouts/partials/docs/inject/content-before.html` | Before page content |
| `layouts/partials/docs/inject/content-after.html` | After page content | | `layouts/partials/docs/inject/content-after.html` | After page content |
| `layouts/partials/docs/inject/toc-before.html` | At the beginning of table of contents block |
| `layouts/partials/docs/inject/toc-after.html` | At the end of table of contents block |
### Extra Customisation ### Extra Customisation
@ -300,7 +302,7 @@ If you want lower maintenance, use one of the released versions. If you want to
### [Extra credits to contributors](https://github.com/alex-shpak/hugo-book/graphs/contributors) ### [Extra credits to contributors](https://github.com/alex-shpak/hugo-book/graphs/contributors)
Contributions are welcome and I will review and consider pull requests. Contributions are welcome and I will review and consider pull requests.
Primary goals are: Primary goals are:
- Keep it simple. - Keep it simple.

View File

@ -209,7 +209,7 @@ ul.pagination {
flex: 0 0 $toc-width; flex: 0 0 $toc-width;
font-size: $font-size-12; font-size: $font-size-12;
nav { > nav {
width: $toc-width; width: $toc-width;
padding: $padding-16; padding: $padding-16;
@ -377,7 +377,7 @@ aside nav,
@media screen and (min-width: $container-max-width) { @media screen and (min-width: $container-max-width) {
.book-page, .book-page,
.book-menu nav, .book-menu nav,
.book-toc nav { .book-toc > nav {
padding: $padding-16 * 2 $padding-16; padding: $padding-16 * 2 $padding-16;
} }
} }

View File

@ -1 +1 @@
{"Target":"book.min.134b70e5316650a530cb42e4e8630b2a01d532bebfc0337028211175336e4806.css","MediaType":"text/css","Data":{"Integrity":"sha256-E0tw5TFmUKUwy0Lk6GMLKgHVMr6/wDNwKCERdTNuSAY="}} {"Target":"book.min.5284606b3d4d63899357ff95f4032c205e62b86963d9241c255c46093296e5a0.css","MediaType":"text/css","Data":{"Integrity":"sha256-UoRgaz1NY4mTV/+V9AMsIF5iuGlj2SQcJVxGCTKW5aA="}}

View File

@ -36,7 +36,11 @@
{{ if default true (default .Site.Params.BookToC .Params.BookToC) }} {{ if default true (default .Site.Params.BookToC .Params.BookToC) }}
<aside class="book-toc"> <aside class="book-toc">
{{ template "toc" . }} <!-- Table of Contents --> <nav>
{{ partial "docs/inject/toc-before" . }}
{{ template "toc" . }} <!-- Table of Contents -->
{{ partial "docs/inject/toc-after" . }}
</nav>
</aside> </aside>
{{ end }} {{ end }}
</main> </main>