jekyll-gensocial 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef354c90190e2f2f97135142004b6f22120202d5aeb186fc434b53fd9d090f6e
|
4
|
+
data.tar.gz: e2530f8c7ec966fb98a4dc86ca91dfc25aee937db78e5e1cfb906bb2ddaf9ce8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebc55a209be45bdef4f0210109a15af9f8f6e123e422cc54eb9379c2a08eed80dd2eee9bb744a5242b32d04126953c6c21e9a1c7f02254a9d2581fc17630a673
|
7
|
+
data.tar.gz: 8d1399f1fcf76c0efb0c2020e4b0edef2ff6e452c90e6627a01adf9fc47ba5f896bfa817235ba8797ddb0ac62a0bb5210286427fb7fee95699757b8cd3cf46db
|
@@ -7,12 +7,15 @@ module Jekyll
|
|
7
7
|
priority :lowest
|
8
8
|
|
9
9
|
def generate(site)
|
10
|
-
config = Utils.deep_merge_hashes(
|
10
|
+
config = Utils.deep_merge_hashes(
|
11
|
+
Gensocial::DEFAULTS,
|
12
|
+
site.config.fetch("jekyll-gensocial", {})
|
13
|
+
)
|
11
14
|
|
12
15
|
return unless config["enabled"] == true
|
13
16
|
|
14
|
-
process_docs(site.pages, site
|
15
|
-
process_docs(site.posts.docs, site
|
17
|
+
process_docs(site.pages, :site => site, :config => config)
|
18
|
+
process_docs(site.posts.docs, :site => site, :config => config)
|
16
19
|
end
|
17
20
|
|
18
21
|
private
|
@@ -20,47 +23,58 @@ module Jekyll
|
|
20
23
|
def process_docs(docs, site:, config:)
|
21
24
|
docs.each do |doc|
|
22
25
|
doc_config = Utils.deep_merge_hashes(config, doc.data.fetch("jekyll-gensocial", {}))
|
26
|
+
process_doc(doc, :site => site, :config => doc_config)
|
27
|
+
end
|
28
|
+
end
|
23
29
|
|
24
|
-
|
25
|
-
|
26
|
-
|
30
|
+
def image_config(config, base_path:)
|
31
|
+
{
|
32
|
+
:size => Geometry::Size.new(config["size"]),
|
33
|
+
:text => ImageCreator::TextLayerConfig.new(
|
34
|
+
config["text"],
|
35
|
+
:base_path => base_path
|
36
|
+
),
|
37
|
+
:bg => ImageCreator::BackgroundLayerConfig.new(
|
38
|
+
config["background"],
|
39
|
+
:base_path => base_path
|
40
|
+
),
|
41
|
+
}
|
42
|
+
end
|
27
43
|
|
28
|
-
|
29
|
-
|
44
|
+
def process_doc(doc, site:, config:)
|
45
|
+
image_config = image_config(config, :base_path => site.source)
|
30
46
|
|
31
|
-
|
47
|
+
text = doc.data["title"] || image_config[:text].string
|
48
|
+
image_path = doc.data["image"]
|
32
49
|
|
33
|
-
|
34
|
-
path: site.in_source_dir(image_path),
|
35
|
-
text: text,
|
36
|
-
image_size: image_size,
|
37
|
-
text_config: text_config,
|
38
|
-
bg_config: bg_config
|
39
|
-
)
|
50
|
+
return if text.nil? || image_path.nil?
|
40
51
|
|
41
|
-
|
42
|
-
|
43
|
-
|
52
|
+
write_image(
|
53
|
+
:path => site.in_source_dir(image_path),
|
54
|
+
:text => text,
|
55
|
+
:image_config => image_config
|
56
|
+
)
|
44
57
|
|
45
|
-
|
46
|
-
|
58
|
+
base = site.source
|
59
|
+
dir = File.dirname(image_path)
|
60
|
+
name = File.basename(image_path)
|
61
|
+
|
62
|
+
site.static_files << Jekyll::StaticFile.new(site, base, dir, name)
|
47
63
|
end
|
48
64
|
|
49
|
-
def write_image(path:, text:,
|
65
|
+
def write_image(path:, text:, image_config:)
|
50
66
|
image = get_image_creator(
|
51
|
-
text
|
52
|
-
|
53
|
-
bg_config: bg_config,
|
54
|
-
text_config: text_config
|
67
|
+
:text => text,
|
68
|
+
:image_config => image_config
|
55
69
|
).image
|
56
70
|
|
57
71
|
image.write(path)
|
58
72
|
end
|
59
73
|
|
60
|
-
def get_image_creator(text:,
|
61
|
-
image_creator = ImageCreator::Composer.new(image_size:
|
62
|
-
image_creator.add_bg_layer(config:
|
63
|
-
image_creator.add_text_layer(text, config:
|
74
|
+
def get_image_creator(text:, image_config:)
|
75
|
+
image_creator = ImageCreator::Composer.new(:image_size => image_config[:size])
|
76
|
+
image_creator.add_bg_layer(:config => image_config[:bg])
|
77
|
+
image_creator.add_text_layer(text, :config => image_config[:text])
|
64
78
|
|
65
79
|
image_creator
|
66
80
|
end
|
@@ -3,8 +3,8 @@
|
|
3
3
|
module Jekyll
|
4
4
|
module Gensocial
|
5
5
|
module Geometry
|
6
|
-
Size = Struct.new(:width, :height, keyword_init
|
7
|
-
Point = Struct.new(:x, :y, keyword_init
|
6
|
+
Size = Struct.new(:width, :height, :keyword_init => true)
|
7
|
+
Point = Struct.new(:x, :y, :keyword_init => true)
|
8
8
|
|
9
9
|
class Rect
|
10
10
|
attr_reader :size, :origin
|
@@ -1,12 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
include Magick
|
3
|
+
require "rmagick"
|
5
4
|
|
6
5
|
module Jekyll
|
7
6
|
module Gensocial
|
8
7
|
module ImageCreator
|
9
8
|
class Composer
|
9
|
+
include Magick
|
10
10
|
attr_reader :image
|
11
11
|
|
12
12
|
def initialize(image_size:)
|
@@ -28,13 +28,13 @@ module Jekyll
|
|
28
28
|
origin = config.rect.origin
|
29
29
|
size = config.rect.size
|
30
30
|
|
31
|
-
text_layer = Magick::Image.read("caption:#{text}")
|
31
|
+
text_layer = Magick::Image.read("caption:#{text}") do
|
32
32
|
self.fill = config.fill
|
33
33
|
self.font = config.font_path unless config.font_path.nil?
|
34
34
|
self.pointsize = config.pointsize
|
35
35
|
self.size = "#{size.width}x#{size.height}"
|
36
36
|
self.background_color = "none"
|
37
|
-
|
37
|
+
end.first
|
38
38
|
|
39
39
|
@image.composite!(text_layer, NorthWestGravity, origin.x, origin.y, OverCompositeOp)
|
40
40
|
end
|
data/lib/jekyll-gensocial.rb
CHANGED
@@ -8,31 +8,33 @@ require "jekyll-gensocial/image_creator"
|
|
8
8
|
|
9
9
|
module Jekyll
|
10
10
|
module Gensocial
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
# rubocop:disable Layout/HashAlignment
|
12
|
+
DEFAULTS = {
|
13
|
+
"enabled" => true,
|
14
|
+
"size" => {
|
15
|
+
"width" => 1920,
|
16
|
+
"height" => 1080,
|
17
|
+
},
|
18
|
+
"background" => {
|
19
|
+
"path" => nil,
|
20
|
+
},
|
21
|
+
"text" => {
|
22
|
+
"string" => nil,
|
23
|
+
"font_path" => nil,
|
24
|
+
"pointsize" => 100,
|
25
|
+
"fill" => "#000000",
|
26
|
+
"rect" => {
|
27
|
+
"size" => {
|
28
|
+
"width" => 1600,
|
29
|
+
"height" => 500,
|
30
|
+
},
|
31
|
+
"origin" => {
|
32
|
+
"x" => 150,
|
33
|
+
"y" => 100,
|
34
|
+
},
|
16
35
|
},
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
"text" => {
|
21
|
-
"string" => nil,
|
22
|
-
"font_path" => nil,
|
23
|
-
"pointsize" => 100,
|
24
|
-
"fill" => "#000000",
|
25
|
-
"rect" => {
|
26
|
-
"size" => {
|
27
|
-
"width" => 1600,
|
28
|
-
"height" => 500,
|
29
|
-
},
|
30
|
-
"origin" => {
|
31
|
-
"x" => 150,
|
32
|
-
"y" => 100
|
33
|
-
}
|
34
|
-
}
|
35
|
-
}
|
36
|
-
}.freeze
|
36
|
+
},
|
37
|
+
}.freeze
|
38
|
+
# rubocop:enable Layout/HashAlignment
|
37
39
|
end
|
38
40
|
end
|