jekyll-og-image 1.4.1 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +5 -3
- data/lib/jekyll_og_image/configuration.rb +4 -0
- data/lib/jekyll_og_image/generator.rb +87 -34
- data/lib/jekyll_og_image/version.rb +1 -1
- metadata +17 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 260918d98e574361037584e4d0d4097dd41fdcd3526386d3abfde00e2dc4b0f6
|
4
|
+
data.tar.gz: e0c75eec8ddb3f3911aac2ef2b45687ecc1bb036057ed183802570a82f1a4922
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16f6da984ff3821513fdfd51eb9beb06e45bfb76c4530464ebc2f7d9164985a4583ec894258580ea125aed96b9ea489acc55332adc920cfda64e7f9f4c7ec3ee
|
7
|
+
data.tar.gz: eb147ebfeb11d50a80370ced4b82b33c1b33730c6b087c3eddc2871b6aed570dac8014cd01f687711b4f316cdf51bb9cf37cbb8eb82b58e048bafa8f3a21bcac
|
data/README.md
CHANGED
@@ -11,7 +11,7 @@ A Jekyll plugin to automatically generate open graph images for posts.
|
|
11
11
|
Add this line to your site's Gemfile:
|
12
12
|
|
13
13
|
```ruby
|
14
|
-
gem 'jekyll-
|
14
|
+
gem 'jekyll-og-image'
|
15
15
|
```
|
16
16
|
|
17
17
|
And then add this line to your site's `_config.yml`:
|
@@ -32,10 +32,11 @@ The plugin can be configured in the `_config.yml` file or in the post's front ma
|
|
32
32
|
|
33
33
|
The following configuration options are available:
|
34
34
|
|
35
|
-
* `
|
35
|
+
* `collections` - An array specifying which types of collections to generate images for. Supports `"posts"`, `"pages"`, and the names of any custom collections. Default: `["posts"]`
|
36
36
|
|
37
|
-
* `
|
37
|
+
* `output_dir` – The directory where the generated images will be saved. Images will be placed in subdirectories named after their collection type (e.g., `assets/images/og/posts`, `assets/images/og/pages`). Default: `assets/images/og`
|
38
38
|
|
39
|
+
* `force` – If set to `true`, the plugin will generate an image for every document, even if the document already has an image. Default: `false`
|
39
40
|
* `verbose` – If set to `true`, the plugin will output additional information about the image generation process. Default: `false`
|
40
41
|
|
41
42
|
* `skip_drafts` – If set to `true`, the plugin will skip post drafts when generating images. Default: `true`
|
@@ -71,6 +72,7 @@ For a side wide level configuration, edit your `_config.yml`, for a post level c
|
|
71
72
|
```yaml
|
72
73
|
# _config.yml
|
73
74
|
og_image:
|
75
|
+
collections: ["posts", "pages"]
|
74
76
|
output_dir: "assets/images/og"
|
75
77
|
domain: "igor.works"
|
76
78
|
border_bottom:
|
@@ -4,50 +4,93 @@ class JekyllOgImage::Generator < Jekyll::Generator
|
|
4
4
|
safe true
|
5
5
|
|
6
6
|
def generate(site)
|
7
|
-
|
7
|
+
config = JekyllOgImage.config
|
8
8
|
|
9
|
-
|
9
|
+
config.collections.each do |type|
|
10
|
+
process_collection(site, type, config)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def process_collection(site, type, config)
|
17
|
+
Jekyll.logger.info "Jekyll Og Image:", "Processing type: #{type}" if config.verbose?
|
10
18
|
|
11
|
-
site
|
12
|
-
|
19
|
+
items = get_items_for_collection(site, type)
|
20
|
+
return if items.empty?
|
13
21
|
|
14
|
-
|
22
|
+
base_output_dir = File.join(config.output_dir, type)
|
23
|
+
absolute_output_dir = File.join(site.config["source"], base_output_dir)
|
24
|
+
FileUtils.mkdir_p absolute_output_dir
|
15
25
|
|
16
|
-
|
17
|
-
|
18
|
-
|
26
|
+
items.each do |item|
|
27
|
+
if item.respond_to?(:draft?) && item.draft? && config.skip_drafts?
|
28
|
+
Jekyll.logger.info "Jekyll Og Image:", "Skipping draft: #{item.data['title']}" if config.verbose?
|
29
|
+
next
|
30
|
+
end
|
31
|
+
|
32
|
+
fallback_basename = if item.respond_to?(:basename_without_ext)
|
33
|
+
item.basename_without_ext
|
34
|
+
# rubocop:disable Layout/ElseAlignment # Disabled due to RuboCop error in v3.3.0
|
35
|
+
else
|
36
|
+
# rubocop:enable Layout/ElseAlignment
|
37
|
+
File.basename(item.name, File.extname(item.name))
|
38
|
+
end
|
39
|
+
slug = item.data["slug"] || Jekyll::Utils.slugify(item.data["title"] || fallback_basename)
|
40
|
+
image_filename = "#{slug}.png"
|
41
|
+
absolute_image_path = File.join(absolute_output_dir, image_filename)
|
42
|
+
relative_image_path = File.join("/", base_output_dir, image_filename) # Use leading slash for URL
|
43
|
+
|
44
|
+
if !File.exist?(absolute_image_path) || config.force?
|
45
|
+
Jekyll.logger.info "Jekyll Og Image:", "Generating image #{absolute_image_path}" if config.verbose?
|
46
|
+
generate_image_for_document(site, item, absolute_image_path, config)
|
19
47
|
else
|
20
|
-
Jekyll.logger.info "Jekyll Og Image:", "Skipping image generation #{
|
48
|
+
Jekyll.logger.info "Jekyll Og Image:", "Skipping image generation for #{relative_image_path} as it already exists." if config.verbose?
|
21
49
|
end
|
22
50
|
|
23
|
-
|
24
|
-
"path" =>
|
51
|
+
item.data["image"] ||= {
|
52
|
+
"path" => relative_image_path,
|
25
53
|
"width" => 1200,
|
26
54
|
"height" => 600,
|
27
|
-
"alt" =>
|
55
|
+
"alt" => item.data["title"]
|
28
56
|
}
|
29
57
|
end
|
30
58
|
end
|
31
59
|
|
32
|
-
|
60
|
+
def get_items_for_collection(site, type)
|
61
|
+
case type
|
62
|
+
when "posts"
|
63
|
+
site.posts.docs
|
64
|
+
when "pages"
|
65
|
+
site.pages.reject { |page| !page.html? }
|
66
|
+
else
|
67
|
+
if site.collections.key?(type)
|
68
|
+
site.collections[type].docs
|
69
|
+
else
|
70
|
+
Jekyll.logger.warn "Jekyll Og Image:", "Unknown collection type \"#{type}\" configured. Skipping."
|
71
|
+
[]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
33
75
|
|
34
|
-
def
|
35
|
-
config =
|
76
|
+
def generate_image_for_document(site, item, path, base_config)
|
77
|
+
config = base_config.merge!(item.data["og_image"] || {})
|
36
78
|
|
37
79
|
canvas = generate_canvas(site, config)
|
38
80
|
canvas = add_border_bottom(canvas, config) if config.border_bottom
|
39
81
|
canvas = add_image(canvas, File.read(File.join(site.config["source"], config.image))) if config.image
|
40
|
-
canvas = add_header(canvas,
|
41
|
-
canvas = add_publish_date(canvas,
|
42
|
-
canvas = add_tags(canvas,
|
43
|
-
canvas = add_domain(canvas,
|
82
|
+
canvas = add_header(canvas, item, config)
|
83
|
+
canvas = add_publish_date(canvas, item, config)
|
84
|
+
canvas = add_tags(canvas, item, config) if item.data["tags"]&.any?
|
85
|
+
canvas = add_domain(canvas, item, config) if config.domain
|
44
86
|
|
45
87
|
canvas.save(path)
|
46
88
|
end
|
47
89
|
|
48
90
|
def generate_canvas(site, config)
|
49
91
|
background_image = if config.canvas.background_image
|
50
|
-
File.
|
92
|
+
bg_path = File.join(site.config["source"], config.canvas.background_image.gsub(/^\//, ""))
|
93
|
+
File.exist?(bg_path) ? File.read(bg_path) : nil
|
51
94
|
end
|
52
95
|
|
53
96
|
JekyllOgImage::Element::Canvas.new(1200, 600,
|
@@ -72,8 +115,9 @@ class JekyllOgImage::Generator < Jekyll::Generator
|
|
72
115
|
) { |_canvas, _text| { x: 80, y: 100 } }
|
73
116
|
end
|
74
117
|
|
75
|
-
def add_header(canvas,
|
76
|
-
|
118
|
+
def add_header(canvas, item, config)
|
119
|
+
title = item.data["title"] || "Untitled"
|
120
|
+
canvas.text(title,
|
77
121
|
width: config.image ? 870 : 1040,
|
78
122
|
color: config.header.color,
|
79
123
|
dpi: 400,
|
@@ -81,19 +125,25 @@ class JekyllOgImage::Generator < Jekyll::Generator
|
|
81
125
|
) { |_canvas, _text| { x: 80, y: 100 } }
|
82
126
|
end
|
83
127
|
|
84
|
-
def add_publish_date(canvas,
|
85
|
-
|
128
|
+
def add_publish_date(canvas, item, config)
|
129
|
+
return canvas unless item.respond_to?(:date) && item.date
|
130
|
+
|
131
|
+
date = item.date.strftime("%B %d, %Y")
|
132
|
+
y_pos = (item.data["tags"]&.any? ? config.margin_bottom + 50 : config.margin_bottom)
|
86
133
|
|
87
134
|
canvas.text(date,
|
88
135
|
gravity: :sw,
|
89
136
|
color: config.content.color,
|
90
137
|
dpi: 150,
|
91
138
|
font: config.content.font_family
|
92
|
-
) { |_canvas, _text| { x: 80, y:
|
139
|
+
) { |_canvas, _text| { x: 80, y: y_pos } }
|
93
140
|
end
|
94
141
|
|
95
|
-
def add_tags(canvas,
|
96
|
-
|
142
|
+
def add_tags(canvas, item, config)
|
143
|
+
tags_list = item.data["tags"]
|
144
|
+
return canvas unless tags_list.is_a?(Array) && tags_list.any?
|
145
|
+
|
146
|
+
tags = tags_list.map { |tag| "##{tag}" }.join(" ")
|
97
147
|
|
98
148
|
canvas.text(tags,
|
99
149
|
gravity: :sw,
|
@@ -103,17 +153,20 @@ class JekyllOgImage::Generator < Jekyll::Generator
|
|
103
153
|
) { |_canvas, _text| { x: 80, y: config.margin_bottom } }
|
104
154
|
end
|
105
155
|
|
106
|
-
def add_domain(canvas,
|
156
|
+
def add_domain(canvas, item, config)
|
157
|
+
y_pos = if item.data["tags"]&.any?
|
158
|
+
config.margin_bottom + 50
|
159
|
+
# rubocop:disable Layout/ElseAlignment # Disabled due to RuboCop error in v3.3.0
|
160
|
+
else
|
161
|
+
# rubocop:enable Layout/ElseAlignment
|
162
|
+
config.margin_bottom
|
163
|
+
end
|
164
|
+
|
107
165
|
canvas.text(config.domain,
|
108
166
|
gravity: :se,
|
109
167
|
color: config.content.color,
|
110
168
|
dpi: 150,
|
111
169
|
font: config.content.font_family
|
112
|
-
)
|
113
|
-
{
|
114
|
-
x: 80,
|
115
|
-
y: post.data["tags"].any? ? config.margin_bottom + 50 : config.margin_bottom
|
116
|
-
}
|
117
|
-
end
|
170
|
+
) { |_canvas, _text| { x: 80, y: y_pos } }
|
118
171
|
end
|
119
172
|
end
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-og-image
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Alexandrov
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: jekyll-seo-tag
|
@@ -72,7 +71,20 @@ dependencies:
|
|
72
71
|
- - "<"
|
73
72
|
- !ruby/object:Gem::Version
|
74
73
|
version: '5.0'
|
75
|
-
|
74
|
+
- !ruby/object:Gem::Dependency
|
75
|
+
name: csv
|
76
|
+
requirement: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
type: :development
|
82
|
+
prerelease: false
|
83
|
+
version_requirements: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
76
88
|
email:
|
77
89
|
- igor.alexandrov@gmail.com
|
78
90
|
executables: []
|
@@ -104,7 +116,6 @@ licenses:
|
|
104
116
|
- MIT
|
105
117
|
metadata:
|
106
118
|
homepage_uri: https://github.com/igor-alexandrov/jekyll-og-image
|
107
|
-
post_install_message:
|
108
119
|
rdoc_options: []
|
109
120
|
require_paths:
|
110
121
|
- lib
|
@@ -119,8 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
130
|
- !ruby/object:Gem::Version
|
120
131
|
version: '0'
|
121
132
|
requirements: []
|
122
|
-
rubygems_version: 3.
|
123
|
-
signing_key:
|
133
|
+
rubygems_version: 3.6.7
|
124
134
|
specification_version: 4
|
125
135
|
summary: Jekyll plugin to generate GitHub-style open graph images
|
126
136
|
test_files: []
|