add anchor links for headlines
This commit is contained in:
parent
8e3958bd09
commit
14567a6df4
9 changed files with 31 additions and 7 deletions
|
@ -2,6 +2,6 @@
|
|||
{{ partial "page-header" . }}
|
||||
<article class="gdoc-markdown">
|
||||
<h1>{{ partial "title" . }}</h1>
|
||||
{{ .Content }}
|
||||
{{ partial "content" . }}
|
||||
</article>
|
||||
{{ end }}
|
||||
|
|
|
@ -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 }}
|
||||
|
|
8
layouts/partials/content.html
Normal file
8
layouts/partials/content.html
Normal 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} <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 |
|
@ -5,6 +5,6 @@
|
|||
<h5>
|
||||
<strong>{{ .Date.Format $dateFormat }}</strong>
|
||||
</h5>
|
||||
{{ .Content }}
|
||||
{{ partial "content" . }}
|
||||
</article>
|
||||
{{ end }}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue