middleman-social_image 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/middleman-social_image/converter.rb +11 -6
- data/lib/middleman-social_image/extension.rb +2 -1
- data/lib/middleman-social_image/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6903e2e4c9c370bcff55abbc8ffd6a6d2333b67db7d3fe127b6ebb0b4d3b1ec9
|
4
|
+
data.tar.gz: a4b1388cdd36533812451638ecb7651c40ef898bdf3d9f6e714c7b82304a29b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1da14d580fce03713d103ab310067911ff16030e56334cf287797ed9a859ad798dabd4cfdb1906464d39a552d4787a10c069d67489242c6e3fe51343800989b0
|
7
|
+
data.tar.gz: 523f65bd90f08997969ea286454551566657fa3b189856e12e0ce2b4b12d533a55c00ee240e4a129a676b9cc98015db15e2d98b3529028ad473d5445700df432
|
data/README.md
CHANGED
@@ -32,6 +32,7 @@ Optionally, you can configure this extension with the following (defaults are sh
|
|
32
32
|
activate :social_image do |social_image|
|
33
33
|
social_image.window_size = '1200,600' # The size of the screenshot
|
34
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.
|
35
|
+
social_image.always_generate = true # Always regenerate images. Takes a long time, but ensures any changes are reflected.
|
35
36
|
social_image.parallel = true # Generate images in parallel.
|
36
37
|
social_image.base_url = "http://localhost:4567/" # When building the site, fetch against this URL.
|
37
38
|
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
require "middleman-social_image/capybara"
|
2
2
|
class Middleman::SocialImage::Converter
|
3
|
-
def initialize(app, window_size, selector, base_url)
|
3
|
+
def initialize(app, window_size, selector, always_generate, base_url)
|
4
4
|
@app = app
|
5
5
|
@window_size = window_size
|
6
6
|
@selector = selector
|
7
|
+
@always_generate = always_generate
|
7
8
|
@base_url = base_url
|
8
9
|
end
|
9
10
|
|
@@ -13,11 +14,15 @@ class Middleman::SocialImage::Converter
|
|
13
14
|
|
14
15
|
def convert(resource)
|
15
16
|
image_path = image_path(resource)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
if File.exist?(image_path) && !@always_generate
|
18
|
+
@app.logger.debug "== social_image: skipping #{resource.path} as already in cache"
|
19
|
+
else
|
20
|
+
@app.logger.debug "== social_image: converting #{resource.path}"
|
21
|
+
session.visit(File.join(@base_url, resource.url))
|
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
|
21
26
|
end
|
22
27
|
|
23
28
|
private
|
@@ -3,6 +3,7 @@ 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
|
6
7
|
option :parallel, true
|
7
8
|
option :base_url, "http://localhost:4567/"
|
8
9
|
|
@@ -10,7 +11,7 @@ class Middleman::SocialImage::Extension < ::Middleman::Extension
|
|
10
11
|
super
|
11
12
|
require "middleman-social_image/converter"
|
12
13
|
require "middleman-social_image/resource"
|
13
|
-
@converter = Middleman::SocialImage::Converter.new(app, options.window_size, options.selector, options.base_url)
|
14
|
+
@converter = Middleman::SocialImage::Converter.new(app, options.window_size, options.selector, options.always_generate, options.base_url)
|
14
15
|
end
|
15
16
|
|
16
17
|
def manipulate_resource_list(resources)
|