add anchor links for headlines

This commit is contained in:
Robert Kaussow 2020-02-26 23:59:30 +01:00
parent 8e3958bd09
commit 14567a6df4
9 changed files with 31 additions and 7 deletions

View file

@ -2,6 +2,6 @@
{{ partial "page-header" . }}
<article class="gdoc-markdown">
<h1>{{ partial "title" . }}</h1>
{{ .Content }}
{{ partial "content" . }}
</article>
{{ end }}

View file

@ -3,6 +3,6 @@
<article class="gdoc-markdown">
<h1>{{ partial "title" . }}</h1>
{{ .Content | replaceRE `<nav id="TableOfContents">\s*<ul>\s*<li>\s*<ul>` `<nav id="TableOfContents"><ul>` | replaceRE `</ul>\s*</li>\s*</ul>\s*</nav>` `</ul></nav>` | safeHTML }}
{{ partial "content" . }}
</article>
{{ end }}

View file

@ -0,0 +1,8 @@
{{ $showAnchor := (and (default true .Page.Params.geekdocAnchor) (default true .Site.Params.geekdocAnchor)) }}
{{ $.Scratch.Set "content" (.Content | replaceRE `<nav id="TableOfContents">\s*<ul>\s*<li>\s*<ul>` `<nav id="TableOfContents"><ul>` | replaceRE `</ul>\s*</li>\s*</ul>\s*</nav>` `</ul></nav>` | safeHTML) }}
{{ if $showAnchor }}
{{ $.Scratch.Set "content" ($.Scratch.Get "content" | replaceRE "(<h[2-9] id=\"([^\"]+)\".+)(</h[2-9]+>)" `${1}&nbsp;<a class="gdoc-page__anchor" href="#${2}"><svg class="icon link"><use xlink:href="#link"></use></svg></a> ${3}</h>` | safeHTML) }}
{{ end }}
{{ $.Scratch.Get "content" }}

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 7.5 KiB

After

Width:  |  Height:  |  Size: 8 KiB

Before After
Before After

View file

@ -5,6 +5,6 @@
<h5>
<strong>{{ .Date.Format $dateFormat }}</strong>
</h5>
{{ .Content }}
{{ partial "content" . }}
</article>
{{ end }}