jekyll-favicon 1.0.0.pre.1 → 1.0.0.pre.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.devcontainer/Dockerfile +1 -1
- data/.devcontainer/devcontainer.json +11 -4
- data/.github/workflows/test.yml +5 -5
- data/.gitignore +1 -2
- 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 +4 -0
- data/Gemfile +1 -1
- data/README.md +3 -3
- data/Rakefile +4 -4
- data/bin/debug +22 -0
- data/jekyll-favicon.gemspec +23 -23
- data/lib/jekyll-favicon.rb +5 -7
- data/lib/jekyll/favicon.rb +13 -16
- data/lib/jekyll/favicon/configuration.rb +11 -11
- data/lib/jekyll/favicon/configuration/defaults.rb +6 -6
- data/lib/jekyll/favicon/generator.rb +5 -6
- data/lib/jekyll/favicon/hooks.rb +4 -4
- data/lib/jekyll/favicon/static_data_file.rb +2 -2
- data/lib/jekyll/favicon/static_file.rb +18 -18
- data/lib/jekyll/favicon/static_file/convertible.rb +30 -27
- data/lib/jekyll/favicon/static_file/mutable.rb +16 -16
- data/lib/jekyll/favicon/static_file/referenceable.rb +2 -2
- data/lib/jekyll/favicon/static_file/sourceable.rb +7 -7
- data/lib/jekyll/favicon/static_file/taggable.rb +8 -14
- data/lib/jekyll/favicon/static_graphic_file.rb +2 -2
- data/lib/jekyll/favicon/tag.rb +9 -10
- data/lib/jekyll/favicon/utils.rb +24 -5
- data/lib/jekyll/favicon/utils/configuration/compact.rb +29 -32
- data/lib/jekyll/favicon/utils/configuration/merge.rb +41 -34
- data/lib/jekyll/favicon/utils/configuration/patch.rb +24 -23
- data/lib/jekyll/favicon/utils/convert.rb +15 -18
- data/lib/jekyll/favicon/utils/tag.rb +44 -28
- data/lib/jekyll/favicon/version.rb +1 -1
- metadata +7 -9
- data/gemfiles/jekyll36.gemfile +0 -6
- data/gemfiles/jekyll37.gemfile +0 -6
- data/gemfiles/jekyll38.gemfile +0 -6
- data/gemfiles/jekyll39.gemfile +0 -6
- data/gemfiles/jekyll40.gemfile +0 -6
- data/gemfiles/jekyll41.gemfile +0 -6
- data/gemfiles/jekyll42.gemfile +0 -6
@@ -1,18 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require "jekyll/plugin"
|
4
|
+
require "jekyll/generator"
|
5
|
+
require "jekyll/favicon"
|
6
6
|
|
7
7
|
module Jekyll
|
8
8
|
module Favicon
|
9
9
|
# New generator that creates all the stastic icons and metadata files
|
10
10
|
class Generator < Jekyll::Generator
|
11
|
-
# :reek:UtilityFunction
|
12
11
|
def generate(site)
|
13
12
|
Favicon.assets(site)
|
14
|
-
|
15
|
-
|
13
|
+
.select(&:generable?)
|
14
|
+
.each { |asset| site.static_files << asset }
|
16
15
|
end
|
17
16
|
end
|
18
17
|
end
|
data/lib/jekyll/favicon/hooks.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "jekyll/hooks"
|
4
4
|
|
5
5
|
Jekyll::Hooks.register :site, :after_init do |site|
|
6
6
|
static_files = Jekyll::Favicon.assets(site)
|
7
|
-
|
8
|
-
excludes = site.config[
|
7
|
+
.uniq(&:path)
|
8
|
+
excludes = site.config["exclude"]
|
9
9
|
static_files.each do |static_file|
|
10
10
|
source = static_file.source_relative_path
|
11
11
|
excludes << source and next if static_file.generable?
|
12
12
|
|
13
13
|
Jekyll.logger.warn Jekyll::Favicon,
|
14
|
-
|
14
|
+
"Missing #{source}, not generating favicons."
|
15
15
|
end
|
16
16
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
3
|
+
require "pathname"
|
4
|
+
require "forwardable"
|
5
|
+
require "jekyll/static_file"
|
6
|
+
require "jekyll/favicon/static_file/sourceable"
|
7
|
+
require "jekyll/favicon/static_file/taggable"
|
8
|
+
require "jekyll/favicon/static_file/referenceable"
|
9
|
+
require "jekyll/favicon/utils"
|
10
|
+
require "jekyll/favicon/configuration"
|
11
11
|
|
12
12
|
module Jekyll
|
13
13
|
module Favicon
|
@@ -23,7 +23,7 @@ module Jekyll
|
|
23
23
|
attr_reader :spec, :site
|
24
24
|
|
25
25
|
def initialize(site, spec = {})
|
26
|
-
raise StandardError unless spec.include?
|
26
|
+
raise StandardError unless spec.include? "name"
|
27
27
|
|
28
28
|
@spec = spec
|
29
29
|
spec_dir, spec_name = File.split spec_relative_path
|
@@ -43,9 +43,9 @@ module Jekyll
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def href
|
46
|
-
Pathname.new(
|
47
|
-
|
48
|
-
|
46
|
+
Pathname.new("/")
|
47
|
+
.join(*[site.baseurl, url].compact)
|
48
|
+
.to_s
|
49
49
|
end
|
50
50
|
|
51
51
|
private
|
@@ -62,11 +62,11 @@ module Jekyll
|
|
62
62
|
end
|
63
63
|
|
64
64
|
def site_dir
|
65
|
-
site_configuration.fetch(
|
65
|
+
site_configuration.fetch("dir", ".")
|
66
66
|
end
|
67
67
|
|
68
68
|
def site_background
|
69
|
-
site_configuration.fetch(
|
69
|
+
site_configuration.fetch("background", "transparent")
|
70
70
|
end
|
71
71
|
|
72
72
|
def site_configuration
|
@@ -80,17 +80,17 @@ module Jekyll
|
|
80
80
|
def spec_relative_pathname
|
81
81
|
return spec_pathname if spec_pathname.relative?
|
82
82
|
|
83
|
-
pathname.relative_path_from
|
83
|
+
pathname.relative_path_from "/"
|
84
84
|
end
|
85
85
|
|
86
86
|
def spec_pathname
|
87
87
|
Pathname.new(site_dir)
|
88
|
-
|
88
|
+
.join(*spec_dir_name)
|
89
89
|
end
|
90
90
|
|
91
91
|
def spec_dir_name
|
92
|
-
spec.values_at(
|
93
|
-
|
92
|
+
spec.values_at("dir", "name")
|
93
|
+
.compact
|
94
94
|
end
|
95
95
|
end
|
96
96
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "jekyll/favicon/configuration/defaults"
|
4
|
+
require "jekyll/favicon/utils"
|
5
5
|
|
6
6
|
module Jekyll
|
7
7
|
module Favicon
|
@@ -24,30 +24,28 @@ module Jekyll
|
|
24
24
|
def convertible_patch(configuration)
|
25
25
|
Utils.patch configuration do |value|
|
26
26
|
case value
|
27
|
-
when :sizes then sizes.join
|
27
|
+
when :sizes then sizes.join " "
|
28
28
|
else value
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
33
|
def sizes
|
34
|
-
if (match =
|
35
|
-
elsif (define = convert_spec[
|
36
|
-
|
37
|
-
elsif (
|
38
|
-
elsif (scale = convert_spec['scale']) then [scale]
|
34
|
+
if (match = Utils.name_to_size(name)) then [match[1]]
|
35
|
+
elsif (define = Utils.define_to_size(convert_spec["define"])) then define
|
36
|
+
elsif (resize = convert_spec["resize"]) then [resize]
|
37
|
+
elsif (scale = convert_spec["scale"]) then [scale]
|
39
38
|
end
|
40
39
|
end
|
41
40
|
|
42
41
|
# Jekyll::StaticFile method
|
43
42
|
# asks if dest mtime is older than source mtime after original modified?
|
44
43
|
def modified?
|
45
|
-
super || self.class.mtimes
|
44
|
+
super || self.class.mtimes.fetch(href, -1) < mtime
|
46
45
|
end
|
47
46
|
|
48
47
|
# Jekyll::StaticFile method
|
49
48
|
# adds dest mtime to list after original write
|
50
|
-
# :reek:ControlParameter
|
51
49
|
def write(dest)
|
52
50
|
super(dest) && self.class.mtimes[href] = mtime
|
53
51
|
end
|
@@ -58,8 +56,8 @@ module Jekyll
|
|
58
56
|
# add file creation instead of copying
|
59
57
|
def copy_file(dest_path)
|
60
58
|
case @extname
|
61
|
-
when
|
62
|
-
when
|
59
|
+
when ".svg" then super(dest_path)
|
60
|
+
when ".ico", ".png"
|
63
61
|
Utils.convert path, dest_path, convert
|
64
62
|
else Jekyll.logger.warn "Jekyll::Favicon: Can't generate " \
|
65
63
|
" #{dest_path}. Extension not supported."
|
@@ -67,46 +65,51 @@ module Jekyll
|
|
67
65
|
end
|
68
66
|
|
69
67
|
def convert_allow_empty?
|
70
|
-
@extname ==
|
68
|
+
@extname == ".svg" && @extname == File.extname(path)
|
71
69
|
end
|
72
70
|
|
73
71
|
def convert_spec
|
74
|
-
spec.fetch
|
72
|
+
spec.fetch "convert", {}
|
73
|
+
end
|
74
|
+
|
75
|
+
def convertible_keys
|
76
|
+
convertible_defaults["defaults"].keys
|
75
77
|
end
|
76
78
|
|
77
79
|
def convert_normalize(options)
|
78
80
|
return {} unless options
|
79
81
|
|
80
|
-
Utils.
|
82
|
+
Utils.slice_and_compact options, convertible_keys
|
81
83
|
end
|
82
84
|
|
83
|
-
def
|
84
|
-
|
85
|
+
def convert_patch(options)
|
86
|
+
patched_options = convert_patch_options options
|
87
|
+
Utils.slice_and_compact patched_options, convertible_keys
|
85
88
|
end
|
86
89
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
options.merge! name => send(method, options[name])
|
90
|
+
def convert_patch_options(options)
|
91
|
+
%w[density extent].each_with_object(options) do |name, memo|
|
92
|
+
method = "convert_patch_option_#{name}".to_sym
|
93
|
+
memo[name] = send(method, options[name])
|
92
94
|
end
|
93
|
-
Utils.compact options.slice(*convertible_defaults['defaults'].keys)
|
94
95
|
end
|
95
96
|
|
96
|
-
def
|
97
|
+
def convert_patch_option_density(density)
|
97
98
|
case density
|
98
99
|
when :max
|
99
|
-
length = sizes.collect { |size| size.split(
|
100
|
+
length = sizes.collect { |size| size.split("x").collect(&:to_i) }
|
101
|
+
.flatten
|
102
|
+
.max
|
100
103
|
length * 3
|
101
104
|
else density
|
102
105
|
end
|
103
106
|
end
|
104
107
|
|
105
|
-
def
|
108
|
+
def convert_patch_option_extent(extent)
|
106
109
|
case extent
|
107
110
|
when :auto
|
108
111
|
if (size = sizes.first)
|
109
|
-
width, height = size.split
|
112
|
+
width, height = size.split "x"
|
110
113
|
size if width != height
|
111
114
|
end
|
112
115
|
else extent
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require "rexml/document"
|
4
|
+
require "jekyll/favicon/utils"
|
5
|
+
require "jekyll/favicon/static_graphic_file"
|
6
6
|
|
7
7
|
module Jekyll
|
8
8
|
module Favicon
|
@@ -15,12 +15,12 @@ module Jekyll
|
|
15
15
|
|
16
16
|
def mutation
|
17
17
|
refers = case @extname
|
18
|
-
when
|
19
|
-
mutation_refers.select { |refer| refer.key?
|
18
|
+
when ".xml"
|
19
|
+
mutation_refers.select { |refer| refer.key? "browserconfig" }
|
20
20
|
else
|
21
|
-
mutation_refers.collect { |refer| refer[
|
22
|
-
|
23
|
-
|
21
|
+
mutation_refers.collect { |refer| refer["webmanifest"] }
|
22
|
+
.compact
|
23
|
+
end
|
24
24
|
patch(Utils.merge(*refers) || {})
|
25
25
|
end
|
26
26
|
|
@@ -41,8 +41,8 @@ module Jekyll
|
|
41
41
|
|
42
42
|
def mutated_content
|
43
43
|
case @extname
|
44
|
-
when
|
45
|
-
when
|
44
|
+
when ".json", ".webmanifest", ".manifest" then mutated_content_json
|
45
|
+
when ".xml" then mutated_content_xml
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -53,7 +53,7 @@ module Jekyll
|
|
53
53
|
|
54
54
|
def mutated_content_xml
|
55
55
|
mutated = Utils.mutate_element (mutable || REXML::Document.new), mutation
|
56
|
-
output =
|
56
|
+
output = +""
|
57
57
|
mutated.write output
|
58
58
|
output
|
59
59
|
end
|
@@ -63,17 +63,17 @@ module Jekyll
|
|
63
63
|
|
64
64
|
content = File.read path
|
65
65
|
case File.extname path
|
66
|
-
when
|
66
|
+
when ".xml" then REXML::Document.new content
|
67
67
|
else JSON.parse content
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
71
|
def mutation_refers
|
72
72
|
site.static_files
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
73
|
+
.select { |static_file| static_file.is_a? StaticFile }
|
74
|
+
.select(&:referenceable?)
|
75
|
+
.collect(&:refer)
|
76
|
+
.flatten
|
77
77
|
end
|
78
78
|
end
|
79
79
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "jekyll/favicon/configuration/defaults"
|
4
4
|
|
5
5
|
module Jekyll
|
6
6
|
module Favicon
|
@@ -14,7 +14,7 @@ module Jekyll
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def refer
|
17
|
-
patch spec.fetch(
|
17
|
+
patch spec.fetch("refer", [])
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "jekyll/favicon/configuration/defaults"
|
4
|
+
require "jekyll/favicon/utils"
|
5
5
|
|
6
6
|
module Jekyll
|
7
7
|
module Favicon
|
@@ -31,7 +31,7 @@ module Jekyll
|
|
31
31
|
case options
|
32
32
|
when String
|
33
33
|
source_dir, source_name = File.split options
|
34
|
-
{
|
34
|
+
{"dir" => source_dir, "name" => source_name}
|
35
35
|
when Hash
|
36
36
|
Utils.compact options
|
37
37
|
else {}
|
@@ -39,15 +39,15 @@ module Jekyll
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def self.source_filter(options)
|
42
|
-
options.fetch
|
42
|
+
options.fetch "source", {}
|
43
43
|
end
|
44
44
|
|
45
45
|
private
|
46
46
|
|
47
47
|
def source_relative_pathname
|
48
|
-
Pathname.new(source[
|
49
|
-
|
50
|
-
|
48
|
+
Pathname.new(source["dir"])
|
49
|
+
.join(source["name"])
|
50
|
+
.cleanpath
|
51
51
|
end
|
52
52
|
|
53
53
|
def source_defaults
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require "rexml/document"
|
4
|
+
require "jekyll/favicon/configuration/defaults"
|
5
|
+
require "jekyll/favicon/utils"
|
6
6
|
|
7
7
|
module Jekyll
|
8
8
|
module Favicon
|
@@ -20,27 +20,21 @@ module Jekyll
|
|
20
20
|
tag_name, tag_options = options.first
|
21
21
|
tag_defaults = taggable_defaults[tag_name]
|
22
22
|
tag_attributes = tag_defaults.merge tag_options
|
23
|
-
|
23
|
+
Utils.build_tag tag_name, patch(tag_attributes)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
private
|
28
28
|
|
29
29
|
def tag_spec
|
30
|
-
spec.fetch
|
31
|
-
end
|
32
|
-
|
33
|
-
# :reek:UtilityFunction
|
34
|
-
def tag_build(name, attributes = {})
|
35
|
-
config = attributes.transform_keys { |key| "_#{key}" }
|
36
|
-
Jekyll::Favicon::Utils.build_element name, nil, config
|
30
|
+
spec.fetch "tag", []
|
37
31
|
end
|
38
32
|
|
39
33
|
def mimetype
|
40
34
|
mappings = {
|
41
|
-
|
42
|
-
|
43
|
-
|
35
|
+
".ico" => "image/x-icon",
|
36
|
+
".png" => "image/png",
|
37
|
+
".svg" => "image/svg+xml"
|
44
38
|
}
|
45
39
|
mappings[extname]
|
46
40
|
end
|
data/lib/jekyll/favicon/tag.rb
CHANGED
@@ -1,24 +1,23 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "liquid"
|
4
|
+
require "jekyll/favicon/static_file"
|
5
5
|
|
6
6
|
module Jekyll
|
7
7
|
module Favicon
|
8
8
|
# New `favicon` tag include html tags on templates
|
9
9
|
class Tag < Liquid::Tag
|
10
|
-
# :reek:UtilityFunction
|
11
10
|
def render(context)
|
12
11
|
context.registers[:site]
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
.static_files
|
13
|
+
.select { |static_file| static_file.is_a? StaticFile }
|
14
|
+
.select(&:taggable?)
|
15
|
+
.collect(&:tags)
|
16
|
+
.flatten
|
17
|
+
.join("\n")
|
19
18
|
end
|
20
19
|
end
|
21
20
|
end
|
22
21
|
end
|
23
22
|
|
24
|
-
Liquid::Template.register_tag(
|
23
|
+
Liquid::Template.register_tag("favicon", Jekyll::Favicon::Tag)
|