Skip to content

Instantly share code, notes, and snippets.

@tcr
Forked from hopsoft/readme2ghpage.rb
Created September 11, 2013 23:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tcr/6531001 to your computer and use it in GitHub Desktop.
Save tcr/6531001 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# checkout the readme from the master branch
`git checkout gh-pages; git checkout master README.md`
path = `pwd`.gsub(/\n/, "")
readme_path = File.join(path, "README.md")
index_path = File.join(path, "index.md")
# write the index readme file
File.open readme_path, "r" do |readme|
File.open index_path, "w" do |index|
# write the jekyll front matter
index.puts "---"
index.puts "layout: main"
index.puts "---"
readme.readlines.each do |line|
# convert backticks to liquid
%w(bash ruby js).each do |lang|
line.gsub!("```#{lang}", "{% highlight #{lang} %}")
end
line.gsub!("```", "{% endhighlight %}")
# convert headers so they are linkable
if line =~ /^#+/
leader = line[0, line.index(/\s/)]
text = line[line.index(/\s./)..-1].strip
line = "#{leader} #{text} {##{text.downcase.gsub(/\s/, "-")}}"
end
index.puts line
end
end
end
# remove the readme
`git reset HEAD README.md; rm README.md; git add .; git commit -am "Gh-pages update"; git push origin gh-pages; git checkout master`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment