middleman-social_image 0.0.1

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: fb0b030a5107566244948ab289a30177c59bd5d5754022fc32d816507b7540fe
4
+ data.tar.gz: 63da5dd031a4a50a2df41f05ad10816e5c0b7853a823d4a10850df693ae24ccd
5
+ SHA512:
6
+ metadata.gz: 4eb79e1af1523f4fd77a616d108a8b53440c3122690a98c338cb8a164ea4262a9726b8686314b5ffa15d8b18604cd9ffb1b11f3db516f7f597146fb2823db4f9
7
+ data.tar.gz: 99c2d6ebaad6d2a4dbaa1e03c6ed2d903411183137b612e710ccc134bc5367c1f63a6418ddf020811679d57194302e9d807995093fcf76b89698fddf5ca7dfcd
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in middleman-social_image.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Paul McMahon
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,42 @@
1
+ # Middleman::SocialImage
2
+
3
+ Use HTML and CSS to dynamically generate static images for Open Graph (Facebook, LinkedIn) and Twitter cards in a Middleman application. Image is generated by using Google Chrome in headless mode to screenshot a page served by middleman. Originally created for [tokyodev](https://www.tokyodev.com/), which lists internationally-friendly software developer jobs in Japan.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'middleman-social_image'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ ## Usage
16
+
17
+ You need to add the following code to your ```config.rb``` file:
18
+
19
+ ```ruby
20
+ activate :social_image
21
+ ```
22
+
23
+ Optionally, you can configure this extension with the following (defaults are shown):
24
+
25
+ ```ruby
26
+ activate :social_image do |social_image|
27
+ social_image.path_to_chrome = '/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome' # Command to execute chrome
28
+ social_image.window_size = '1200,600' # The size of the screenshot
29
+ social_image.base_url = 'http://localhost:4567/' # Base URL of running middleman server
30
+ social_image.base_asset_dir = 'assets/images/social-images' # Where to save the generated images
31
+ social_image.social_image_url_pattern = %r{(/social-image)/$} # Screenshot URLs matching this pattern
32
+ social_image.social_image_url_substitution, '\1.png' # When generating screenshots, replace URLs matching social_image_url_pattern with this
33
+ end
34
+ ```
35
+
36
+ Create a HTML page in your middleman app that contains the HTML you want to be rendered. The URL for this should match the social_image_url_pattern (so by default, ending with `/social-image/`).
37
+
38
+ Start up the middleman server with `bundle exec middleman server`
39
+
40
+ Run the `bundle exec middleman social_image` command to generate images from any URLs matching social_image_url_pattern. The image will be saved to a location matching the URL of the resource used to generate it, with the social_image_url_substitution applied, in the base_asset_dir. So with the default settings, if for instance you had created a page at `/examples/social-image/`, this image would be saved at `assets/images/social-images/examples/social-image.png`.
41
+
42
+ You can now refer to this image as normal within your middleman application.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "middleman/social_image"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,8 @@
1
+ require "middleman-core"
2
+ require 'middleman-social_image/version'
3
+
4
+ Middleman::Extensions.register :social_image do
5
+ require "middleman-social_image/extension"
6
+ require 'middleman-social_image/commands'
7
+ Middleman::SocialImage::Extension
8
+ end
@@ -0,0 +1,39 @@
1
+ require 'middleman-cli'
2
+
3
+ module Middleman
4
+ module Cli
5
+ class SocialImage < Thor::Group
6
+ include Thor::Actions
7
+
8
+ check_unknown_options!
9
+
10
+ namespace :social_image
11
+
12
+ def self.exit_on_failure?
13
+ true
14
+ end
15
+
16
+ def social_image
17
+ app = ::Middleman::Application.new do
18
+ config[:mode] = :config
19
+ config[:watcher_disable] = true
20
+ end
21
+ options = app.extensions[:social_image].options
22
+ app.sitemap.resources.each do |resource|
23
+ if resource.url =~ options.social_image_url_pattern
24
+ image_path = File.join(app.source_dir, options.base_asset_dir, resource.url.sub(options.social_image_url_pattern, options.social_image_url_substitution))
25
+ if File.exists?(image_path)
26
+ say "Image for #{resource.url} already generated, skipping."
27
+ else
28
+ FileUtils.mkdir_p(File.dirname(image_path))
29
+ url = File.join(options.base_url, resource.url)
30
+ run "#{options.path_to_chrome} --headless --disable-gpu --screenshot=#{image_path} --window-size=#{options.window_size} #{url}"
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ Base.register(Middleman::Cli::SocialImage, 'social_image', 'social_image [options]', 'Generates social images.')
38
+ end
39
+ end
@@ -0,0 +1,11 @@
1
+ require 'middleman-core'
2
+ require 'middleman-social_image/commands'
3
+
4
+ class Middleman::SocialImage::Extension < ::Middleman::Extension
5
+ option :path_to_chrome, '/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome'
6
+ option :window_size, '1200,600'
7
+ option :base_url, 'http://localhost:4567/'
8
+ option :base_asset_dir, 'assets/images/social-images'
9
+ option :social_image_url_pattern, %r{(/social-image)/$}
10
+ option :social_image_url_substitution, '\1.png'
11
+ end
@@ -0,0 +1,5 @@
1
+ module Middleman
2
+ module SocialImage
3
+ VERSION = '0.0.1'.freeze
4
+ end
5
+ end
@@ -0,0 +1,25 @@
1
+ require_relative 'lib/middleman-social_image/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "middleman-social_image"
5
+ spec.version = Middleman::SocialImage::VERSION
6
+ spec.authors = ["Paul McMahon"]
7
+ spec.email = ["paul@tokyodev.com"]
8
+
9
+ spec.summary = %q{Generate social images with Middleman.}
10
+ spec.homepage = "https://github.com/pwim/middleman-social_image"
11
+ spec.license = "MIT"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+
14
+ spec.metadata["homepage_uri"] = spec.homepage
15
+ spec.metadata["source_code_uri"] = "https://github.com/pwim/middleman-social_image"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: middleman-social_image
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Paul McMahon
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-05-08 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - paul@tokyodev.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - Gemfile
22
+ - LICENSE.txt
23
+ - README.md
24
+ - Rakefile
25
+ - bin/console
26
+ - bin/setup
27
+ - lib/middleman-social_image.rb
28
+ - lib/middleman-social_image/commands.rb
29
+ - lib/middleman-social_image/extension.rb
30
+ - lib/middleman-social_image/version.rb
31
+ - middleman-social_image.gemspec
32
+ homepage: https://github.com/pwim/middleman-social_image
33
+ licenses:
34
+ - MIT
35
+ metadata:
36
+ homepage_uri: https://github.com/pwim/middleman-social_image
37
+ source_code_uri: https://github.com/pwim/middleman-social_image
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 2.3.0
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubygems_version: 3.1.2
54
+ signing_key:
55
+ specification_version: 4
56
+ summary: Generate social images with Middleman.
57
+ test_files: []