jekyll-external-links 0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 874a5043ed58555922815f10b706a43d31602b33
4
+ data.tar.gz: 692246a4713c26ceed5ae997d1648a44f2bfe7a9
5
+ SHA512:
6
+ metadata.gz: 4346f5087be47d6982afb5052eb8db9f38121dc80b9702bae39d8389c388e53d62495d61354c66a2225c37325df91747889baa0dce49732bf155326a48157f86
7
+ data.tar.gz: 345cde83fa3d65b18772acf03d5fc27b38dd46a1f6b4007295c7ec21f38fb191a99c5ed91c653729e14946678b71776b2bf8410bbc7503c78520ea5b8bdf5028
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Ribose
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,31 @@
1
+ # Jekyll plugin that marks external links
2
+
3
+ In each Jekyll document or page content, updates `<a>` elements that point
4
+ to external sites as follows:
5
+
6
+ - Adds `rel="external"` attribute
7
+ - Adds inner HTML markup with external link icon
8
+
9
+ You can specify a CSS selector for which links are to be marked,
10
+ and a list of selectors for which links are to be ignored
11
+ (ignored selectors take precedence).
12
+
13
+ ## Configuration
14
+
15
+ Example configuration with defaults:
16
+
17
+ ```
18
+ external_links:
19
+ selector: 'main a'
20
+ ignored_selectors:
21
+ - a[href*=travis]
22
+ - a[href*=coverity]
23
+ - a[href*=codecov]
24
+ marker_html: "<span class='ico-ext'><i class='fas fa-external-link-square-alt'></i></span>"
25
+ ```
26
+
27
+ As you can see, by default the Font Awesome’s `fa-externa-link-square-alt` icon is used,
28
+ which implies that you are using Font Awesome.
29
+
30
+ You can set marker_html to empty string and style links with custom CSS rule
31
+ (e.g., `a[rel=external] { border-bottom-style: dashed; }`), though it’s less flexible.
data/develop/release ADDED
@@ -0,0 +1,41 @@
1
+ #!/bin/sh
2
+ # Tag and push a release.
3
+
4
+ set -e
5
+
6
+ # Make sure we're in the project root.
7
+
8
+ cd $(dirname "$0")/..
9
+
10
+ # Make sure the darn thing works? Meh.
11
+ # bundle update
12
+
13
+ # Build a new gem archive.
14
+
15
+ rm -rf jekyll-external-links-*.gem
16
+ gem build -q jekyll-external-links.gemspec
17
+
18
+ # Make sure we're on the master branch.
19
+
20
+ (git branch | grep -q 'master') || {
21
+ echo "Only release from the master branch."
22
+ exit 1
23
+ }
24
+
25
+ # Figure out what version we're releasing.
26
+
27
+ tag=v`ls jekyll-external-links-*.gem | sed 's/^jekyll-external-links-\(.*\)\.gem$/\1/'`
28
+
29
+ # Make sure we haven't released this version before.
30
+
31
+ git fetch -t origin
32
+
33
+ (git tag -l | grep -q "$tag") && {
34
+ echo "Whoops, there's already a '${tag}' tag."
35
+ exit 1
36
+ }
37
+
38
+ # Tag it and bag it.
39
+
40
+ gem push jekyll-external-links-*.gem && git tag "$tag" &&
41
+ git push origin master && git push origin "$tag"
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'jekyll-external-links'
5
+ s.version = '0.1'
6
+ s.authors = ['Ribose Inc.']
7
+ s.email = ['open.source@ribose.com']
8
+
9
+ s.summary = 'Jekyll plugin that marks external links in your site'
10
+ s.homepage = 'https://github.com/riboseinc/jekyll-external-links/'
11
+ s.license = 'MIT'
12
+
13
+ s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r!^(test|spec|features)/!) }
14
+
15
+ s.add_runtime_dependency 'jekyll', '~> 3.8'
16
+ s.add_development_dependency 'rake', '~> 12.0'
17
+ s.add_development_dependency 'rubocop', '~> 0.50'
18
+
19
+ s.require_paths = ["lib"]
20
+ end
@@ -0,0 +1,7 @@
1
+ require 'jekyll-external-links/external_links'
2
+
3
+
4
+ module Jekyll
5
+ module ExternalLinks
6
+ end
7
+ end
@@ -0,0 +1,73 @@
1
+ require 'nokogiri'
2
+ require 'uri'
3
+
4
+ # Given hostname and content, updates any found <a> elements as follows:
5
+ #
6
+ # - Adds `rel` attribute
7
+ # - Appends inner markup for external link icon
8
+ #
9
+ # Only processes external links where `href` starts with "http"
10
+ # and target host does not start with given site hostname.
11
+ def process_content(site_hostname, content, marker_html, link_selector, exclude_selectors=[])
12
+ content = Nokogiri::HTML(content)
13
+ content.css(link_selector).each do |a|
14
+ next if matches_one_of(a, exclude_selectors)
15
+ next unless a.get_attribute('href') =~ /\Ahttp/i
16
+ next if a.get_attribute('href') =~ /\Ahttp(s)?:\/\/#{site_hostname}\//i
17
+ next if a.inner_html.include? "ico-ext"
18
+ a.set_attribute('rel', 'external')
19
+ a.inner_html = "#{a.inner_html}#{marker_html}"
20
+ end
21
+ return content.to_s
22
+ end
23
+
24
+ def process_page_or_document(page_or_document)
25
+ site_hostname = URI(doc.site.config['url']).host
26
+
27
+ ext_link_config = doc.site.config['external_links'] || {}
28
+
29
+ # The link is marked as external by:
30
+ # (1) setting the rel attribute to external and
31
+ # (2) appending specified marker HTML.
32
+ # Default marker is Font Awesome icon.
33
+ marker_html = ext_link_config['marker_html'] || "<span class='ico-ext'><i class='fas fa-external-link-square-alt'></i></span>"
34
+
35
+ # Determines which links to mark. E.g., usually we don’t want to mark navigational links.
36
+ link_selector = ext_link_config['selector'] || 'main a'
37
+
38
+ # Determining which links to ignore. For example, links comprised entirely from images
39
+ # may look incorrectly with external marker.
40
+ unmarked_link_selectors = ext_link_config['ignored_selectors'] || [
41
+ 'a[href*=travis]',
42
+ 'a[href*=coverity]',
43
+ 'a[href*=codecov]',
44
+ ]
45
+
46
+ unless page_or_document.asset_file?
47
+ page_or_document.output = process_content(
48
+ site_hostname,
49
+ doc.output,
50
+ marker_html,
51
+ link_selector,
52
+ unmarked_link_selectors)
53
+ end
54
+ end
55
+
56
+ # Returns true if Nokogiri’s Node matches one of selectors,
57
+ # otherwise return false
58
+ def matches_one_of(node, selectors)
59
+ for selector in selectors
60
+ if node.matches? selector
61
+ return true
62
+ end
63
+ end
64
+ return false
65
+ end
66
+
67
+ Jekyll::Hooks.register :documents, :post_render do |doc|
68
+ mark_links_in_page_or_document(doc)
69
+ end
70
+
71
+ Jekyll::Hooks.register :pages, :post_render do |page|
72
+ mark_links_in_page_or_document(doc)
73
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-external-links
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Ribose Inc.
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-06-06 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.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '12.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '12.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.50'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.50'
55
+ description:
56
+ email:
57
+ - open.source@ribose.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - LICENSE.txt
63
+ - README.md
64
+ - develop/release
65
+ - jekyll-external-links.gemspec
66
+ - lib/jekyll-external-links.rb
67
+ - lib/jekyll-external-links/external_links.rb
68
+ homepage: https://github.com/riboseinc/jekyll-external-links/
69
+ licenses:
70
+ - MIT
71
+ metadata: {}
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 2.5.2.3
89
+ signing_key:
90
+ specification_version: 4
91
+ summary: Jekyll plugin that marks external links in your site
92
+ test_files: []