Skip to content

Instantly share code, notes, and snippets.

@hopsoft
Created June 21, 2012 17:09
Show Gist options
  • Save hopsoft/2967061 to your computer and use it in GitHub Desktop.
Save hopsoft/2967061 to your computer and use it in GitHub Desktop.
Convert your README.md on master to index.md on gh-pages
#!/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`
@mekb-turtle
Copy link

mekb-turtle commented Apr 8, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment