LoginSignup
2
2

More than 5 years have passed since last update.

gistの貼り付けタグのScriptからHTMLにする。

Posted at

Gistの貼り付けタグは で、 document.writeオン・パレードです。これでは、検索にインデックスに反映されないし、なによりdocument.writeは嫌過ぎるので、gistの貼り付けタグから、貼り付け用のHTMLタグを生成することにした。

gist2html.rb
!/usr/bin/env ruby
coding:utf-8

require 'openssl'
 require 'open-uri'
 require 'rubygems'
 require 'json'

if ARGV.size < 1 || ! (/([0-9]+)/ =~ ARGV[0])
 puts "Usage : Gist のIDを指定。"
 puts "以下のように指定"
 puts " #{FILE} https://gist.github.com/3033059 "
 puts " #{FILE} https://gist.github.com/3033059.js "
 puts " #{FILE} https://gist.github.com/3033059.json "
 puts " #{FILE} 3033059 "
 exit
 end

id = $1
 json = open("https://gist.github.com/#{id}.json").read
 data = JSON.load json
 puts '<link rel="stylesheet" href="https://gist.github.com/stylesheets/gist/embed.css"/>'
 puts data["div"]
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2