diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e7c4c96..8b6efad0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/exampleSite/content/usage/configuration.md b/exampleSite/content/usage/configuration.md index 87cbc283..edd0fa55 100644 --- a/exampleSite/content/usage/configuration.md +++ b/exampleSite/content/usage/configuration.md @@ -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 >}} diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index caa456d6..cecbbdb1 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -27,4 +27,5 @@ +{{ partial "foot" . }} diff --git a/layouts/partials/content.html b/layouts/partials/content.html index 1ca0cb31..73bc6fbe 100644 --- a/layouts/partials/content.html +++ b/layouts/partials/content.html @@ -3,9 +3,9 @@ {{ $.Scratch.Set "content" (.Content | replaceRE `` `` | safeHTML) }} {{ if and $showAnchor $anchorLeft }} - {{ $.Scratch.Set "content" ($.Scratch.Get "content" | replaceRE "(]*>)(.*?)()" `${1}${3}${4}` | safeHTML) }} + {{ $.Scratch.Set "content" ($.Scratch.Get "content" | replaceRE "(]*>)(.*?)()" (printf `%s%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 "(]*>)(.*?)()" `${1}${3}${4}` | safeHTML) }} + {{ $.Scratch.Set "content" ($.Scratch.Get "content" | replaceRE "(]*>)(.*?)()" (printf `%s%s%s` `${1}` `${3}` (absURL (printf "%s#%s" .Permalink `${2}`)) `${2}` `${4}`) | safeHTML) }} {{ end }} {{ $.Scratch.Get "content" }} diff --git a/layouts/partials/foot.html b/layouts/partials/foot.html new file mode 100644 index 00000000..cc5506bc --- /dev/null +++ b/layouts/partials/foot.html @@ -0,0 +1,14 @@ +{{ if default true .Site.Params.GeekdocSearch }} +{{ .Scratch.Set "geekdocSearchConfig" .Site.Params.GeekdocSearchConfig }} + +{{ $searchJSFile := printf "js/%s.search.js" .Language.Lang }} +{{ $searchJS := resources.Get "js/search.js" | resources.ExecuteAsTemplate $searchJSFile . | resources.Minify }} + +{{ end }} + +{{ if default true .Site.Params.GeekdocAnchorCopy }} + + +{{ end }} diff --git a/layouts/partials/head.html b/layouts/partials/head.html index 43b8e3fc..2d10cde3 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -9,14 +9,6 @@ -{{ if default true .Site.Params.GeekdocSearch }} - {{ .Scratch.Set "geekdocSearchConfig" .Site.Params.GeekdocSearchConfig }} - - {{ $searchJSFile := printf "js/%s.search.js" .Language.Lang }} - {{ $searchJS := resources.Get "js/search.js" | resources.ExecuteAsTemplate $searchJSFile . | resources.Minify }} - -{{ end }} - {{ with .OutputFormats.Get "rss" -}} {{ printf `` .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }} diff --git a/static/js/clipboard.min.js b/static/js/clipboard.min.js new file mode 100644 index 00000000..02c549e3 --- /dev/null +++ b/static/js/clipboard.min.js @@ -0,0 +1,7 @@ +/*! + * clipboard.js v2.0.4 + * https://zenorocha.github.io/clipboard.js + * + * Licensed MIT © Zeno Rocha + */ +!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.ClipboardJS=e():t.ClipboardJS=e()}(this,function(){return function(n){var o={};function r(t){if(o[t])return o[t].exports;var e=o[t]={i:t,l:!1,exports:{}};return n[t].call(e.exports,e,e.exports,r),e.l=!0,e.exports}return r.m=n,r.c=o,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,n){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},i=function(){function o(t,e){for(var n=0;n