Merge pull request #3 from xoxys/add-anchor-copy

Add anchor copy
uci-hugo-doc
Robert Kaussow 2020-02-27 13:45:35 +01:00 committed by GitHub
commit e081e04981
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 31 additions and 10 deletions

View File

@ -1,2 +1,3 @@
* FEATURE
* Add option to move anchor links to the left site of headlines
* add optional clipboard.js to copy anchor links on click

View File

@ -55,6 +55,9 @@
# (Optional, default false) Move anchor link to the left side of headlines.
geekdocAnchorLeft = false
# (Optional, default true) Copy anchor url to clipboard on click.
geekdocAnchorCopy = true
```
{{< /tab >}}
@ -113,6 +116,9 @@ params:
# (Optional, default false) Move anchor link to the left side of headlines.
geekdocAnchorLeft: false
# (Optional, default true) Copy anchor url to clipboard on click.
geekdocAnchorCopy: true
```
{{< /tab >}}

View File

@ -27,4 +27,5 @@
</div>
</body>
{{ partial "foot" . }}
</html>

View File

@ -3,9 +3,9 @@
{{ $.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 and $showAnchor $anchorLeft }}
{{ $.Scratch.Set "content" ($.Scratch.Get "content" | replaceRE "(<h[2-9] id=\"([^\"]+)\"[^>]*>)(.*?)(</h[2-9]+>)" `${1}<a class="gdoc-page__anchor gdoc-page__anchor--left" href="#${2}"><svg class="icon link"><use xlink:href="#link"></use></svg></a>${3}${4}` | safeHTML) }}
{{ $.Scratch.Set "content" ($.Scratch.Get "content" | replaceRE "(<h[2-9] id=\"([^\"]+)\"[^>]*>)(.*?)(</h[2-9]+>)" (printf `%s<a data-clipboard-text="%s" class="gdoc-page__anchor gdoc-page__anchor--left clip" href="#%s"><svg class="icon link"><use xlink:href="#link"></use></svg></a>%s%s` `${1}` (absURL (printf "%s#%s" .Permalink `${2}`)) `${2}` `${3}` `${4}`) | safeHTML) }}
{{ else if and $showAnchor (not $anchorLeft) }}
{{ $.Scratch.Set "content" ($.Scratch.Get "content" | replaceRE "(<h[2-9] id=\"([^\"]+)\"[^>]*>)(.*?)(</h[2-9]+>)" `${1}${3}<a class="gdoc-page__anchor gdoc-page__anchor--right" href="#${2}"><svg class="icon link"><use xlink:href="#link"></use></svg></a>${4}` | safeHTML) }}
{{ $.Scratch.Set "content" ($.Scratch.Get "content" | replaceRE "(<h[2-9] id=\"([^\"]+)\"[^>]*>)(.*?)(</h[2-9]+>)" (printf `%s%s<a data-clipboard-text="%s" class="gdoc-page__anchor gdoc-page__anchor--right clip" href="#%s"><svg class="icon link"><use xlink:href="#link"></use></svg></a>%s` `${1}` `${3}` (absURL (printf "%s#%s" .Permalink `${2}`)) `${2}` `${4}`) | safeHTML) }}
{{ end }}
{{ $.Scratch.Get "content" }}

View File

@ -0,0 +1,14 @@
{{ if default true .Site.Params.GeekdocSearch }}
{{ .Scratch.Set "geekdocSearchConfig" .Site.Params.GeekdocSearchConfig }}
<!-- Remove after https://github.com/gohugoio/hugo/issues/6331 -->
{{ $searchJSFile := printf "js/%s.search.js" .Language.Lang }}
{{ $searchJS := resources.Get "js/search.js" | resources.ExecuteAsTemplate $searchJSFile . | resources.Minify }}
<script defer src="{{ $searchJS.RelPermalink }}"></script>
{{ end }}
{{ if default true .Site.Params.GeekdocAnchorCopy }}
<script src="{{ "js/clipboard.min.js" | relURL }}"></script>
<script>
var clipboard = new ClipboardJS('.clip');
</script>
{{ end }}

View File

@ -9,14 +9,6 @@
<!-- Theme stylesheet, you can customize css by creating static/custom.css` in your website -->
<link rel="stylesheet" href="{{ "custom.css" | relURL }}">
{{ if default true .Site.Params.GeekdocSearch }}
{{ .Scratch.Set "geekdocSearchConfig" .Site.Params.GeekdocSearchConfig }}
<!-- Remove after https://github.com/gohugoio/hugo/issues/6331 -->
{{ $searchJSFile := printf "js/%s.search.js" .Language.Lang }}
{{ $searchJS := resources.Get "js/search.js" | resources.ExecuteAsTemplate $searchJSFile . | resources.Minify }}
<script defer src="{{ $searchJS.RelPermalink }}"></script>
{{ end }}
<!-- RSS -->
{{ with .OutputFormats.Get "rss" -}}
{{ printf `<link rel="%s" type="%s" href="%s" title="%s" />` .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }}

7
static/js/clipboard.min.js vendored Normal file

File diff suppressed because one or more lines are too long