Our great sponsors
-
WorkOS
The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.
require "Rubygems" require "Ferrum" def generate_card(browser, card, png, options={}) browser.go_to("http://localhost:4000/cards/#{card}") # see all the options here https://github.com/rubycdp/ferrum#screenshots browser.screenshot(path: "./images/cards/#{png}", full: true, # final image size is window_size x scale scale: 2) end browser = Ferrum::Browser.new(window_size: [800, 418]) # Check what cards we need to make Dir.glob("_posts/*").each do |post| post = File.basename(post, ".md") png = post + ".png" card = post + ".html" generate_card(browser, card, png) unless File.exists?("./images/cards/#{png}") end
I’ve now got a simple, ruby-only, automated way of making Twitter summary cards and OpenGraph image previews for the posts on this blog. Now I just need to iterate on the currently horrible version-zero look of them!
In my Jekyll install I’ve got a _cards symbolic link to my _posts directory, and in my _config.yml I’ve got a defaults section that looks like this:
Related posts
- Best library for scraping dynamic page in Sidekiq background job (Selenium/Puppeteer/Cypress/Playwright)
- Sometimes things simply don't work
- Craft Your GitHub Profile Page in 60 Seconds with Zero Code, Absolutely Free
- Supermium – Chromium fork for Win 2003 and newer
- Map your (Vim) keys for web surfing, expand the browser with JavaScript