jekyll_href 1.0.0

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
+ SHA256:
3
+ metadata.gz: d6d09a2fc7a319e4fb417c383b15bb97acfc644cd795fefeba3faa5cbcf83403
4
+ data.tar.gz: d0a2c065d042a1ff2cefb8a973849585fafe7d57da8f8dd512e7cf4ac6161257
5
+ SHA512:
6
+ metadata.gz: 034224a848331a861479db283806d0736e355cc042fdac5829405158f4bc777a6c15af2cf07b79739eaa272d40a452e3267a528c801fb14ddbdaa4444d336edb
7
+ data.tar.gz: 18f59ff3419338872629d589adb3e9380fc963e9bda568afde8a45d8fbd8124a90bc7b45099262beaa67b8829708a9b762f93df3b9dfd29e0c0bb7a76aeb1740
data/.rubocop.yml ADDED
@@ -0,0 +1,31 @@
1
+ require: rubocop-jekyll
2
+ inherit_gem:
3
+ rubocop-jekyll: .rubocop.yml
4
+
5
+ AllCops:
6
+ Exclude:
7
+ - vendor/**/*
8
+ - Gemfile*
9
+ NewCops: enable
10
+ TargetRubyVersion: 2.6
11
+
12
+ Layout/LineLength:
13
+ Max: 150
14
+
15
+ Layout/MultilineMethodCallIndentation:
16
+ Enabled: false
17
+
18
+ Metrics/BlockLength:
19
+ Enabled: false
20
+
21
+ Style/PercentLiteralDelimiters:
22
+ Enabled: false
23
+
24
+ Style/RegexpLiteral:
25
+ Enabled: false
26
+
27
+ Style/StringLiterals:
28
+ Enabled: false
29
+
30
+ Style/StringLiteralsInInterpolation:
31
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ ## 1.0.0 / 2022-03-11
2
+ * Made into a Ruby gem and published on RubyGems.org as [jekyll_href](https://rubygems.org/gems/jekyll_href).
3
+ * `bin/attach` script added for debugging
4
+ * Rubocop standards added
5
+ * Proper versioning and CHANGELOG.md added
6
+
7
+ ## 0.1.0 / 2020-12-29
8
+ * Initial version published
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in jekyll_href.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,69 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ jekyll_href (1.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ coderay (1.1.3)
11
+ diff-lcs (1.5.0)
12
+ method_source (1.0.0)
13
+ parallel (1.21.0)
14
+ parser (3.1.1.0)
15
+ ast (~> 2.4.1)
16
+ pry (0.14.1)
17
+ coderay (~> 1.1)
18
+ method_source (~> 1.0)
19
+ rainbow (3.1.1)
20
+ rake (13.0.6)
21
+ regexp_parser (2.2.1)
22
+ rexml (3.2.5)
23
+ rspec (3.11.0)
24
+ rspec-core (~> 3.11.0)
25
+ rspec-expectations (~> 3.11.0)
26
+ rspec-mocks (~> 3.11.0)
27
+ rspec-core (3.11.0)
28
+ rspec-support (~> 3.11.0)
29
+ rspec-expectations (3.11.0)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.11.0)
32
+ rspec-mocks (3.11.0)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.11.0)
35
+ rspec-support (3.11.0)
36
+ rubocop (1.18.4)
37
+ parallel (~> 1.10)
38
+ parser (>= 3.0.0.0)
39
+ rainbow (>= 2.2.2, < 4.0)
40
+ regexp_parser (>= 1.8, < 3.0)
41
+ rexml
42
+ rubocop-ast (>= 1.8.0, < 2.0)
43
+ ruby-progressbar (~> 1.7)
44
+ unicode-display_width (>= 1.4.0, < 3.0)
45
+ rubocop-ast (1.16.0)
46
+ parser (>= 3.1.1.0)
47
+ rubocop-jekyll (0.12.0)
48
+ rubocop (~> 1.18.0)
49
+ rubocop-performance (~> 1.2)
50
+ rubocop-performance (1.13.3)
51
+ rubocop (>= 1.7.0, < 2.0)
52
+ rubocop-ast (>= 0.4.0)
53
+ ruby-progressbar (1.11.0)
54
+ unicode-display_width (2.1.0)
55
+
56
+ PLATFORMS
57
+ x86_64-linux
58
+
59
+ DEPENDENCIES
60
+ bundler
61
+ jekyll_href!
62
+ pry
63
+ rake (~> 13.0)
64
+ rspec
65
+ rubocop
66
+ rubocop-jekyll
67
+
68
+ BUNDLED WITH
69
+ 2.3.7
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Mike Slinn
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,102 @@
1
+ # `Jekyll_href`
2
+
3
+ `Jekyll_href` is a Jekyll plugin that provides a new Liquid tag: `href`.
4
+ The Liquid tag generates and `<a href>` HTML tag, by default containing `target="_blank"` and `rel=nofollow`.
5
+ To suppress the `nofollow` attribute, preface the link with the word `follow`.
6
+ To suppress the `target` attribute, preface the link with the word `notarget`.
7
+
8
+
9
+ ### Syntax:
10
+ ```
11
+ {% href [match | [follow] [notarget]] url text to display %}
12
+ ```
13
+ Note that the url should not be enclosed in quotes.
14
+ Also please note that the square brackets denote optional parameters, and should not be typed.
15
+
16
+
17
+ ## Installation
18
+
19
+ Add this line to your Jekyll website's `Gemfile`, within the `jekyll_plugins` group:
20
+
21
+ ```ruby
22
+ group :jekyll_plugins do
23
+ gem 'jekyll_href'
24
+ end
25
+ ```
26
+
27
+ And then execute:
28
+
29
+ $ bundle install
30
+
31
+ Or install it yourself as:
32
+
33
+ $ gem install jekyll_href
34
+
35
+ ## Usage
36
+
37
+ ```
38
+ {% href https://mslinn.com The Awesome %}
39
+ ```
40
+
41
+ Expands to this:
42
+ ```html
43
+ <a href='https://mslinn.com' target='_blank' rel='nofollow'>The Awesome</a>
44
+ ```
45
+
46
+ Which renders as this: <a href='https://mslinn.com' target='_blank' rel='nofollow'>The Awesome</a>
47
+
48
+
49
+ ```
50
+ {% href follow https://mslinn.com The Awesome %}
51
+ ```
52
+
53
+ Expands to this:
54
+ ```html
55
+ <a href='https://mslinn.com' target='_blank'>The Awesome</a>
56
+ ```
57
+
58
+
59
+ ```
60
+ {% href notarget https://mslinn.com The Awesome %}
61
+ ```
62
+
63
+ Expands to this:
64
+ ```html
65
+ <a href='https://mslinn.com' rel='nofollow'>The Awesome</a>
66
+ ```
67
+
68
+
69
+ ```
70
+ {% href follow notarget https://mslinn.com The Awesome %}
71
+ ```
72
+
73
+ Expands to this:
74
+ ```html
75
+ <a href='https://mslinn.com'>The Awesome</a>
76
+ ```
77
+
78
+ ```
79
+ {% href match setting-up-django-oscar.html tutorial site %}
80
+ ```
81
+
82
+ Expands to this:
83
+ ```html
84
+ <a href='/blog/2021/02/11/setting-up-django-oscar.html'>tutorial site</a>
85
+ ```
86
+
87
+
88
+ ## Development
89
+
90
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
91
+
92
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
93
+
94
+
95
+ ## Contributing
96
+
97
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/jekyll_href.
98
+
99
+
100
+ ## License
101
+
102
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/jekyll_href/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "jekyll_href"
7
+ spec.version = JekyllHref::VERSION
8
+ spec.authors = ["Mike Slinn"]
9
+ spec.email = ["mslinn@mslinn.com"]
10
+
11
+ spec.summary = "Generates an 'a href' tag, possibly with target='_blank' and rel='nofollow'."
12
+ spec.description = "Generates an 'a href' tag, possibly with target='_blank' and rel='nofollow'."
13
+ spec.homepage = "https://github.com/mslinn/jekyll_href"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ spec.metadata["allowed_push_host"] = "https://rubygems.org/"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/mslinn/jekyll_href"
21
+ spec.metadata["changelog_uri"] = "https://github.com/mslinn/jekyll_href/CHANGELOG.md"
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject do |f|
27
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
28
+ end
29
+ end
30
+ spec.bindir = "exe"
31
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+
34
+ spec.add_development_dependency 'bundler'
35
+ spec.add_development_dependency 'pry'
36
+ spec.add_development_dependency 'rake'
37
+ spec.add_development_dependency 'rspec'
38
+ spec.add_development_dependency 'rubocop'
39
+ spec.add_development_dependency 'rubocop-jekyll'
40
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JekyllHref
4
+ VERSION = "1.0.0"
5
+ end
@@ -0,0 +1,148 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "jekyll_href/version"
4
+
5
+ # @author Copyright 2020 Michael Slinn
6
+ # @license SPDX-License-Identifier: Apache-2.0
7
+ #
8
+ # Generates an href.
9
+ # Note that the url should not be enclosed in quotes.
10
+ #
11
+ # If the link starts with 'http' or `match` is specified:
12
+ # The link will open in a new tab or window
13
+ # The link will include `rel=nofollow` for SEO purposes.
14
+ #
15
+ # To suppress the `nofollow` attribute, preface the link with the word `follow`.
16
+ # To suppress the `target` attribute, preface the link with the word `notarget`.
17
+ #
18
+ # The `match` option looks through the pages collection for a URL with containing the provided substring.
19
+ # Match implies follow and notarget.
20
+ #
21
+ # If a section called plugin-vars exists then its name/value pairs are available for substitution.
22
+ # plugin-vars:
23
+ # django-github: 'https://github.com/django/django/blob/3.1.7'
24
+ # django-oscar-github: 'https://github.com/django-oscar/django-oscar/blob/3.0.2'
25
+ #
26
+ #
27
+ # @example General form
28
+ # {% href [follow] [notarget] [match] url text to display %}
29
+ #
30
+ # @example Generates `nofollow` and `target` attributes.
31
+ # {% href https://mslinn.com The Awesome %}
32
+ #
33
+ # @example Does not generate `nofollow` or `target` attributes.
34
+ # {% href follow notarget https://mslinn.com The Awesome %}
35
+ #
36
+ # @example Does not generate `nofollow` attribute.
37
+ # {% href follow https://mslinn.com The Awesome %}
38
+ #
39
+ # @example Does not generate `target` attribute.
40
+ # {% href notarget https://mslinn.com The Awesome %}
41
+ #
42
+ # @example Matches page with URL containing abc.
43
+ # {% href match abc The Awesome %}
44
+ # @example Matches page with URL containing abc.
45
+ # {% href match abc.html#tag The Awesome %}
46
+ #
47
+ # @example Substitute name/value pair for the django-github variable:
48
+ # {% href {{django-github}}/django/core/management/__init__.py#L398-L401
49
+ # <code>django.core.management.execute_from_command_line</code> %}
50
+
51
+ module JekyllHref
52
+ class Error < StandardError; end
53
+
54
+ class ExternalHref < Liquid::Tag
55
+ # @param tag_name [String] is the name of the tag, which we already know.
56
+ # @param command_line [Hash, String, Liquid::Tag::Parser] the arguments from the web page.
57
+ # @param tokens [Liquid::ParseContext] tokenized command line
58
+ # @return [void]
59
+ def initialize(tag_name, command_line, tokens) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
60
+ super
61
+
62
+ @follow = " rel='nofollow'"
63
+ @match = false
64
+ @target = " target='_blank'"
65
+
66
+ tokens = command_line.strip.split
67
+
68
+ follow_index = tokens.index("follow")
69
+ if follow_index
70
+ tokens.delete_at(follow_index)
71
+ @follow = ""
72
+ end
73
+
74
+ target_index = tokens.index("notarget")
75
+ if target_index
76
+ tokens.delete_at(target_index)
77
+ @target = ""
78
+ end
79
+
80
+ match_index = tokens.index("match")
81
+ if match_index
82
+ tokens.delete_at(match_index)
83
+ @follow = ""
84
+ @match = true
85
+ @target = ""
86
+ end
87
+
88
+ @link = tokens.shift
89
+
90
+ @text = tokens.join(" ").strip
91
+ if @text.empty?
92
+ @text = "<code>${@link}</code>"
93
+ @link = "https://#{@link}"
94
+ end
95
+
96
+ unless @link.start_with? "http"
97
+ @follow = ""
98
+ @target = ""
99
+ end
100
+ end
101
+
102
+ def match(context) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
103
+ site = context.registers[:site]
104
+ config = site.config['href']
105
+ die_if_nomatch = !config.nil? && config['nomatch'] && config['nomatch']=='fatal'
106
+
107
+ path, fragment = @link.split('#')
108
+
109
+ # puts "@link=#{@link}"
110
+ # puts "site.posts[0].url = #{site.posts.docs[0].url}"
111
+ # puts "site.posts[0].path = #{site.posts.docs[0].path}"
112
+ posts = site.posts.docs.select { |x| x.url.include?(path) }
113
+ case posts.length
114
+ when 0
115
+ if die_if_nomatch
116
+ abort "href error: No url matches '#{@link}'"
117
+ else
118
+ @link = "#"
119
+ @text = "<i>#{@link} is not available</i>"
120
+ end
121
+ when 1
122
+ @link = "#{@link}\##{fragment}" if fragment
123
+ else
124
+ abort "Error: More than one url matched: #{ matches.join(", ")}"
125
+ end
126
+ end
127
+
128
+ def replace_vars(context, link)
129
+ variables = context.registers[:site].config['plugin-vars']
130
+ variables.each do |name, value|
131
+ # puts "#{name}=#{value}"
132
+ link = link.gsub("{{#{name}}}", value)
133
+ end
134
+ link
135
+ end
136
+
137
+ # Method prescribed by the Jekyll plugin lifecycle.
138
+ # @return [String]
139
+ def render(context)
140
+ match(context) if @match
141
+ link = replace_vars(context, @link)
142
+ # puts "@link=#{@link}; link=#{link}"
143
+ "<a href='#{link}'#{@target}#{@follow}>#{@text}</a>"
144
+ end
145
+ end
146
+ end
147
+
148
+ Liquid::Template.register_tag('href', JekyllHref::ExternalHref)
@@ -0,0 +1,4 @@
1
+ module JekyllHref
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll_href
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Mike Slinn
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-03-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop-jekyll
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Generates an 'a href' tag, possibly with target='_blank' and rel='nofollow'.
98
+ email:
99
+ - mslinn@mslinn.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".rubocop.yml"
105
+ - CHANGELOG.md
106
+ - Gemfile
107
+ - Gemfile.lock
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - jekyll_href.gemspec
112
+ - lib/jekyll_href.rb
113
+ - lib/jekyll_href/version.rb
114
+ - sig/jekyll_href.rbs
115
+ homepage: https://github.com/mslinn/jekyll_href
116
+ licenses:
117
+ - MIT
118
+ metadata:
119
+ allowed_push_host: https://rubygems.org/
120
+ homepage_uri: https://github.com/mslinn/jekyll_href
121
+ source_code_uri: https://github.com/mslinn/jekyll_href
122
+ changelog_uri: https://github.com/mslinn/jekyll_href/CHANGELOG.md
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: 2.6.0
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubygems_version: 3.2.5
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Generates an 'a href' tag, possibly with target='_blank' and rel='nofollow'.
142
+ test_files: []