-
Notifications
You must be signed in to change notification settings - Fork 12
/
build_readme.py
53 lines (41 loc) · 1.33 KB
/
build_readme.py
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
# Build README.md file
from os import walk, sep
from os.path import join
print("Writing README file...")
src_dir = "." + sep + "src"
link_dir = "src/"
readme_src = ["# RbxCookbook\n", "Feel free to submit a pull request with your own contributions!\n"]
# Get source files:
(_, _, filenames) = next(walk(src_dir))
def get_filename_without_ext(filename):
dot = filename.rfind(".")
if dot != -1:
filename = filename[:dot]
return filename
# Create list:
readme_src.append("### Snippets\n")
for filename in filenames:
name = get_filename_without_ext(filename)
anchor_name = name
anchor_name = "".join(e for e in anchor_name if e.isalnum()).lower()
readme_src.append(" - [" + filename + "](#" + anchor_name + ")")
readme_src.append("")
# Collect source code:
first = True
for filename in filenames:
filepath = join(src_dir, filename)
with open(filepath) as f:
source = f.read()
name = get_filename_without_ext(filename)
src_file_link = link_dir + filename
if not first:
readme_src.append("----------\n\n")
else:
first = False
readme_src.append("### " + name + "\n[`" + filename + "`](" + src_file_link + ")\n")
readme_src.append("```lua\n" + source + "```\n")
# Write readme file:
with open("README.md", "w") as readme_file:
readme_src_str = "\n".join(readme_src)
readme_file.write(readme_src_str)
print("README written")