Skip to content

Instantly share code, notes, and snippets.

@billie66
Last active August 29, 2015 14:08
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 billie66/124c06f54efd91ffcf42 to your computer and use it in GitHub Desktop.
Save billie66/124c06f54efd91ffcf42 to your computer and use it in GitHub Desktop.
deal with file names, like 001-git-revert.md, to make a content for all of files
# encoding: utf-8
def html(num, sname, fname, token)
str = <<-EOF
<tr class="episode-wrap#{token}">
<td class="episode-index">#{num}</td>
<td class="episode-title">
<a href="#{fname}">#{sname}</a>
</td>
</tr>
EOF
end
def layout(rows)
str = <<-EOF.gsub(/^\s{4}/, '')
---
layout: default
title: Happycasts
---
<section class="container content">
<table class="index-table">
<tbody>
#{rows}
</tbody>
</table>
</section>
EOF
end
list = ""
count = 0
Dir["[01]*.md"].each do |f|
count += 1
a = f.gsub('.md', '').split('-')
num = a.delete_at(0)
sname = a.join(' ')
token = count.even? ? ' even' : ''
list = html(num, sname, f.gsub('.md', '.html'), token) + list
end
File.open("index.md", 'w+') do |f|
f.write(layout(list))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment