jekyll-gensocial 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ce45a392c7a7483af49f360f0fc7b4b87abe2e554732f241007f597d2a0a56f0
4
+ data.tar.gz: 1e5ab8538cec2f157c62fc43d47b0138c290ee262e1d016e4908c9fb1fd854dc
5
+ SHA512:
6
+ metadata.gz: 5f7def175a5c5c5cd83ee4c3266bd296d2966c5e1e83aaad5043c1ded971d35b56ffabc505d1f2ec4f580b9100817745f6dc5173b3af57c33ab0bd2dae3d55ab
7
+ data.tar.gz: d11c957220e7e479f9852de144cc692ed7035bd5458fd4a9fec43ceeab6c363cabd35cf24d6105270418c33b6e655d5ff41189a864666ad5b58a783ecf1d55dc
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Danger Cove
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,154 @@
1
+ # Jekyll Gensocial
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/jekyll-gensocial.svg)](https://badge.fury.io/rb/jekyll-gensocial)
4
+
5
+ A Jekyll plugin that automatically generates images that will be used when your links are shared on social media.
6
+
7
+ ![An image generated by this plugin](https://raw.githubusercontent.com/boyvanamstel/jekyll-gensocial/master/screenshots/twitter.png)
8
+ _^ Here's an example._
9
+
10
+ ## Installation
11
+
12
+ ### Dependencies
13
+
14
+ First install ImageMagick (and GhostScript if you don't supply your own font):
15
+
16
+ #### macOS
17
+
18
+ ```bash
19
+ brew install pkg-config imagemagick [gs]
20
+ ```
21
+
22
+ Add `gem "jekyll-gensocial"` to the `:jekyll_plugins` group in your `Gemfile`:
23
+
24
+ ```ruby
25
+ # Gemfile
26
+
27
+ group :jekyll_plugins do
28
+ gem "jekyll-gensocial"
29
+ end
30
+ ```
31
+
32
+ #### Linux and Windows
33
+
34
+ _Haven't tried yet. If you have, please submit a PR._
35
+
36
+ ### Jekyll
37
+
38
+ Add these lines to your site's `_config.yml`:
39
+
40
+ ```yml
41
+ # _config.yml
42
+
43
+ plugins:
44
+ - jekyll-gensocial
45
+ ```
46
+
47
+ ## Usage
48
+
49
+ You can customize the image's background layer and text appearance from your `_config.yml`.
50
+
51
+ ```yaml
52
+ # These are the default settings
53
+
54
+ jekyll-gensocial:
55
+ enabled: true # Disables the output
56
+ size: # The size of the overall canvas
57
+ width: 1920
58
+ height: 1080
59
+ background: # The background image
60
+ path: nil
61
+ text:
62
+ string: nil # Overrides the post/page title
63
+ font_path: nil # Path to your custom font
64
+ pointsize: 100 # Font size
65
+ fill: "#000000" # Font color
66
+ rect: # Text will appear inside this frame
67
+ size:
68
+ width: 1600
69
+ height: 500
70
+ origin:
71
+ x: 150
72
+ y: 100
73
+ ```
74
+
75
+ Set the `image` front matter in the posts and pages that you want to generate images for.
76
+
77
+ ```yaml
78
+ # _posts/2020-03-19-macdevsclub.md
79
+
80
+ ---
81
+ layout: post
82
+ title: "Your #1 resource for building, distributing and selling Mac apps. Visit macdevs.club!"
83
+ date: 2020-03-19
84
+ categories: [swift-ui]
85
+ image: assets/img/macdevsclub.jpg
86
+ ---
87
+
88
+ The contents of your post goes here.
89
+ ```
90
+
91
+ After building the site, an image will appear in `[your site's source]/assets/img/macdevsclub.jpg`.
92
+
93
+ The plugin generates images in the source directory per default. This enables post-processors to minify and optimize the files if needed.
94
+
95
+ ### Overrides
96
+
97
+ You can override the default settings on a per post/page basis.
98
+
99
+ ```yaml
100
+ # _posts/2020-03-19-macdevsclub.md
101
+
102
+ ---
103
+ layout: post
104
+ title: "Your #1 resource for building, distributing and selling Mac apps. Visit macdevs.club!"
105
+ date: 2020-03-19
106
+ categories: [swift-ui]
107
+ image: assets/img/macdevsclub.jpg
108
+ jekyll-gensocial:
109
+ text:
110
+ string: "Let's display something else"
111
+ fill: "#ff0000" # And make it red
112
+ ---
113
+
114
+ The contents of your post goes here.
115
+ ```
116
+
117
+ ### Example
118
+
119
+ ```yaml
120
+ # Features a background image, text fill color and custom font
121
+
122
+ jekyll-gensocial:
123
+ background:
124
+ path: "_assets/img/gensocial_bg.jpg"
125
+ text:
126
+ fill: "#2d3748"
127
+ font_path: "_assets/fonts/Lato-Regular.ttf"
128
+ ```
129
+
130
+ ![The settings used by macdevs.club](https://raw.githubusercontent.com/boyvanamstel/jekyll-gensocial/master/screenshots/macdevsclub.jpg)
131
+
132
+ ## Purpose
133
+
134
+ Used in conjuction with the [`jekyll-seo-tag`](https://github.com/jekyll/jekyll-seo-tag) plugin, this automatically improves how your links look when shared online.
135
+
136
+ Instead of having to create a new image for every page and post, why not automate the process.
137
+
138
+ ## Development
139
+
140
+ After checking out the repo, run `script/bootstrap` to install dependencies. Then, run `bundle exec rake spec` to run the tests.
141
+
142
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `lib/jekyll-gensocial/version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
143
+
144
+ ## Contributing
145
+
146
+ Bug reports and pull requests are welcome on GitHub at https://github.com/boyvanamstel/jekyll-gensocial. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to behave appropriately.
147
+
148
+ ### Stuff to work on
149
+
150
+ * Expand testing to verify image output.
151
+
152
+ ## License
153
+
154
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "jekyll"
4
+ require "jekyll-gensocial/version"
5
+ require "jekyll-gensocial/generator"
6
+ require "jekyll-gensocial/geometry"
7
+ require "jekyll-gensocial/image_creator"
8
+
9
+ module Jekyll
10
+ module Gensocial
11
+ DEFAULTS = {
12
+ "enabled" => true,
13
+ "size" => {
14
+ "width" => 1920,
15
+ "height" => 1080
16
+ },
17
+ "background" => {
18
+ "path" => nil
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
37
+ end
38
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Gensocial
5
+ class Generator < Jekyll::Generator
6
+ safe true
7
+ priority :lowest
8
+
9
+ def generate(site)
10
+ config = Utils.deep_merge_hashes(Gensocial::DEFAULTS, site.config.fetch("jekyll-gensocial", {}))
11
+
12
+ return unless config["enabled"] == true
13
+
14
+ process_docs(site.pages, site: site, config: config)
15
+ process_docs(site.posts.docs, site: site, config: config)
16
+ end
17
+
18
+ private
19
+
20
+ def process_docs(docs, site:, config:)
21
+ docs.each do |doc|
22
+ doc_config = Utils.deep_merge_hashes(config, doc.data.fetch("jekyll-gensocial", {}))
23
+
24
+ image_size = Geometry::Size.new(doc_config["size"])
25
+ text_config = ImageCreator::TextLayerConfig.new(doc_config["text"], base_path: site.source)
26
+ bg_config = ImageCreator::BackgroundLayerConfig.new(doc_config["background"], base_path: site.source)
27
+
28
+ text = doc.data["title"] || text_config.string
29
+ image_path = doc.data["image"]
30
+
31
+ next if text.nil? || image_path.nil?
32
+
33
+ write_image(
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
+ )
40
+
41
+ base = site.source
42
+ dir = File.dirname(image_path)
43
+ name = File.basename(image_path)
44
+
45
+ site.static_files << Jekyll::StaticFile.new(site, base, dir, name)
46
+ end
47
+ end
48
+
49
+ def write_image(path:, text:, image_size:, text_config: , bg_config:)
50
+ image = get_image_creator(
51
+ text: text,
52
+ image_size: image_size,
53
+ bg_config: bg_config,
54
+ text_config: text_config
55
+ ).image
56
+
57
+ image.write(path)
58
+ end
59
+
60
+ def get_image_creator(text:, image_size:, bg_config:, text_config:)
61
+ image_creator = ImageCreator::Composer.new(image_size: image_size)
62
+ image_creator.add_bg_layer(config: bg_config)
63
+ image_creator.add_text_layer(text, config: text_config)
64
+
65
+ image_creator
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Gensocial
5
+ module Geometry
6
+ Size = Struct.new(:width, :height, keyword_init: true)
7
+ Point = Struct.new(:x, :y, keyword_init: true)
8
+
9
+ class Rect
10
+ attr_reader :size, :origin
11
+
12
+ def initialize(hash)
13
+ @size = Size.new(hash["size"])
14
+ @origin = Point.new(hash["origin"])
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "image_creator/background_layer_config"
4
+ require_relative "image_creator/text_layer_config"
5
+ require_relative "image_creator/composer"
6
+
7
+ module Jekyll
8
+ module Gensocial
9
+ module ImageCreator
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Gensocial
5
+ module ImageCreator
6
+ class BackgroundLayerConfig
7
+ attr_reader :path
8
+
9
+ def initialize(hash, base_path:)
10
+ @path = File.join(base_path, hash["path"]) unless hash["path"].nil?
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rmagick'
4
+ include Magick
5
+
6
+ module Jekyll
7
+ module Gensocial
8
+ module ImageCreator
9
+ class Composer
10
+ attr_reader :image
11
+
12
+ def initialize(image_size:)
13
+ @image_size = image_size
14
+ @image = Image.new(image_size.width, image_size.height)
15
+ end
16
+
17
+ def add_bg_layer(config:)
18
+ return if config.path.nil?
19
+
20
+ bg_layer = Image.read(config.path)
21
+ .first
22
+ .resize_to_fill(@image_size.width, @image_size.height)
23
+
24
+ @image.composite!(bg_layer, CenterGravity, OverCompositeOp)
25
+ end
26
+
27
+ def add_text_layer(text, config:)
28
+ origin = config.rect.origin
29
+ size = config.rect.size
30
+
31
+ text_layer = Magick::Image.read("caption:#{text}") {
32
+ self.fill = config.fill
33
+ self.font = config.font_path unless config.font_path.nil?
34
+ self.pointsize = config.pointsize
35
+ self.size = "#{size.width}x#{size.height}"
36
+ self.background_color = "none"
37
+ }.first
38
+
39
+ @image.composite!(text_layer, NorthWestGravity, origin.x, origin.y, OverCompositeOp)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Gensocial
5
+ module ImageCreator
6
+ class TextLayerConfig
7
+ attr_reader :string, :font_path, :pointsize, :fill, :rect
8
+
9
+ def initialize(hash, base_path:)
10
+ @string = hash["string"]
11
+ @font_path = File.join(base_path, hash["font_path"]) unless hash["font_path"].nil?
12
+ @pointsize = hash["pointsize"]
13
+ @fill = hash["fill"]
14
+ @rect = Geometry::Rect.new(hash["rect"])
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Gensocial
5
+ VERSION = "1.0.0"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-gensocial
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Boy van Amstel
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-04-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jekyll
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.3'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '3.3'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: rmagick
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 4.1.1
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: 4.1.1
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: 2.1.2
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: 2.1.2
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '13.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '13.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rspec
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '3.0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '3.0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rubocop-jekyll
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: 0.11.0
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: 0.11.0
103
+ description:
104
+ email:
105
+ executables: []
106
+ extensions: []
107
+ extra_rdoc_files: []
108
+ files:
109
+ - LICENSE
110
+ - README.md
111
+ - lib/jekyll-gensocial.rb
112
+ - lib/jekyll-gensocial/generator.rb
113
+ - lib/jekyll-gensocial/geometry.rb
114
+ - lib/jekyll-gensocial/image_creator.rb
115
+ - lib/jekyll-gensocial/image_creator/background_layer_config.rb
116
+ - lib/jekyll-gensocial/image_creator/composer.rb
117
+ - lib/jekyll-gensocial/image_creator/text_layer_config.rb
118
+ - lib/jekyll-gensocial/version.rb
119
+ homepage: https://www.github.com/boyvanamstel/jekyll-gensocial
120
+ licenses:
121
+ - MIT
122
+ metadata:
123
+ source_code_uri: https://www.github.com/boyvanamstel/jekyll-gensocial
124
+ changelog_uri: https://www.github.com/boyvanamstel/jekyll-gensocial
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '2.7'
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubygems_version: 3.1.2
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: A plugin for Jekyll to easily generate sharable images for your posts.
144
+ test_files: []