Created
June 21, 2012 17:09
-
-
Save hopsoft/2967061 to your computer and use it in GitHub Desktop.
Convert your README.md on master to index.md on gh-pages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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).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` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cool, I stared it!
Just wondering if anyone knows how to add a favicon to a GitHub pages repo with a .md file as the page. I already know how to do that with just a .md file as the homepage. Also if anyone can have a custom HTML head as well, that would be much appreciated.