Improve page title handling and side menu templates

This commit is contained in:
Alex Shpak 2018-09-17 18:29:36 +02:00
parent 0dec1cd3a8
commit 561659ed53
6 changed files with 50 additions and 40 deletions

View file

@ -97,12 +97,12 @@ bookShowToC: false
### Partials ### Partials
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/nav-before.html` | Before `<nav>` menu block | | `layouts/partials/docs/inject/nav-before.html` | At the beginning of `<nav>` menu block |
| `layouts/partials/docs/inject/nav-after.html` | After `<nav>` menu block | | `layouts/partials/docs/inject/nav-after.html` | At the end of `<nav>` menu block |
## Contributing ## Contributing

View file

@ -28,7 +28,6 @@ a {
font-weight: 400; font-weight: 400;
a { a {
padding: 0 $padding-16;
color: $body-font-color; color: $body-font-color;
} }
} }
@ -52,12 +51,16 @@ a {
ul { ul {
list-style: none; list-style: none;
margin: 0;
padding-left: $padding-16; padding-left: $padding-16;
li {
line-height: $padding-16 * 2;
}
a { a {
display: block; display: block;
color: $nav-link-color; color: $nav-link-color;
padding: $padding-4 $padding-16;
text-transform: capitalize; text-transform: capitalize;
&[href]:hover { &[href]:hover {

View file

@ -1,9 +1,9 @@
<!DOCTYPE html> <!DOCTYPE html>
<!-- {{ partial "docs/shared" }} -->
<html> <html>
<head> <head>
{{ partial "docs/html-head" . }} {{ partial "docs/html-head" . }}
{{ partial "docs/inject/head" . }} {{ partial "docs/inject/head" . }}
<title>{{ block "title" . }} {{- .Site.Title -}} {{ end }}</title>
</head> </head>
<body> <body>
@ -27,7 +27,7 @@
<div class="pure-g"> <div class="pure-g">
<div class="pure-u book-page markdown"> <div class="pure-u book-page markdown">
{{ block "main" . }} {{- .Content -}} {{ end }} {{- .Content -}}
</div> </div>
{{ $showToC := default (default true .Site.Params.BookShowToC) .Params.bookshowtoc }} {{ $showToC := default (default true .Site.Params.BookShowToC) .Params.bookshowtoc }}
{{ if and ($showToC) (.Page.TableOfContents) }} {{ if and ($showToC) (.Page.TableOfContents) }}

View file

@ -1,5 +1,6 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{- template "title" . }} | {{ .Site.Title -}}</title>
<link href="https://fonts.googleapis.com/css?family=Roboto+Mono|Roboto:300,400,700" rel="stylesheet"> <link href="https://fonts.googleapis.com/css?family=Roboto+Mono|Roboto:300,400,700" rel="stylesheet">
<link href="/css/pure-min.css" rel="stylesheet"> <link href="/css/pure-min.css" rel="stylesheet">

View file

@ -1,15 +1,5 @@
{{ $bookSection := default "docs" .Site.Params.BookSection }} <!-- Put configured sections list to .Scratch -->
{{ if eq $bookSection "*" }} {{ template "book-get-root-section" . }}
{{ .Scratch.Set "BookSections" .Site.Sections }}
{{ else }}
{{ $bookSections := where .Site.Sections "Section" $bookSection }}
{{ .Scratch.Set "BookSections" $bookSections }}
{{ if eq (len $bookSections) 1 }}
{{ $singleSection := index $bookSections 0 }}
{{ .Scratch.Set "BookSections" $singleSection.Sections }}
{{ end }}
{{ end }}
<ul> <ul>
{{ range .Scratch.Get "BookSections" }} {{ range .Scratch.Get "BookSections" }}
@ -20,7 +10,15 @@
<!-- Single section of menu (recursive) --> <!-- Single section of menu (recursive) -->
{{ define "book-section" }} {{ define "book-section" }}
<li {{ if .Section.Params.booktopsection }}class="book-nav-section"{{ end }}> <li {{ if .Section.Params.booktopsection }}class="book-nav-section"{{ end }}>
{{ template "book-heading" .Section }}
{{ with .Section}}
{{- if .Content -}}
<a href="{{ .RelPermalink }}">{{- template "title" . -}}</a>
{{- else -}}
{{- template "title" . -}}
{{- end -}}
{{ end }}
<ul> <ul>
{{ range .Section.Sections }} {{ range .Section.Sections }}
{{ template "book-section" (dict "Section" . "CurrentPage" $.CurrentPage) }} {{ template "book-section" (dict "Section" . "CurrentPage" $.CurrentPage) }}
@ -28,7 +26,7 @@
{{ range .Section.Pages }} {{ range .Section.Pages }}
<li> <li>
<a href="{{ .RelPermalink }}" class="{{ if eq $.CurrentPage .Permalink }}active{{ end }}"> <a href="{{ .RelPermalink }}" class="{{ if eq $.CurrentPage .Permalink }}active{{ end }}">
{{ default .Title (.File | humanize | title) }} {{- template "title" . -}}
</a> </a>
</li> </li>
{{ end }} {{ end }}
@ -36,21 +34,18 @@
</li> </li>
{{ end }} {{ end }}
<!-- Menu Heading --> {{ define "book-get-root-section" }}
{{ define "book-heading" }} <!-- Complex logic to guess page title without .Title specified -->
{{ $bookSection := default "docs" .Site.Params.BookSection }}
{{ $sections := split (trim .Dir "/") "/" }} {{ if eq $bookSection "*" }}
{{ $title := index ($sections | last 1) 0 | humanize | title }} {{ .Scratch.Set "BookSections" .Site.Sections }}
{{ $title := default .Title $title }}
{{ if .Content }}
<a href="{{ .RelPermalink }}">
{{- $title -}}
</a>
{{ else }} {{ else }}
<a> {{ $bookSections := where .Site.Sections "Section" $bookSection }}
{{- $title -}} {{ .Scratch.Set "BookSections" $bookSections }}
</a>
{{ end }}
{{ if eq (len $bookSections) 1 }}
{{ $singleSection := index $bookSections 0 }}
{{ .Scratch.Set "BookSections" $singleSection.Sections }}
{{ end }}
{{ end }}
{{ end }} {{ end }}

View file

@ -0,0 +1,11 @@
<!-- These templates contains some more complex logic and shared between partials-->
{{ define "title" }}
{{- if .Pages -}}
{{ $sections := split (trim .Dir "/") "/" }}
{{ $title := index ($sections | last 1) 0 | humanize | title }}
{{- default .Title $title -}}
{{- else -}}
{{ $title := .File | humanize | title }}
{{- default .Title $title -}}
{{- end -}}
{{ end }}