Skip to content

Commit

Permalink
Merge pull request keithmifsud#44 from keithmifsud/amyspark-jekyll-4
Browse files Browse the repository at this point in the history
Amyspark jekyll 4
  • Loading branch information
keithmifsud authored Oct 14, 2019
2 parents 2f338ad + 373aa8c commit f6fb51a
Show file tree
Hide file tree
Showing 10 changed files with 218 additions and 221 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
Gemfile.lock
dev_notes.md
.vscode
spec/fixtures/unit/.jekyll-cache
pkg
spec/fixtures/unit/.jekyll-cache
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ inherit_gem:
jekyll: .rubocop.yml

AllCops:
TargetRubyVersion: 2.3
TargetRubyVersion: 2.6
Exclude:
- vendor/**/*

Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ language: ruby
rvm:
- 2.5
- 2.4
- 2.3
- 2.6
before_install:
- gem update --system
- gem install bundler
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

source "https://rubygems.org"
source 'https://rubygems.org'

gemspec
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require "bundler/gem_tasks"
require "rspec/core/rake_task"
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec)
36 changes: 18 additions & 18 deletions jekyll-target-blank.gemspec
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
# frozen_string_literal: true

lib = File.expand_path("lib", __dir__)
lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "jekyll-target-blank/version"
require 'jekyll-target-blank/version'

Gem::Specification.new do |spec|
spec.name = "jekyll-target-blank"
spec.name = 'jekyll-target-blank'
spec.version = JekyllTargetBlank::VERSION
spec.authors = ["Keith Mifsud"]
spec.email = ["[email protected]"]
spec.summary = "Target Blank automatically changes the external links to open in a new browser."
spec.description = "Target Blank automatically changes the external links to open in a new browser for Jekyll sites."
spec.homepage = "https://github.com/keithmifsud/jekyll-target-blank"
spec.license = "MIT"
spec.authors = ['Keith Mifsud']
spec.email = ['[email protected]']
spec.summary = 'Target Blank automatically changes the external links to open in a new browser.'
spec.description = 'Target Blank automatically changes the external links to open in a new browser for Jekyll sites.'
spec.homepage = 'https://github.com/keithmifsud/jekyll-target-blank'
spec.license = 'MIT'
spec.files = `git ls-files -z`.split("\x0")
spec.require_paths = ["lib"]
spec.required_ruby_version = ">= 2.3.0"
spec.require_paths = ['lib']
spec.required_ruby_version = '>= 2.3.0'
spec.add_dependency 'jekyll', '>= 3.0', '<5.0'
spec.add_dependency 'nokogiri', '~> 1.10'
spec.add_development_dependency 'bundler', '~> 2.0'
spec.add_development_dependency 'rake', '~> 12.0'
spec.add_development_dependency 'rspec', '~> 3.0'
spec.add_development_dependency 'rubocop', '>= 0.68.0', '<= 0.72.0'
spec.add_development_dependency "rubocop-jekyll", "~> 0.10.0"

spec.add_dependency "jekyll", "~> 3.0"
spec.add_dependency "nokogiri", "~> 1.10.4"

spec.add_development_dependency "bundler", "~> 2.0"
spec.add_development_dependency "rake", "~> 12.0"
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency "rubocop", "0.55"
end
41 changes: 20 additions & 21 deletions lib/jekyll-target-blank.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
module Jekyll
class TargetBlank
BODY_START_TAG = "<body"
OPENING_BODY_TAG_REGEX = %r!<body([^<>]*)>\s*!
OPENING_BODY_TAG_REGEX = %r!<body([^<>]*)>\s*!.freeze

class << self
# Public: Processes the content and updated the external links
Expand Down Expand Up @@ -117,13 +117,9 @@ def configure_adding_additional_css_classes

# Private: Handles the default rel attribute values
def add_default_rel_attributes?
if should_not_include_noopener?
@should_add_noopener = false
end
@should_add_noopener = false if should_not_include_noopener?

if should_not_include_noreferrer?
@should_add_noreferrrer = false
end
@should_add_noreferrrer = false if should_not_include_noreferrer?
end

# Private: Sets any extra rel attribute values
Expand All @@ -142,7 +138,7 @@ def add_css_classes_if_required(link)
if @should_add_css_classes
existing_classes = get_existing_css_classes(link)
existing_classes = " " + existing_classes unless existing_classes.to_s.empty?
link["class"] = @css_classes_to_add + existing_classes
link["class"] = @css_classes_to_add + existing_classes
end
end

Expand All @@ -158,27 +154,30 @@ def add_target_blank_attribute(link)
# link = Nokogiri node.
def add_rel_attributes(link)
rel = ""
if @should_add_noopener
rel = "noopener"
end
rel = add_noopener_to_rel(rel)

if @should_add_noreferrrer
unless rel.empty?
rel += " "
end
rel += " " unless rel.empty?
rel += "noreferrer"
end

if @should_add_extra_rel_attribute_values
unless rel.empty?
rel += " "
end
rel += " " unless rel.empty?
rel += @extra_rel_attribute_values
end

unless rel.empty?
link["rel"] = rel
link["rel"] = rel unless rel.empty?
end

# Private: Adds noopener attribute.
#
# rel = string
def add_noopener_to_rel(rel)
if @should_add_noopener
rel += " " unless rel.empty?
rel += "noopener"
end
rel
end

# Private: Checks if the link is a mailto url.
Expand All @@ -193,7 +192,7 @@ def not_mailto_link?(link)
#
# link - a url.
def external?(link)
if link =~ URI.regexp(%w(http https))
if link&.match?(URI.regexp(%w(http https)))
URI.parse(link).host != URI.parse(@site_url).host
end
end
Expand Down Expand Up @@ -332,6 +331,6 @@ def class_config
end

# Hooks into Jekyll's post_render event.
Jekyll::Hooks.register %i[pages documents], :post_render do |doc|
Jekyll::Hooks.register [:pages, :documents], :post_render do |doc|
Jekyll::TargetBlank.process(doc) if Jekyll::TargetBlank.document_processable?(doc)
end
2 changes: 1 addition & 1 deletion lib/jekyll-target-blank/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module JekyllTargetBlank
VERSION = "1.2.0"
VERSION = "2.0.0"
end
Loading

0 comments on commit f6fb51a

Please sign in to comment.