Skip to content

Commit

Permalink
Merge branch 'release/3.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Dec 9, 2021
2 parents beecae2 + 1485586 commit 727d1c1
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 3 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# v3.1.0
## 12/09/2021

1. [](#new)
* **NEW** Added option to automatically copying to clipboard an anchor URL when clicking on it

# v3.0.0
## 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
Expand Down
10 changes: 10 additions & 0 deletions assets/page-toc-anchors.js
Original file line number Diff line number Diff line change
@@ -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);
13 changes: 12 additions & 1 deletion blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Page Toc
type: plugin
slug: page-toc
version: 3.0.0
version: 3.1.0
description: Generate a table of contents and anchors from a page
icon: list
author:
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions languages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 3 additions & 0 deletions page-toc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion page-toc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 727d1c1

Please sign in to comment.