middleman-social_image 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +8 -3
- data/lib/middleman-social_image/converter.rb +6 -11
- data/lib/middleman-social_image/extension.rb +1 -2
- data/lib/middleman-social_image/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b33a5a00bdde76bcf00c4c872bcc525e691874adf5bd95a12d92e52f38974e4
|
4
|
+
data.tar.gz: 992ac18e68e3f25e9f9bd8c1ef0b3af7a253e75aef05a442b63ed6278a769323
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86ea9bb9a3bb9759e770e1633058c2390594096d182fd68b221c3e67abf0b8fa95800cce97ac0b3eb23a2dc1623cc3c89e451be6b11a12a80c0faa50bb2cff44
|
7
|
+
data.tar.gz: ab6aaf979d769b23ec82ee5d056fd7d6f604b7f298d088472b4ef32a824602ba58555e2f867ff53d466f93f44b978b5ca9e3b42f325c6f7fa4f2e66dbf98e668
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
# Middleman::SocialImage
|
2
2
|
|
3
|
-
Use HTML and CSS to
|
3
|
+
Use HTML and CSS to generate images when building your Middleman site. The intended use case is for generating images for use with [the Open Graph protocol](https://ogp.me/), which will be included when someone shares your page on Facebook, Twitter, etc.
|
4
|
+
|
5
|
+
Example of an image generated with this extension:
|
6
|
+
|
7
|
+
![](https://www.tokyodev.com/2020/05/29/generating-social-images-with-static-site-generators/social-image-714b5c6e.png)
|
8
|
+
|
9
|
+
For more background, see [generating social images with static site generators](https://www.tokyodev.com/2020/05/29/generating-social-images-with-static-site-generators/).
|
4
10
|
|
5
11
|
## Installation
|
6
12
|
|
@@ -26,7 +32,6 @@ Optionally, you can configure this extension with the following (defaults are sh
|
|
26
32
|
activate :social_image do |social_image|
|
27
33
|
social_image.window_size = '1200,600' # The size of the screenshot
|
28
34
|
social_image.selector = 'body > *' # Used to test that the social image url has loaded properly. The more specific this is, the better the chance of catching errors.
|
29
|
-
social_image.always_generate = true # Always regenerate images. Takes a long time, but ensures any changes are reflected.
|
30
35
|
social_image.parallel = true # Generate images in parallel.
|
31
36
|
social_image.base_url = "http://localhost:4567/" # When building the site, fetch against this URL.
|
32
37
|
end
|
@@ -42,4 +47,4 @@ end
|
|
42
47
|
|
43
48
|
You can now refer to this image as normal within your middleman application.
|
44
49
|
|
45
|
-
In preview mode, you don't need any other special setup. However, to generate the images in build, you also need to be running the preview server. While you can use `bundle exec middleman server`, using a concurrent server like puma can speed up the generation incredibly.
|
50
|
+
In preview mode, you don't need any other special setup. However, to generate the images in build, you also need to be running the preview server. While you can use `bundle exec middleman server`, using a concurrent server like puma can speed up the generation incredibly. To do this, you'll need to [create a config.ru file](https://middlemanapp.com/basics/start-new-site/#config-ru).
|
@@ -1,10 +1,9 @@
|
|
1
1
|
require "middleman-social_image/capybara"
|
2
2
|
class Middleman::SocialImage::Converter
|
3
|
-
def initialize(app, window_size, selector,
|
3
|
+
def initialize(app, window_size, selector, base_url)
|
4
4
|
@app = app
|
5
5
|
@window_size = window_size
|
6
6
|
@selector = selector
|
7
|
-
@always_generate = always_generate
|
8
7
|
@base_url = base_url
|
9
8
|
end
|
10
9
|
|
@@ -14,15 +13,11 @@ class Middleman::SocialImage::Converter
|
|
14
13
|
|
15
14
|
def convert(resource)
|
16
15
|
image_path = image_path(resource)
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
raise "#{resource.url} did not contain '#{@selector}'." unless session.has_selector?(@selector)
|
23
|
-
FileUtils.mkdir_p(File.dirname(image_path))
|
24
|
-
session.save_screenshot(image_path)
|
25
|
-
end
|
16
|
+
@app.logger.debug "== social_image: converting #{resource.path}"
|
17
|
+
session.visit(File.join(@base_url, resource.url))
|
18
|
+
raise "#{resource.url} did not contain '#{@selector}'." unless session.has_selector?(@selector)
|
19
|
+
FileUtils.mkdir_p(File.dirname(image_path))
|
20
|
+
session.save_screenshot(image_path)
|
26
21
|
end
|
27
22
|
|
28
23
|
private
|
@@ -3,7 +3,6 @@ require 'middleman-core'
|
|
3
3
|
class Middleman::SocialImage::Extension < ::Middleman::Extension
|
4
4
|
option :window_size, '1200,600'
|
5
5
|
option :selector, "body > *"
|
6
|
-
option :always_generate, true
|
7
6
|
option :parallel, true
|
8
7
|
option :base_url, "http://localhost:4567/"
|
9
8
|
|
@@ -11,7 +10,7 @@ class Middleman::SocialImage::Extension < ::Middleman::Extension
|
|
11
10
|
super
|
12
11
|
require "middleman-social_image/converter"
|
13
12
|
require "middleman-social_image/resource"
|
14
|
-
@converter = Middleman::SocialImage::Converter.new(app, options.window_size, options.selector, options.
|
13
|
+
@converter = Middleman::SocialImage::Converter.new(app, options.window_size, options.selector, options.base_url)
|
15
14
|
end
|
16
15
|
|
17
16
|
def manipulate_resource_list(resources)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: middleman-social_image
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul McMahon
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: middleman-core
|