h2o-ac-jekyll-extlinks 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +3 -0
- data/License +21 -0
- data/README.md +52 -0
- data/jekyll-extlinks.gemspec +17 -0
- data/lib/jekyll-extlinks.rb +85 -0
- metadata +78 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1e484818952d26986d7abda90750340177dcea1f67b49c6a5967334c69532938
|
4
|
+
data.tar.gz: e3b9992c0da16660d4f4e40d282662e5cffa6be6ff3cc3fd81fc5dfcc79e295b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1a198e66810b990940cdea1febfd44f367ce8e0a975d1e1a44673ea3c8c68b8e09b06f3b7a0faecc2317d1650bc72edbddbc5692f2f4403e378c82193acc5003
|
7
|
+
data.tar.gz: 4d0ec454a9b4c38b2e35112d16a968a5642a99b0e69b134a35ad4d28be11ff44bf08b48108a3b1347f921ca1adc2c7e3e0296c91ad06b86404fecf079fa9326f
|
data/Gemfile
ADDED
data/License
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2017 Dmitry Ogarkov
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Jekyll ExtLinks
|
2
|
+
|
3
|
+
This Jekyll plugin adds custom attributes (`rel="nofollow"`, `target="_blank"`, etc.) to external links in your content.
|
4
|
+
|
5
|
+
This Jekyll plugin adds custom attributes to external links in your content. For example, you can add `rel="nofollow"` to all external links by default (with exceptions if you need them), or something like `class="external"`. You can also use it to add `target="_blank"` to external links, but generally it is not recommended as it leads to bad user experience. Multiple attributes are allowed.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
1. Install the gem from RubyGems: `gem install h2o-ac-jekyll-extlinks`.
|
10
|
+
|
11
|
+
2. Add this to your project's `Gemfile`:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'h2o-ac-jekyll-extlinks'
|
15
|
+
```
|
16
|
+
|
17
|
+
3. Add this to your project's `_config.yml`:
|
18
|
+
|
19
|
+
```yml
|
20
|
+
plugins:
|
21
|
+
- jekyll-extlinks
|
22
|
+
```
|
23
|
+
|
24
|
+
## Configuration
|
25
|
+
|
26
|
+
Configure the plugin in your `_config.yml`. Notice the indentation matters. Example:
|
27
|
+
|
28
|
+
```yml
|
29
|
+
extlinks:
|
30
|
+
attributes: {rel: nofollow, target: _blank, class: external}
|
31
|
+
rel_exclude: ['host1.com', 'host2.net']
|
32
|
+
class_exclude: ['host1.com', 'host2.net']
|
33
|
+
```
|
34
|
+
|
35
|
+
* `attributes` are required - at least one of them; `rel_exclude` and `class_exclude` are optional
|
36
|
+
* Links to hosts listed in `rel_exclude` will not have the `rel` attribute set
|
37
|
+
* Links to hosts listed in `class_exclude` will not have the `class` attribute set
|
38
|
+
* Links which have the `rel` attribute already will keep it unchanged, like this one in Markdown: `[Link text](http://someurl.com){:rel="dofollow"}`
|
39
|
+
* Relative links will not be processed
|
40
|
+
* Don't forget to actually use the plugin (see below)
|
41
|
+
|
42
|
+
## Usage
|
43
|
+
|
44
|
+
Use the plugin in your Jekyll layouts: `{{ content | extlinks }}`
|
45
|
+
|
46
|
+
## Notes
|
47
|
+
|
48
|
+
Developed by Dmitry Ogarkov - <http://ogarkov.com/jekyll/plugins/extlinks/>
|
49
|
+
|
50
|
+
Based on <http://dev.mensfeld.pl/2014/12/rackrails-middleware-that-will-ensure-relnofollow-for-all-your-links/>
|
51
|
+
|
52
|
+
Revised by zhonger - <https://github.com/zhonger/jekyll-extlinks>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "h2o-ac-jekyll-extlinks"
|
3
|
+
s.version = "0.0.1"
|
4
|
+
s.date = "2022-08-29"
|
5
|
+
s.summary = "Jekyll ExtLinks Plugin"
|
6
|
+
s.description = <<-EOF
|
7
|
+
Adds custom attributes to external links (rel="nofollow", target="_blank", etc.)
|
8
|
+
EOF
|
9
|
+
s.authors = ["Dmitry Ogarkov"]
|
10
|
+
s.email = "dima@ogarkov.com"
|
11
|
+
s.files = ["lib/jekyll-extlinks.rb", "Gemfile", "jekyll-extlinks.gemspec", "License", "README.md"]
|
12
|
+
s.homepage = "https://github.com/zhonger/jekyll-extlinks/"
|
13
|
+
s.license = "MIT"
|
14
|
+
|
15
|
+
s.add_runtime_dependency "jekyll", "~> 4.0"
|
16
|
+
s.add_runtime_dependency "nokogiri", "~> 1"
|
17
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# Jekyll ExtLinks Plugin
|
2
|
+
# Adds custom attributes to external links (rel="nofollow", target="_blank", etc.)
|
3
|
+
#
|
4
|
+
# Configuration example in _config.yml (notice the indentation matters):
|
5
|
+
#
|
6
|
+
# extlinks:
|
7
|
+
# attributes: {rel: nofollow, target: _blank}
|
8
|
+
# rel_exclude: ['host1.com', 'host2.net']
|
9
|
+
#
|
10
|
+
# (attributes are required - at least one of them, rel_exclude is optional)
|
11
|
+
# Relative links will not be processed.
|
12
|
+
# Links to hosts listed in rel_exclude will not have the 'rel' attribute set.
|
13
|
+
# Links which have the 'rel' attribute already will keep it unchanged, like
|
14
|
+
# this one in Markdown:
|
15
|
+
# [Link text](http://someurl.com){:rel="dofollow"}
|
16
|
+
#
|
17
|
+
# Using in layouts: {{ content | extlinks }}
|
18
|
+
#
|
19
|
+
# Developed by Dmitry Ogarkov - http://ogarkov.com/jekyll/plugins/extlinks/
|
20
|
+
# Based on http://dev.mensfeld.pl/2014/12/rackrails-middleware-that-will-ensure-relnofollow-for-all-your-links/
|
21
|
+
|
22
|
+
require 'jekyll'
|
23
|
+
require 'nokogiri'
|
24
|
+
|
25
|
+
module Jekyll
|
26
|
+
module ExtLinks
|
27
|
+
# Access plugin config in _config.yml
|
28
|
+
def config
|
29
|
+
@context.registers[:site].config['extlinks']
|
30
|
+
end
|
31
|
+
|
32
|
+
# Checks if str contains any fragment of the fragments array
|
33
|
+
def contains_any(str, fragments)
|
34
|
+
return false unless Regexp.union(fragments) =~ str
|
35
|
+
true
|
36
|
+
end
|
37
|
+
|
38
|
+
def extlinks(content)
|
39
|
+
# Process configured link attributes and whitelisted hosts
|
40
|
+
if config
|
41
|
+
if config['attributes']
|
42
|
+
attributes = Array(config['attributes'])
|
43
|
+
end
|
44
|
+
if config['rel_exclude']
|
45
|
+
rel_exclude = Array(config['rel_exclude'])
|
46
|
+
end
|
47
|
+
if config['class_exclude']
|
48
|
+
class_exclude = Array(config['class_exclude'])
|
49
|
+
end
|
50
|
+
end
|
51
|
+
# Stop if no attributes were specified
|
52
|
+
return content unless attributes
|
53
|
+
|
54
|
+
doc = Nokogiri::HTML.fragment(content)
|
55
|
+
# Stop if we could't parse with HTML
|
56
|
+
return content unless doc
|
57
|
+
|
58
|
+
doc.css('a').each do |a|
|
59
|
+
# If this is a local link don't change it
|
60
|
+
next unless a.get_attribute('href') =~ /\Ahttp/i
|
61
|
+
|
62
|
+
attributes.each do |attr, value|
|
63
|
+
if attr.downcase == 'rel'
|
64
|
+
# If there's a rel already don't change it
|
65
|
+
next unless !a.get_attribute('rel') || a.get_attribute('rel').empty?
|
66
|
+
# Skip whitelisted hosts for the 'rel' attribute
|
67
|
+
next if rel_exclude && contains_any(a.get_attribute('href'), rel_exclude)
|
68
|
+
end
|
69
|
+
if attr.downcase == 'class'
|
70
|
+
# If there's a class already don't change it
|
71
|
+
next unless !a.get_attribute('class') || a.get_attribute('class').empty?
|
72
|
+
# Skip whitelisted hosts for the 'class' attribute
|
73
|
+
next if class_exclude && contains_any(a.get_attribute('href'), class_exclude)
|
74
|
+
end
|
75
|
+
a.set_attribute(attr, value)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
doc.to_s
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
Liquid::Template.register_filter(Jekyll::ExtLinks)
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: h2o-ac-jekyll-extlinks
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dmitry Ogarkov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-08-29 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
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: nokogiri
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1'
|
41
|
+
description: ' Adds custom attributes to external links (rel="nofollow", target="_blank",
|
42
|
+
etc.)
|
43
|
+
|
44
|
+
'
|
45
|
+
email: dima@ogarkov.com
|
46
|
+
executables: []
|
47
|
+
extensions: []
|
48
|
+
extra_rdoc_files: []
|
49
|
+
files:
|
50
|
+
- Gemfile
|
51
|
+
- License
|
52
|
+
- README.md
|
53
|
+
- jekyll-extlinks.gemspec
|
54
|
+
- lib/jekyll-extlinks.rb
|
55
|
+
homepage: https://github.com/zhonger/jekyll-extlinks/
|
56
|
+
licenses:
|
57
|
+
- MIT
|
58
|
+
metadata: {}
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubygems_version: 3.2.3
|
75
|
+
signing_key:
|
76
|
+
specification_version: 4
|
77
|
+
summary: Jekyll ExtLinks Plugin
|
78
|
+
test_files: []
|