jekyll-favicon 0.2.6 → 1.0.0.pre.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.devcontainer/Dockerfile +20 -0
- data/.devcontainer/devcontainer.json +42 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +10 -13
- data/.github/PULL_REQUEST_TEMPLATE.md +11 -9
- data/.github/workflows/gem-push.yml +40 -0
- data/.github/workflows/test.yml +38 -0
- data/.gitignore +4 -0
- data/.reek.yml +25 -0
- data/.vscode/launch.json +16 -0
- data/.vscode/settings.json +7 -0
- data/.vscode/tasks.json +15 -0
- data/CHANGELOG.md +42 -0
- data/Gemfile +3 -1
- data/README.md +80 -20
- data/Rakefile +9 -7
- data/bin/console +1 -0
- data/bin/debug +22 -0
- data/config/jekyll/favicon.yml +115 -0
- data/config/jekyll/favicon/static_file.yml +3 -0
- data/config/jekyll/favicon/static_file/convertible.yml +42 -0
- data/config/jekyll/favicon/static_file/mutable.yml +22 -0
- data/config/jekyll/favicon/static_file/referenceable.yml +15 -0
- data/config/jekyll/favicon/static_file/sourceable.yml +3 -0
- data/config/jekyll/favicon/static_file/taggable.yml +22 -0
- data/jekyll-favicon.gemspec +24 -24
- data/lib/jekyll-favicon.rb +7 -16
- data/lib/jekyll/favicon.rb +19 -16
- data/lib/jekyll/favicon/configuration.rb +73 -0
- data/lib/jekyll/favicon/configuration/defaults.rb +49 -0
- data/lib/jekyll/favicon/generator.rb +10 -74
- data/lib/jekyll/favicon/hooks.rb +12 -10
- data/lib/jekyll/favicon/static_data_file.rb +17 -0
- data/lib/jekyll/favicon/static_file.rb +97 -0
- data/lib/jekyll/favicon/static_file/convertible.rb +121 -0
- data/lib/jekyll/favicon/static_file/mutable.rb +81 -0
- data/lib/jekyll/favicon/static_file/referenceable.rb +22 -0
- data/lib/jekyll/favicon/static_file/sourceable.rb +73 -0
- data/lib/jekyll/favicon/static_file/taggable.rb +53 -0
- data/lib/jekyll/favicon/static_graphic_file.rb +21 -0
- data/lib/jekyll/favicon/tag.rb +14 -17
- data/lib/jekyll/favicon/utils.rb +43 -0
- data/lib/jekyll/favicon/utils/configuration/compact.rb +58 -0
- data/lib/jekyll/favicon/utils/configuration/merge.rb +70 -0
- data/lib/jekyll/favicon/utils/configuration/patch.rb +49 -0
- data/lib/jekyll/favicon/utils/convert.rb +39 -0
- data/lib/jekyll/favicon/utils/tag.rb +70 -0
- data/lib/jekyll/favicon/version.rb +3 -1
- metadata +69 -67
- data/.rubocop.yml +0 -5
- data/.ruby-version +0 -1
- data/.travis.yml +0 -21
- data/Gemfile.lock +0 -97
- data/lib/browserconfig.rb +0 -54
- data/lib/hash.rb +0 -12
- data/lib/image.rb +0 -33
- data/lib/jekyll/favicon/config/defaults.yml +0 -54
- data/lib/jekyll/favicon/icon.rb +0 -73
- data/lib/jekyll/favicon/metadata.rb +0 -12
- data/lib/jekyll/favicon/templates/chrome.html.erb +0 -5
- data/lib/jekyll/favicon/templates/classic.html.erb +0 -8
- data/lib/jekyll/favicon/templates/ie.html.erb +0 -4
- data/lib/jekyll/favicon/templates/safari.html.erb +0 -8
- data/lib/string.rb +0 -14
- data/lib/webmanifest.rb +0 -30
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "jekyll/favicon/configuration/defaults"
|
4
|
+
|
5
|
+
module Jekyll
|
6
|
+
module Favicon
|
7
|
+
class StaticFile < Jekyll::StaticFile
|
8
|
+
# Add reference to a static file
|
9
|
+
module Referenceable
|
10
|
+
include Configuration::Defaults
|
11
|
+
|
12
|
+
def referenceable?
|
13
|
+
refer.any?
|
14
|
+
end
|
15
|
+
|
16
|
+
def refer
|
17
|
+
patch spec.fetch("refer", [])
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "jekyll/favicon/configuration/defaults"
|
4
|
+
require "jekyll/favicon/utils"
|
5
|
+
|
6
|
+
module Jekyll
|
7
|
+
module Favicon
|
8
|
+
class StaticFile < Jekyll::StaticFile
|
9
|
+
# Add source to a static file
|
10
|
+
module Sourceable
|
11
|
+
include Configuration::Defaults
|
12
|
+
|
13
|
+
def sourceable?
|
14
|
+
source.any? && File.file?(path)
|
15
|
+
end
|
16
|
+
|
17
|
+
def source
|
18
|
+
Utils.merge sourceable_defaults, source_site, source_asset
|
19
|
+
end
|
20
|
+
|
21
|
+
# overrides Jekyll::StaticFile method
|
22
|
+
def path
|
23
|
+
File.join(*[@base, source_relative_path].compact)
|
24
|
+
end
|
25
|
+
|
26
|
+
def source_relative_path
|
27
|
+
source_relative_pathname.to_s
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.source_normalize(options)
|
31
|
+
case options
|
32
|
+
when String
|
33
|
+
source_dir, source_name = File.split options
|
34
|
+
{"dir" => source_dir, "name" => source_name}
|
35
|
+
when Hash
|
36
|
+
Utils.compact options
|
37
|
+
else {}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.source_filter(options)
|
42
|
+
options.fetch "source", {}
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def source_relative_pathname
|
48
|
+
Pathname.new(source["dir"])
|
49
|
+
.join(source["name"])
|
50
|
+
.cleanpath
|
51
|
+
end
|
52
|
+
|
53
|
+
def source_defaults
|
54
|
+
sourceable_defaults
|
55
|
+
end
|
56
|
+
|
57
|
+
def source_site
|
58
|
+
site_config = Configuration.merged @site
|
59
|
+
config = Sourceable.source_filter site_config
|
60
|
+
Sourceable.source_normalize config
|
61
|
+
end
|
62
|
+
|
63
|
+
def source_spec
|
64
|
+
Sourceable.source_filter spec
|
65
|
+
end
|
66
|
+
|
67
|
+
def source_asset
|
68
|
+
Sourceable.source_normalize source_spec
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rexml/document"
|
4
|
+
require "jekyll/favicon/configuration/defaults"
|
5
|
+
require "jekyll/favicon/utils"
|
6
|
+
|
7
|
+
module Jekyll
|
8
|
+
module Favicon
|
9
|
+
class StaticFile < Jekyll::StaticFile
|
10
|
+
# Add tags to favicon's static files
|
11
|
+
module Taggable
|
12
|
+
include Configuration::Defaults
|
13
|
+
|
14
|
+
def taggable?
|
15
|
+
tags.any?
|
16
|
+
end
|
17
|
+
|
18
|
+
def tags
|
19
|
+
tag_spec.collect do |options|
|
20
|
+
tag_name, tag_options = options.first
|
21
|
+
tag_defaults = taggable_defaults[tag_name]
|
22
|
+
tag_attributes = tag_defaults.merge tag_options
|
23
|
+
Utils.build_tag tag_name, patch(tag_attributes)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def tag_spec
|
30
|
+
spec.fetch "tag", []
|
31
|
+
end
|
32
|
+
|
33
|
+
def mimetype
|
34
|
+
mappings = {
|
35
|
+
".ico" => "image/x-icon",
|
36
|
+
".png" => "image/png",
|
37
|
+
".svg" => "image/svg+xml"
|
38
|
+
}
|
39
|
+
mappings[extname]
|
40
|
+
end
|
41
|
+
|
42
|
+
def taggable_patch(configuration)
|
43
|
+
Favicon::Utils.patch configuration do |value|
|
44
|
+
case value
|
45
|
+
when :mime then mimetype
|
46
|
+
else value
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "jekyll/favicon/static_file"
|
4
|
+
require "jekyll/favicon/static_file/convertible"
|
5
|
+
|
6
|
+
module Jekyll
|
7
|
+
module Favicon
|
8
|
+
# Favicon::StaticFile subclass
|
9
|
+
class StaticGraphicFile < StaticFile
|
10
|
+
include StaticFile::Convertible
|
11
|
+
|
12
|
+
def generable?
|
13
|
+
convertible? && super
|
14
|
+
end
|
15
|
+
|
16
|
+
def patch(configuration)
|
17
|
+
convertible_patch super(configuration)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/jekyll/favicon/tag.rb
CHANGED
@@ -1,26 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "liquid"
|
4
|
+
require "jekyll/favicon/static_file"
|
5
|
+
|
1
6
|
module Jekyll
|
2
7
|
module Favicon
|
3
|
-
# New `favicon` tag
|
8
|
+
# New `favicon` tag include html tags on templates
|
4
9
|
class Tag < Liquid::Tag
|
5
|
-
def initialize(tag_name, text, tokens)
|
6
|
-
super
|
7
|
-
@text = text
|
8
|
-
end
|
9
|
-
|
10
10
|
def render(context)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
19
|
-
foot = '<!-- End Jekyll Favicon tag -->'
|
20
|
-
[head, body.join("\n"), foot].join("\n")
|
11
|
+
context.registers[:site]
|
12
|
+
.static_files
|
13
|
+
.select { |static_file| static_file.is_a? StaticFile }
|
14
|
+
.select(&:taggable?)
|
15
|
+
.collect(&:tags)
|
16
|
+
.flatten
|
17
|
+
.join("\n")
|
21
18
|
end
|
22
19
|
end
|
23
20
|
end
|
24
21
|
end
|
25
22
|
|
26
|
-
Liquid::Template.register_tag(
|
23
|
+
Liquid::Template.register_tag("favicon", Jekyll::Favicon::Tag)
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "jekyll/favicon/utils/configuration/compact"
|
4
|
+
require "jekyll/favicon/utils/configuration/merge"
|
5
|
+
require "jekyll/favicon/utils/configuration/patch"
|
6
|
+
require "jekyll/favicon/utils/convert"
|
7
|
+
require "jekyll/favicon/utils/tag"
|
8
|
+
|
9
|
+
module Jekyll
|
10
|
+
module Favicon
|
11
|
+
# Favicon utils functions
|
12
|
+
module Utils
|
13
|
+
include Configuration::Compact
|
14
|
+
include Configuration::Merge
|
15
|
+
include Configuration::Patch
|
16
|
+
include Convert
|
17
|
+
include Tag
|
18
|
+
|
19
|
+
def self.except(hash, *keys)
|
20
|
+
hash.reject { |key, _| keys.include? key }
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.define_to_size(define)
|
24
|
+
return unless define
|
25
|
+
|
26
|
+
define.split("=")
|
27
|
+
.last
|
28
|
+
.split(",")
|
29
|
+
.collect { |size| [size, size].join "x" }
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.name_to_size(name)
|
33
|
+
size_in_name_regex = /^.*-(\d+x\d+)\..*$/
|
34
|
+
name.match size_in_name_regex
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.slice_and_compact(hash, keys)
|
38
|
+
compactable = hash.slice(*keys)
|
39
|
+
Utils.compact compactable
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module Favicon
|
5
|
+
module Utils
|
6
|
+
module Configuration
|
7
|
+
# Favicon configuration compact logic
|
8
|
+
module Compact
|
9
|
+
def self.included(klass)
|
10
|
+
klass.extend(ClassMethods)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.compact_deep(compactable)
|
14
|
+
case compactable
|
15
|
+
when Hash then compact_hash compactable
|
16
|
+
when Array then compact_array compactable
|
17
|
+
else compactable
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.compact_hash(hash)
|
22
|
+
compacted_hash = hash.each_with_object({}) do |(key, value), memo|
|
23
|
+
next unless (compacted = compact_deep(value))
|
24
|
+
|
25
|
+
memo[key] = compacted
|
26
|
+
end
|
27
|
+
compact_shallow compacted_hash
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.compact_array(array)
|
31
|
+
compacted_array = array.each_with_object([]) do |value, memo|
|
32
|
+
next unless (compacted = compact_deep(value))
|
33
|
+
|
34
|
+
memo << compacted
|
35
|
+
end
|
36
|
+
compact_shallow compacted_array
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.compact_shallow(compactable)
|
40
|
+
compactable.empty? ? nil : compactable.compact
|
41
|
+
end
|
42
|
+
|
43
|
+
# Nil and empty remove from configurations
|
44
|
+
module ClassMethods
|
45
|
+
def compact(compactable)
|
46
|
+
case compactable
|
47
|
+
when Hash, Array
|
48
|
+
Compact.compact_deep(compactable) || compactable.class[]
|
49
|
+
else
|
50
|
+
compactable
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module Favicon
|
5
|
+
module Utils
|
6
|
+
module Configuration
|
7
|
+
# Favicon configuration merge logic
|
8
|
+
module Merge
|
9
|
+
def self.included(klass)
|
10
|
+
klass.extend(ClassMethods)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.merge_multiple(left = nil, *right_and_or_rest)
|
14
|
+
return left if right_and_or_rest.empty?
|
15
|
+
|
16
|
+
right, *rest = right_and_or_rest
|
17
|
+
merged = merge_pair left, right
|
18
|
+
return merged if rest.empty?
|
19
|
+
|
20
|
+
merge_multiple(merged, *rest)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.merge_pair(left, right)
|
24
|
+
return right if !left || !right || !left.instance_of?(right.class)
|
25
|
+
|
26
|
+
case right
|
27
|
+
when Hash then merge_pair_hash left, right
|
28
|
+
when Array then merge_pair_array left, right
|
29
|
+
else right
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.merge_pair_hash(left_hash, right_hash)
|
34
|
+
left_hash.merge(right_hash) do |_, left_value, right_value|
|
35
|
+
merge_multiple left_value, right_value
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.merge_pair_array(left_array, right_array)
|
40
|
+
joint_array = left_array + right_array
|
41
|
+
joint_array.group_by { |map| merge_group map }
|
42
|
+
.collect { |group, values| merge_collect group, values }
|
43
|
+
.flatten
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.merge_group(map, keys = %w[name dir])
|
47
|
+
map.is_a?(Hash) ? map.values_at(*keys) : []
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.merge_collect(group, values)
|
51
|
+
group.first ? merge_multiple(*values) : values
|
52
|
+
end
|
53
|
+
|
54
|
+
# Merge configurations
|
55
|
+
module ClassMethods
|
56
|
+
def merge(left = nil, *right_and_or_rest)
|
57
|
+
return left if right_and_or_rest.empty?
|
58
|
+
|
59
|
+
right, *rest = right_and_or_rest
|
60
|
+
merged = Merge.merge_pair left, right
|
61
|
+
return merged if rest.empty?
|
62
|
+
|
63
|
+
Merge.merge_multiple(merged, *rest)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module Favicon
|
5
|
+
module Utils
|
6
|
+
module Configuration
|
7
|
+
# Favicon configuration patch logic
|
8
|
+
module Patch
|
9
|
+
def self.included(klass)
|
10
|
+
klass.extend(ClassMethods)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.patch_unknown(value_or_values, &block)
|
14
|
+
patch_method = case value_or_values
|
15
|
+
when Array then :patch_array
|
16
|
+
when Hash then :patch_hash
|
17
|
+
when Symbol, String then :patch_value
|
18
|
+
else return value_or_values
|
19
|
+
end
|
20
|
+
send patch_method, value_or_values, &block
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.patch_array(values, &block)
|
24
|
+
values.collect { |value| patch_unknown value, &block }
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.patch_hash(values, &block)
|
28
|
+
values.transform_values { |value| patch_unknown value, &block }
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.patch_value(value, &block)
|
32
|
+
block.call patch_value_string_symbol(value)
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.patch_value_string_symbol(value)
|
36
|
+
value.to_s.start_with?(":") ? value[1..].to_sym : value
|
37
|
+
end
|
38
|
+
|
39
|
+
# Patch configuration with the block provided
|
40
|
+
module ClassMethods
|
41
|
+
def patch(value_or_values, &block)
|
42
|
+
Patch.patch_unknown value_or_values, &block
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "mini_magick"
|
4
|
+
|
5
|
+
module Jekyll
|
6
|
+
module Favicon
|
7
|
+
module Utils
|
8
|
+
# Favicon convert for include
|
9
|
+
module Convert
|
10
|
+
def self.included(klass)
|
11
|
+
klass.extend(ClassMethods)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.convert_apply(convert, options = {})
|
15
|
+
options.each_with_object(convert) do |(option, value), memo|
|
16
|
+
memo.send option.to_sym, value
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.convert_options(convert, options = {})
|
21
|
+
priorities = %w[resize scale]
|
22
|
+
convert_apply convert, options.slice(*priorities)
|
23
|
+
common_options = options.reject { |key| priorities.include? key }
|
24
|
+
convert_apply convert, common_options
|
25
|
+
end
|
26
|
+
|
27
|
+
# Favicon convert utils functions
|
28
|
+
module ClassMethods
|
29
|
+
def convert(input, output, options = {})
|
30
|
+
MiniMagick::Tool::Convert.new do |convert|
|
31
|
+
convert.flatten
|
32
|
+
Convert.convert_options(convert, options) << input << output
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|