forked from lightninglabs/lightning-dev-site
-
Notifications
You must be signed in to change notification settings - Fork 0
/
render.py
executable file
·87 lines (73 loc) · 2.99 KB
/
render.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
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
#!/usr/local/bin/python2.7
from jinja2 import Environment, FileSystemLoader, select_autoescape
def read_file_without_title(filename):
"""
Takes filename of markdown as input and returns the file contents as a
utf-8 encoded string after stripping out the title
"""
file_lines = open(filename).readlines()
while True:
line = file_lines[0].decode('utf-8').strip()
# If the line is empty or begins with a `# ` denoting a h1 md header
if line == '' or line[:2] == '# ':
# Remove the first line
file_lines.pop(0)
else:
break
# At this point, file_lines is stripped of the title.
# Return the utf string
return "".join(file_lines)
def render():
"""
Given the necessary markdown files that are maintained on Github in the
`lnd` repo, renders the guides with Jekyll header.
"""
# Load the Jekyll header from the `templates` dir
env = Environment(
loader=FileSystemLoader('./templates'),
autoescape=select_autoescape(['html', 'xml'])
)
template = env.get_template('base.md')
# Read INSTALL.md and output guides/installation.md
installation_guide = template.render(
title='Installation',
permalink=None,
content=read_file_without_title('INSTALL.md'),
footer=open('templates/installation_footer.md').read(),
).encode('utf-8')
installation_output = 'guides/installation.md'
with open(installation_output, "wb") as file_out:
file_out.write(installation_guide)
print "Rendered {}".format(installation_output)
# Read DOCKER-README.md and output guides/docker.md
docker_guide = template.render(
title='Working with LND and Docker',
permalink=None,
content=read_file_without_title('DOCKER-README.md'),
).encode('utf-8')
docker_output = 'guides/docker.md'
with open(docker_output, "wb") as file_out:
file_out.write(docker_guide)
print "Rendered {}".format(docker_output)
# Read python.md and output guides/python-grpc.md
python_grpc_guide = template.render(
title='How to write a Python gRPC client for the Lightning Network Daemon',
permalink=None,
content=read_file_without_title('python.md'),
).encode('utf-8')
python_grpc_output = 'guides/python-grpc.md'
with open(python_grpc_output, "wb") as file_out:
file_out.write(python_grpc_guide)
print "Rendered {}".format(python_grpc_output)
# Read javascript.md and output guides/javascript-grpc.md
javascript_grpc_guide = template.render(
title='How to write a Javascript gRPC client for the Lightning Network Daemon',
permalink=None,
content=read_file_without_title('javascript.md'),
).encode('utf-8')
javascript_grpc_output = 'guides/javascript-grpc.md'
with open(javascript_grpc_output, "wb") as file_out:
file_out.write(javascript_grpc_guide)
print "Rendered {}".format(javascript_grpc_output)
if __name__ == '__main__':
render()