jekyll-external-link-accessibility 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +17 -0
- data/LICENSE.txt +21 -0
- data/README.md +70 -0
- data/lib/jekyll-external-link-accessibility/hooks.rb +13 -0
- data/lib/jekyll-external-link-accessibility/version.rb +7 -0
- data/lib/jekyll-external-link-accessibility.rb +79 -0
- metadata +92 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 849fc21433dad344657c4a178cdde53743b725dc9c469c8de7cab31b17f9109c
|
|
4
|
+
data.tar.gz: afab990efcde48e427a61e210ac525181dfe97cee3c994a1e4e06de4585f7747
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: d1d54d9b739f5e0e9bc702142c191287001e4e391a01b866697358a629c6cd04c319ee6c44a0c12b060ef1fd786849b87886acb63560614219525228d0b8cd2c
|
|
7
|
+
data.tar.gz: c5023bb2b680dc49821a78c235e99e7a114db56e55e4dbc785f5fba28b3d1829d49f41e504b5d37934f1b224c1bb83ca8987c5a85d2a07c3dda4dd3de372b518
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# main [(unreleased)](https://github.com/fastruby/jekyll-external-link-accessibility/compare/v0.2.0...main)
|
|
2
|
+
|
|
3
|
+
- Your changes/patches go here.
|
|
4
|
+
|
|
5
|
+
# v0.2.0 / 2026-07-15 [(commits)](https://github.com/fastruby/jekyll-external-link-accessibility/compare/v0.1.0...v0.2.0)
|
|
6
|
+
|
|
7
|
+
- [FEATURE: Detect external links by host instead of URL prefix, ignoring the `www.` prefix and host casing](https://github.com/fastruby/jekyll-external-link-accessibility/pull/4)
|
|
8
|
+
- [FEATURE: Open internal links in a new tab too, without adding `rel="nofollow"`](https://github.com/fastruby/jekyll-external-link-accessibility/pull/4)
|
|
9
|
+
- [FEATURE: Show the new-tab icon on all links, not just external ones](https://github.com/fastruby/jekyll-external-link-accessibility/pull/4)
|
|
10
|
+
|
|
11
|
+
# v0.1.0
|
|
12
|
+
|
|
13
|
+
- [FEATURE: Add accessibility attributes (`target`, `title`, new-tab icon, screen-reader note) and `rel="nofollow"` to external links in blog posts](https://github.com/fastruby/jekyll-external-link-accessibility/commit/cbc17d840038fa932f4c1f2f153b885a659fa69e)
|
|
14
|
+
- [FEATURE: Add a `data-no-external` attribute to skip individual links](https://github.com/fastruby/jekyll-external-link-accessibility/commit/49c4721)
|
|
15
|
+
- [FEATURE: Add `post-excerpt` class links to the accessibility code](https://github.com/fastruby/jekyll-external-link-accessibility/pull/1)
|
|
16
|
+
- [BUGFIX: Skip `scss` and `json` files in the hook](https://github.com/fastruby/jekyll-external-link-accessibility/pull/2)
|
|
17
|
+
- [BUGFIX: Skip `xml` files in the hook](https://github.com/fastruby/jekyll-external-link-accessibility/pull/3)
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Kudakwashe Siziva
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Jekyll External Link Accessibility
|
|
2
|
+
|
|
3
|
+
This plugin makes every link in your blog posts open in a new tab accessibly (`target`, `title`, a new-tab icon, and a screen-reader note), and adds `rel="nofollow"` to external links.
|
|
4
|
+
|
|
5
|
+
## Setup
|
|
6
|
+
|
|
7
|
+
1. Add the gem to your `Gemfile`:
|
|
8
|
+
```ruby
|
|
9
|
+
gem 'jekyll-external-link-accessibility'
|
|
10
|
+
```
|
|
11
|
+
2. Run `bundle install` to install the gem
|
|
12
|
+
3. Add the following to your `_config.yml`:
|
|
13
|
+
```yaml
|
|
14
|
+
plugins:
|
|
15
|
+
- jekyll-external-link-accessibility
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
The plugin edits every link in a post, internal and external:
|
|
20
|
+
|
|
21
|
+
- All links open in a new tab so readers don't lose their place, with a `title`, a new-tab icon, and a screen-reader-only "opens a new window" note. Skip a specific link by adding `data-no-external="true"`, e.g. `<a href="...." data-no-external="true">...</a>`.
|
|
22
|
+
- External links (pointing to a host other than your site's `url` in `_config.yml`) also get a `rel` attribute (`external nofollow noopener noreferrer` by default, see Configuration). The `nofollow` keeps them from passing your link equity off-site, so internal links are left without a `rel`. The `www.` prefix and host casing are ignored when comparing hosts.
|
|
23
|
+
|
|
24
|
+
### Configuration
|
|
25
|
+
You can override the default configuration by adding the following section to your Jekyll site's `_config.yml`:
|
|
26
|
+
|
|
27
|
+
```yaml
|
|
28
|
+
external_links:
|
|
29
|
+
rel: external nofollow noopener noreferrer
|
|
30
|
+
target: _blank
|
|
31
|
+
title: Opens a new window
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Styling
|
|
35
|
+
Next to each link is a new-tab icon with a `icon-external-link` class name. You need to have the styles in your project. For example, we use icomoon for icons:
|
|
36
|
+
|
|
37
|
+
```css
|
|
38
|
+
.icon-external-link:before {
|
|
39
|
+
content: "\ea7e";
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
#### Default Configuration
|
|
43
|
+
| Key | Default Value | Description |
|
|
44
|
+
| ---------------------------- | ---------------------------- | -------------------------------------------------- |
|
|
45
|
+
| `external_links.rel` | `external nofollow noopener noreferrer` | The `rel` attribute to add to external links. |
|
|
46
|
+
| `external_links.target` | `_blank` | The `target` attribute to add to external links. |
|
|
47
|
+
| `external_links.title` | `Opens a new window` | The `title` attribute to add title to links. |
|
|
48
|
+
|
|
49
|
+
## Steps to release a new version
|
|
50
|
+
|
|
51
|
+
We follow [Semantic Versioning](https://semver.org/): bump MAJOR for incompatible changes, MINOR for backwards-compatible features, and PATCH for backwards-compatible bug fixes.
|
|
52
|
+
|
|
53
|
+
1. Update the version in `lib/jekyll-external-link-accessibility/version.rb`
|
|
54
|
+
2. Update `CHANGELOG.md`: move the `main (unreleased)` entries under a new `vX.Y.Z / YYYY-MM-DD` header
|
|
55
|
+
3. Push a `release/vX.Y.Z` branch with those changes
|
|
56
|
+
4. Open a pull request titled "Release vX.Y.Z" and merge it to `main`
|
|
57
|
+
5. Tag the release and push the tag:
|
|
58
|
+
```bash
|
|
59
|
+
git checkout main && git pull
|
|
60
|
+
git tag vX.Y.Z
|
|
61
|
+
git push --tags
|
|
62
|
+
```
|
|
63
|
+
6. Build the gem:
|
|
64
|
+
```bash
|
|
65
|
+
gem build jekyll-external-link-accessibility.gemspec
|
|
66
|
+
```
|
|
67
|
+
7. Push it to RubyGems:
|
|
68
|
+
```bash
|
|
69
|
+
gem push jekyll-external-link-accessibility-X.Y.Z.gem
|
|
70
|
+
```
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require 'jekyll/hooks'
|
|
2
|
+
require 'jekyll-external-link-accessibility'
|
|
3
|
+
|
|
4
|
+
Jekyll::Hooks.register :posts, :post_render do |page|
|
|
5
|
+
Jekyll::ExternalLinkAccessibility.modify_links(page)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
Jekyll::Hooks.register :pages, :post_render do |page|
|
|
9
|
+
# Only rewrite HTML pages. Running the HTML parser over .xml (rss/sitemap),
|
|
10
|
+
# .json, .txt, etc. would wrap them in <html><body> and corrupt them.
|
|
11
|
+
next unless ['.html', '.htm'].include?(page.extname)
|
|
12
|
+
Jekyll::ExternalLinkAccessibility.modify_links(page)
|
|
13
|
+
end
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
require 'jekyll-external-link-accessibility/hooks'
|
|
2
|
+
require 'nokogiri'
|
|
3
|
+
require 'uri'
|
|
4
|
+
|
|
5
|
+
module Jekyll
|
|
6
|
+
class ExternalLinkAccessibility
|
|
7
|
+
EXTERNAL_SCHEMES = %w[http:// https:// //].freeze
|
|
8
|
+
|
|
9
|
+
def self.modify_links(page)
|
|
10
|
+
config = page.site.config
|
|
11
|
+
site_host = host_for(config['url'])
|
|
12
|
+
doc = Nokogiri::HTML5(page.output)
|
|
13
|
+
doc.css('.post-content a, .post-excerpt a').each do |a|
|
|
14
|
+
next if a['href'].nil? || a['href'].empty? || a['href'].start_with?('#') || a['data-no-external'] == 'true'
|
|
15
|
+
|
|
16
|
+
# Every link opens in a new tab so readers don't lose their place. Add the
|
|
17
|
+
# icon and a screen-reader note so both sighted and screen-reader users know.
|
|
18
|
+
a['target'] = external_link_target(config: config) unless a['target']
|
|
19
|
+
a['title'] = external_link_title(config: config) unless a['title']
|
|
20
|
+
a.add_child(" <i class='icon-external-link' aria-hidden='true'></i>")
|
|
21
|
+
a.add_child(
|
|
22
|
+
"<span
|
|
23
|
+
style='overflow: hidden;clip: rect(0,0,0,0);
|
|
24
|
+
position: absolute !important;
|
|
25
|
+
width: 1px;
|
|
26
|
+
height: 1px;
|
|
27
|
+
border: 0;
|
|
28
|
+
word-wrap: normal !important;'>
|
|
29
|
+
opens a new window
|
|
30
|
+
</span>"
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
# Only external links get the configured rel (nofollow, etc.) so we don't
|
|
34
|
+
# pass our link equity to other sites.
|
|
35
|
+
if external_link?(a['href'], site_host)
|
|
36
|
+
a['rel'] = external_link_rel(config: config) unless a['rel']
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
page.output = doc.to_html
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# A link is external only when it points to a different host than the site.
|
|
43
|
+
# Relative links ("/blog/...") and absolute links to our own domain are internal,
|
|
44
|
+
# so they keep their link equity (no nofollow).
|
|
45
|
+
def self.external_link?(href, site_host)
|
|
46
|
+
return false unless href.start_with?(*EXTERNAL_SCHEMES)
|
|
47
|
+
|
|
48
|
+
link_host = host_for(href)
|
|
49
|
+
return true if link_host.nil?
|
|
50
|
+
|
|
51
|
+
link_host != site_host
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Returns the lowercased host without a leading "www." so hosts match
|
|
55
|
+
# regardless of case or www prefix.
|
|
56
|
+
def self.host_for(url)
|
|
57
|
+
host = URI.parse(url.to_s).host
|
|
58
|
+
host&.downcase&.sub(/\Awww\./, '')
|
|
59
|
+
rescue URI::InvalidURIError
|
|
60
|
+
nil
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def self.external_link_rel(config:)
|
|
64
|
+
config.dig('external_links', 'rel') || 'external nofollow noopener noreferrer'
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def self.external_link_target(config:)
|
|
68
|
+
config.dig('external_links', 'target') || '_blank'
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def self.external_link_title(config:)
|
|
72
|
+
config.dig('external_links', 'title') || 'Opens a new window'
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
private_class_method :external_link_rel
|
|
76
|
+
private_class_method :external_link_target
|
|
77
|
+
private_class_method :external_link_title
|
|
78
|
+
end
|
|
79
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: jekyll-external-link-accessibility
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.2.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Kudakwashe Siziva
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-07-16 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: jekyll
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '4.0'
|
|
20
|
+
- - ">="
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: 4.0.1
|
|
23
|
+
type: :runtime
|
|
24
|
+
prerelease: false
|
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
26
|
+
requirements:
|
|
27
|
+
- - "~>"
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '4.0'
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: 4.0.1
|
|
33
|
+
- !ruby/object:Gem::Dependency
|
|
34
|
+
name: nokogiri
|
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '1.8'
|
|
40
|
+
- - ">="
|
|
41
|
+
- !ruby/object:Gem::Version
|
|
42
|
+
version: 1.8.5
|
|
43
|
+
type: :runtime
|
|
44
|
+
prerelease: false
|
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
46
|
+
requirements:
|
|
47
|
+
- - "~>"
|
|
48
|
+
- !ruby/object:Gem::Version
|
|
49
|
+
version: '1.8'
|
|
50
|
+
- - ">="
|
|
51
|
+
- !ruby/object:Gem::Version
|
|
52
|
+
version: 1.8.5
|
|
53
|
+
description: Knows how to target external `a` tags and accessibility attributes
|
|
54
|
+
email:
|
|
55
|
+
- kudakwashe@ombulabs.com
|
|
56
|
+
executables: []
|
|
57
|
+
extensions: []
|
|
58
|
+
extra_rdoc_files: []
|
|
59
|
+
files:
|
|
60
|
+
- CHANGELOG.md
|
|
61
|
+
- LICENSE.txt
|
|
62
|
+
- README.md
|
|
63
|
+
- lib/jekyll-external-link-accessibility.rb
|
|
64
|
+
- lib/jekyll-external-link-accessibility/hooks.rb
|
|
65
|
+
- lib/jekyll-external-link-accessibility/version.rb
|
|
66
|
+
homepage: https://github.com/fastruby/jekyll-external-link-accessibility
|
|
67
|
+
licenses:
|
|
68
|
+
- MIT
|
|
69
|
+
metadata:
|
|
70
|
+
homepage_uri: https://github.com/fastruby/jekyll-external-link-accessibility
|
|
71
|
+
source_code_uri: https://github.com/fastruby/jekyll-external-link-accessibility
|
|
72
|
+
changelog_uri: https://github.com/fastruby/jekyll-external-link-accessibility/blob/main/CHANGELOG.md
|
|
73
|
+
post_install_message:
|
|
74
|
+
rdoc_options: []
|
|
75
|
+
require_paths:
|
|
76
|
+
- lib
|
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - ">="
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: 2.7.2
|
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
|
+
requirements:
|
|
84
|
+
- - ">="
|
|
85
|
+
- !ruby/object:Gem::Version
|
|
86
|
+
version: '0'
|
|
87
|
+
requirements: []
|
|
88
|
+
rubygems_version: 3.1.6
|
|
89
|
+
signing_key:
|
|
90
|
+
specification_version: 4
|
|
91
|
+
summary: A simple gem to add accessibility to external links in blog posts
|
|
92
|
+
test_files: []
|