jekyll-extlinks 0.0.1
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/lib/jekyll-extlinks.rb +76 -0
- metadata +73 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2a63e8d8d7b76eb4f87d6b7040f87c674da86480
|
4
|
+
data.tar.gz: 11f4d4d5ac30accdc119aa90988cdc6942c8d99c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8464f1eea90564ebae54da60448d51b5def727423497e61357d6dd90a6c6ae6c76bf38d3ef83c2fec873041ce4e8aba412b05d70b6b0fde7e27db4835041252b
|
7
|
+
data.tar.gz: b9f916c452c5379c69763a72c624ca603151ab744d497bac39b0dfe947f50b3d0d5776da1844f4be179a28a9abf77aa23b3f0445ad28710019026c65cc1f44b1
|
@@ -0,0 +1,76 @@
|
|
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
|
+
end
|
48
|
+
# Stop if no attributes were specified
|
49
|
+
return content unless attributes
|
50
|
+
|
51
|
+
doc = Nokogiri::HTML.parse(content)
|
52
|
+
# Stop if we could't parse with HTML
|
53
|
+
return content unless doc
|
54
|
+
|
55
|
+
doc.css('a').each do |a|
|
56
|
+
# If this is a local link don't change it
|
57
|
+
next unless a.get_attribute('href') =~ /\Ahttp/i
|
58
|
+
|
59
|
+
attributes.each do |attr, value|
|
60
|
+
if attr.downcase == 'rel'
|
61
|
+
# If there's a rel already don't change it
|
62
|
+
next unless !a.get_attribute('rel') || a.get_attribute('rel').empty?
|
63
|
+
# Skip whitelisted hosts for the 'rel' attribute
|
64
|
+
next if rel_exclude && contains_any(a.get_attribute('href'), rel_exclude)
|
65
|
+
end
|
66
|
+
a.set_attribute(attr, value)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
doc.to_s
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
Liquid::Template.register_filter(Jekyll::ExtLinks)
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: 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: 2017-02-25 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: '3.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.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.6'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
description: |2
|
42
|
+
Adds custom attributes to external links (rel="nofollow", target="_blank", etc.)
|
43
|
+
email: dima@ogarkov.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- lib/jekyll-extlinks.rb
|
49
|
+
homepage: http://ogarkov.com/jekyll/plugins/extlinks/
|
50
|
+
licenses:
|
51
|
+
- MIT
|
52
|
+
metadata: {}
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
requirements: []
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 2.6.10
|
70
|
+
signing_key:
|
71
|
+
specification_version: 4
|
72
|
+
summary: Jekyll ExtLinks Plugin
|
73
|
+
test_files: []
|