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

Add anchor copy
This commit is contained in:
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 * FEATURE
* Add option to move anchor links to the left site of headlines * 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. # (Optional, default false) Move anchor link to the left side of headlines.
geekdocAnchorLeft = false geekdocAnchorLeft = false
# (Optional, default true) Copy anchor url to clipboard on click.
geekdocAnchorCopy = true
``` ```
{{< /tab >}} {{< /tab >}}
@ -113,6 +116,9 @@ params:
# (Optional, default false) Move anchor link to the left side of headlines. # (Optional, default false) Move anchor link to the left side of headlines.
geekdocAnchorLeft: false geekdocAnchorLeft: false
# (Optional, default true) Copy anchor url to clipboard on click.
geekdocAnchorCopy: true
``` ```
{{< /tab >}} {{< /tab >}}

View file

@ -27,4 +27,5 @@
</div> </div>
</body> </body>
{{ partial "foot" . }}
</html> </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) }} {{ $.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 }} {{ 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) }} {{ 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 }} {{ end }}
{{ $.Scratch.Get "content" }} {{ $.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 --> <!-- Theme stylesheet, you can customize css by creating static/custom.css` in your website -->
<link rel="stylesheet" href="{{ "custom.css" | relURL }}"> <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 --> <!-- RSS -->
{{ with .OutputFormats.Get "rss" -}} {{ with .OutputFormats.Get "rss" -}}
{{ printf `<link rel="%s" type="%s" href="%s" title="%s" />` .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }} {{ 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