-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_readme
executable file
·34 lines (29 loc) · 907 Bytes
/
build_readme
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
#!/usr/bin/env ruby
require "ostruct"
require "pathname"
root = File.dirname(File.expand_path(__FILE__))
root_path = Pathname.new(root)
tils = {}.tap do |result|
Dir["#{root}/*/"].sort.each do |dir|
dir_name = Pathname.new(dir).relative_path_from(root_path).to_s
result[dir_name] = Dir["#{dir}*.md"].sort.map do |f|
OpenStruct.new(label: File.basename(f).gsub(".md", "").tr("_", " "),
link: File.join(dir_name, File.basename(f)))
end
end
end
md = []
md << ["# til", "Today I Learned", "", "---", "", "### Categories", ""]
tils.each do |dir, files|
md << "* [#{dir}](##{dir.downcase})" unless files.empty?
end
md << ""
tils.each do |dir, files|
next if files.empty?
md << ["---", "", "### #{dir}", ""]
files.each do |f|
md << "- [#{f.label}](#{f.link})"
end
md << ""
end
File.open(File.join(root, "README.md"), "w") { |f| f << md.join("\n") }