├── screenshots ├── 1.png ├── 2.png └── 3.png ├── .gitignore ├── README.md ├── LICENSE └── lazy_tweet_embedding.rb /screenshots/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/takuti/jekyll-lazy-tweet-embedding/HEAD/screenshots/1.png -------------------------------------------------------------------------------- /screenshots/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/takuti/jekyll-lazy-tweet-embedding/HEAD/screenshots/2.png -------------------------------------------------------------------------------- /screenshots/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/takuti/jekyll-lazy-tweet-embedding/HEAD/screenshots/3.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /jekyll-sample/* 2 | 3 | !/jekyll-sample/_posts/ 4 | /jekyll-sample/_posts/* 5 | !/jekyll-sample/_posts/2016-07-01-sample-html.html 6 | !/jekyll-sample/_posts/2016-07-01-sample-markdown.md 7 | 8 | !/jekyll-sample/_site/ 9 | /jekyll-sample/_site/* 10 | !/jekyll-sample/_site/sample-html.html 11 | !/jekyll-sample/_site/sample-markdown.html 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Jekyll Lazy Tweet Embedding Plugin 2 | ==== 3 | 4 | Embed your tweet into posts, by just copy-and-pasting tweet url. 5 | 6 | ## Description 7 | 8 | This converter plugin converts all tweet urls in your posts written as `.html` or `.md`. 9 | 10 | ## Usage 11 | 12 | After putting `lazy_tweet_embedding.rb` under the **_plugins** directory, Jekyll will automatically embed tweet card every time he generates your site. 13 | 14 | First of all, make sure the tweet url: 15 | 16 | ![1](/screenshots/1.png) 17 | 18 | Next, just copy and paste it in your awesome article: 19 | 20 | ![2](/screenshots/2.png) 21 | 22 | Done! Jekyll converts the url automatically. 23 | 24 | ![3](/screenshots/3.png) 25 | 26 | :tada: :tada: :tada: :tada: :tada: 27 | 28 | ## Licence 29 | 30 | MIT 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016: Takuya Kitazawa. 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 all 13 | 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 THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /lazy_tweet_embedding.rb: -------------------------------------------------------------------------------- 1 | require "open-uri" 2 | require "json" 3 | 4 | module Jekyll 5 | 6 | # convert tweet url to embedding html 7 | class LazyTweetEmbedding 8 | def get_html(id) 9 | url = "https://api.twitter.com/1/statuses/oembed.json?id=#{id}" 10 | JSON.parse(URI.open(url).read, { :symbolize_names => true })[:html] 11 | end 12 | 13 | def convert(line) 14 | r = /^https?:\/\/twitter\.com\/[a-zA-Z0-9_]+\/status(es)?\/([0-9]+)\/?$/ 15 | r =~ line ? get_html($~[2]) : line 16 | end 17 | 18 | def embed(content) 19 | content.lines.collect {|line| convert(line) }.join 20 | end 21 | end 22 | 23 | # for markdown, extend oroginal parser's convert method 24 | module Converters 25 | class Markdown < Converter 26 | alias_method :parser_converter, :convert 27 | 28 | def convert(content) 29 | parser_converter(Jekyll::LazyTweetEmbedding.new.embed(content)) 30 | end 31 | end 32 | end 33 | 34 | # for html, extend converter as a plugin 35 | class EmbeddingTweetIntoHTML < Converter 36 | safe true 37 | priority :low 38 | 39 | def matches(ext) 40 | ext =~ /^\.html$/i 41 | end 42 | 43 | def output_ext(ext) 44 | ".html" 45 | end 46 | 47 | def convert(content) 48 | Jekyll::LazyTweetEmbedding.new.embed(content) 49 | end 50 | end 51 | 52 | end 53 | --------------------------------------------------------------------------------