mirror of https://github.com/istio/istio.io.git
Add support for skip_toc and skip_seealso front-matter values. (#1989)
This commit is contained in:
parent
75ab0f02e6
commit
5f2af0fd69
|
|
@ -100,7 +100,8 @@ The available front matter fields are:
|
||||||
|`publishdate` | For blog posts, indicates the date of publication of the post
|
|`publishdate` | For blog posts, indicates the date of publication of the post
|
||||||
|`subtitle` | For blog posts, supplies an optional subtitle to be displayed below the main title
|
|`subtitle` | For blog posts, supplies an optional subtitle to be displayed below the main title
|
||||||
|`attribution` | For blog posts, supplies an optional author's name
|
|`attribution` | For blog posts, supplies an optional author's name
|
||||||
|`toc` | Set this to false to prevent the page from having a table of contents generated for it
|
|`skip_toc` | Set this to true to prevent the page from having a table of contents generated for it
|
||||||
|
|`skip_seealso` | Set this to true to prevent the page from having a "See also" section generated for it
|
||||||
|`force_inline_toc` | Set this to true to force the generated table of contents from being inserted inline in the text instead of in a sidebar
|
|`force_inline_toc` | Set this to true to force the generated table of contents from being inserted inline in the text instead of in a sidebar
|
||||||
|
|
||||||
## Adding images
|
## Adding images
|
||||||
|
|
|
||||||
|
|
@ -11,47 +11,53 @@
|
||||||
{{ $page.Scratch.Set "seeAlso" false }}
|
{{ $page.Scratch.Set "seeAlso" false }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{ $headers := findRE "<h[23456].*?id=\".*?\".*?>.*?</h[23456]>" $page.Content }}
|
{{ if $page.Params.skip_seealso }}
|
||||||
{{ $len := len $headers }}
|
{{ $page.Scratch.Set "seeAlso" false }}
|
||||||
|
{{ end }}
|
||||||
{{ if or (gt $len 0) ($page.Scratch.Get "seeAlso") }}
|
|
||||||
{{ $page.Scratch.Set "needTOC" true }}
|
{{ if not $page.Params.skip_toc }}
|
||||||
<nav id="TableOfContents">
|
{{ $headers := findRE "<h[23456].*?id=\".*?\".*?>.*?</h[23456]>" $page.Content }}
|
||||||
<ul>
|
{{ $len := len $headers }}
|
||||||
{{ $page.Scratch.Set "level" 50 }}
|
|
||||||
{{ range $h := $headers }}
|
{{ if or (gt $len 0) ($page.Scratch.Get "seeAlso") }}
|
||||||
{{ $level := index (index (findRE "<h[23456].*?" $h) 0) 2 | int }}
|
{{ $page.Scratch.Set "needTOC" true }}
|
||||||
{{ $id := replaceRE "<h[23456].*?id=\"(.*?)\".*?>.*?</h[23456]>" "$1" $h }}
|
<nav id="TableOfContents">
|
||||||
{{ $title := replaceRE "<h[23456].*?>(.*?)</h[23456]>" "$1" $h }}
|
<ul>
|
||||||
{{ $current := $page.Scratch.Get "level" | int }}
|
{{ $page.Scratch.Set "level" 50 }}
|
||||||
|
{{ range $h := $headers }}
|
||||||
{{ if gt $level $current }}
|
{{ $level := index (index (findRE "<h[23456].*?" $h) 0) 2 | int }}
|
||||||
{{ $delta := sub $level $current }}
|
{{ $id := replaceRE "<h[23456].*?id=\"(.*?)\".*?>.*?</h[23456]>" "$1" $h }}
|
||||||
{{ range $index, $num := (seq $delta) }}
|
{{ $title := replaceRE "<h[23456].*?>(.*?)</h[23456]>" "$1" $h }}
|
||||||
<ul>
|
{{ $current := $page.Scratch.Get "level" | int }}
|
||||||
{{ end }}
|
|
||||||
{{ else if lt $level $current }}
|
{{ if gt $level $current }}
|
||||||
{{ $delta := sub $current $level }}
|
{{ $delta := sub $level $current }}
|
||||||
{{ range $index, $num := (seq $delta) }}
|
{{ range $index, $num := (seq $delta) }}
|
||||||
</ul>
|
<ul>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ end }}
|
{{ else if lt $level $current }}
|
||||||
|
{{ $delta := sub $current $level }}
|
||||||
<li><a href="#{{ $id }}">{{ $title | safeHTML }}</a></li>
|
{{ range $index, $num := (seq $delta) }}
|
||||||
|
</ul>
|
||||||
{{ $page.Scratch.Set "level" $level }}
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{ $delta := sub ($page.Scratch.Get "level") 50 }}
|
<li><a href="#{{ $id }}">{{ $title | safeHTML }}</a></li>
|
||||||
{{ range $index, $num := (seq $delta) }}
|
|
||||||
</ul>
|
{{ $page.Scratch.Set "level" $level }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{ if $page.Scratch.Get "seeAlso" }}
|
{{ $delta := sub ($page.Scratch.Get "level") 50 }}
|
||||||
{{ with $related }}
|
{{ range $index, $num := (seq $delta) }}
|
||||||
<li><a href="#see-also">See also</a></li>
|
</ul>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ end }}
|
|
||||||
</ul>
|
{{ if $page.Scratch.Get "seeAlso" }}
|
||||||
</nav>
|
{{ with $related }}
|
||||||
|
<li><a href="#see-also">See also</a></li>
|
||||||
|
{{ end }}
|
||||||
|
{{ end }}
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue