From 79981e41bef2b21a58332168f027e53e6bb5865f Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 6 Dec 2021 12:36:20 -0700 Subject: [PATCH 1/3] typo in changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 18866d2..31e4015 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 12/03/2021 1. [](#new) - * **NEW** Support built-in `anchors`'` with customization of icon/classes/css etc. + * **NEW** Support built-in `anchors` with customization of icon/classes/css etc. * **NEW** `[anchor]` shortcode for creating manual anchors for easy linking to page content * Moved the vendor-based TOC functionality in-plugin to provide more flexibility and additional features * Added several more Twig functions for increased flexibility From 58dca5960dee9d0ec655ad137b665ddcd5e3e026 Mon Sep 17 00:00:00 2001 From: Djamil Legato Date: Mon, 6 Dec 2021 12:29:30 -0800 Subject: [PATCH 2/3] Added option to automatically copying to clipboard an anchor URL when clicking on it --- CHANGELOG.md | 6 ++++++ assets/page-toc-anchors.js | 10 ++++++++++ blueprints.yaml | 13 ++++++++++++- languages.yaml | 2 ++ page-toc.php | 3 +++ page-toc.yaml | 2 +- 6 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 assets/page-toc-anchors.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 31e4015..7e03d06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# v3.0.1 +## 12/06/2021 + +1. [](#new) + * **NEW** Added option to automatically copying to clipboard an anchor URL when clicking on it + # v3.0.0 ## 12/03/2021 diff --git a/assets/page-toc-anchors.js b/assets/page-toc-anchors.js new file mode 100644 index 0000000..ec5c459 --- /dev/null +++ b/assets/page-toc-anchors.js @@ -0,0 +1,10 @@ +document.body.addEventListener('click', (event) => { + if (typeof event.target.dataset.anchorIcon !== 'undefined') { + const href = event.target.href; + navigator.clipboard.writeText(href) + .then(() => {}) + .catch((error) => { + console.error('Unable to copy to clipboard the anchor', error); + }); + } +}, true); \ No newline at end of file diff --git a/blueprints.yaml b/blueprints.yaml index ba2e5af..f742a3f 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -1,7 +1,7 @@ name: Page Toc type: plugin slug: page-toc -version: 3.0.0 +version: 3.0.1 description: Generate a table of contents and anchors from a page icon: list author: @@ -143,6 +143,17 @@ form: options: before: PLUGIN_PAGE_TOC.BEFORE_TEXT after: PLUGIN_PAGE_TOC.AFTER_TEXT + anchors.copy_to_clipboard: + type: toggle + label: PLUGIN_PAGE_TOC.COPY_TO_CLIPBOARD + help: PLUGIN_PAGE_TOC.COPY_TO_CLIPBOARD_HELP + highlight: 1 + default: 1 + options: + 1: Enabled + 0: Disabled + validate: + type: bool anchors.slug_maxlen: type: number label: PLUGIN_PAGE_TOC.SLUG_MAXLEN diff --git a/languages.yaml b/languages.yaml index e36125d..60b8a85 100644 --- a/languages.yaml +++ b/languages.yaml @@ -23,6 +23,8 @@ en: ANCHORS_ICON_HELP: 'Can be any text character, symbol, unicode character or even emjoi. leave blank if you intend to style with CSS.' ANCHORS_POSITION: 'Anchor Position' ANCHORS_POSITION_HELP: 'Position to put the anchor, `before|after`' + ANCHORS_COPY_TO_CLIPBOARD: 'Copy to Clipboard' + ANCHORS_COPY_TO_CLIPBOARD_HELP: 'When clicking an anchor, it will also copy to clipboard the full URL. Convenient for sharing/opening in new tab' BEFORE_TEXT: 'Before text' AFTER_TEXT: 'After text' SLUG_MAXLEN: 'Slug max-length' diff --git a/page-toc.php b/page-toc.php index 74c2d1b..a59498f 100644 --- a/page-toc.php +++ b/page-toc.php @@ -116,6 +116,9 @@ public function onTwigSiteVariables() if ($this->grav['config']->get('plugins.page-toc.include_css')) { $this->grav['assets']->addCss('plugin://page-toc/assets/page-toc-anchors.css'); } + if ($this->grav['config']->get('plugins.page-toc.anchors.copy_to_clipboard')) { + $this->grav['assets']->addJs('plugin://page-toc/assets/page-toc-anchors.js', ['group' => 'bottom', 'defer' => 'defer']); + } } public function registerTwigFunctions() diff --git a/page-toc.yaml b/page-toc.yaml index ad9ed0b..da89e23 100644 --- a/page-toc.yaml +++ b/page-toc.yaml @@ -12,6 +12,6 @@ anchors: # Anchor configuration class: # Custom Header anchor styling classes icon: '#' # Icon to use, can be a symbol, emoji, ascii etc. position: after # Position to put the anchor, `before|after` - copy_to_clipboard: true # Copy to clipboard functionality (coming soon) + copy_to_clipboard: false # Copy to clipboard functionality slug_maxlen: 25 # Max length of slugs used for anchors slug_prefix: # A prefix used in front of generated slugs From 14855862dd12b9e0d52212bbb7b679cf328caaa6 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Thu, 9 Dec 2021 14:14:48 -0700 Subject: [PATCH 3/3] prepare for release --- CHANGELOG.md | 4 ++-- blueprints.yaml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e03d06..0bd7de7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ -# v3.0.1 -## 12/06/2021 +# v3.1.0 +## 12/09/2021 1. [](#new) * **NEW** Added option to automatically copying to clipboard an anchor URL when clicking on it diff --git a/blueprints.yaml b/blueprints.yaml index f742a3f..e43536d 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -1,7 +1,7 @@ name: Page Toc type: plugin slug: page-toc -version: 3.0.1 +version: 3.1.0 description: Generate a table of contents and anchors from a page icon: list author: