Last active
August 29, 2015 14:08
-
-
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
This file contains hidden or 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
# 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