-
Notifications
You must be signed in to change notification settings - Fork 29
/
make-html-index
executable file
·110 lines (92 loc) · 2.05 KB
/
make-html-index
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
load 'make-common'
require 'rss/maker'
def usage
puts <<USAGE
Usage:
make-html-index
Options:
-d, --debug : debuging
USAGE
exit
end
# re-generate all if nothing
if ARGV.empty?
$DEBUG = true
Dir["#$here/html/chap*.html"].each do |file|
ARGV.push(file)
end
end
# extract info
items = ARGV.sort.map do |path|
chap = /chap(\d+)/.match(path)[1]
date = html_mtime(chap)
link = path["#$here/html/".length..-1]
info = {
"title" => "",
"abstract" => "",
}
# extract info
markdown = File.read("#$here/chap#{chap}/doc.markdown")
info.each_key do |key|
blob = markdown.scan(/^% #{key}:(.*)/).join
blob.gsub("\n", "")
info[key] = blob
end
info["chap"] = chap
info["date"] = date
info["link"] = link
info
end
# generate rss feed
print "\tCreating rss.xml ... " if $DEBUG
rssfeed = RSS::Maker.make("2.0") do |m|
# rss info
m.channel.title = "Emacsbook"
m.channel.link = "http://emacsbook.taesoo.org"
m.channel.description = "이맥스 이해하기"
m.items.do_sort = true # sort items by date
items.each do |info|
# create new rss item
i = m.items.new_item
i.title = "Chap ##{info["chap"]}. #{info["title"]}"
i.link = info["link"]
i.date = Time.parse(info["date"])
i.description = info["abstract"]
end
end
# flush rss
File.open("#$here/html/rss.xml","w") do |f|
f.write(rssfeed)
end
print "done\n"
# generate html index
print "\tCreating index.html ... " if $DEBUG
html = "<ul>\n"
items.each do |info|
# create html item
html += <<DONE
<li>
<article class="post">
<header>
<h3>
<span class="hint">Chap ##{info["chap"]}</span>
#{info["date"]}
</h3>
<h1>
<a href="#{info["link"]}">#{info["title"]}</a>
</h1>
</header>
<p>#{info["abstract"]}</p>
</article>
</li>
DONE
end
html += "</ul>"
# flush index.html
File.open("#$here/html/index.html", 'w') do |file|
template = $index_template.result(binding)
file.write($base_template.result(binding))
end
puts "done" if $DEBUG