-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
executable file
·66 lines (57 loc) · 1.73 KB
/
build.py
File metadata and controls
executable file
·66 lines (57 loc) · 1.73 KB
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import io
import json
import os.path
import logging
from os import walk
from markdown import markdown
from jinja2 import Environment, PackageLoader
env = Environment(loader=PackageLoader('build', 'templates'))
# index page (with architecture/modules)
def render_index():
index = env.get_template('index.html')
with io.open('index.html', 'w', encoding='utf-8') as h:
modules = {
"mobile": [],
"www": [],
"backend": [],
"storage": []
}
# read modules
dirpath, _, filenames = next(walk('modules/modules'))
for filename in filenames:
path = os.path.join(dirpath, filename)
with io.open(path, 'r', encoding='utf-8') as j:
js = json.load(j)
js = process_module_properties(js)
name = js.get('name')
types = js.get('type', [])
for typ in types:
if typ in modules:
modules[typ].append(js)
else:
logging.error("The module {} has an invalid type “{}”"
.format(name, typ))
h.write(index.render(modules=modules))
def process_module_properties(properties):
""" Applies Markdown to "description" and "short". Shortens "description"
to 100 chars if "short" is not present.
"""
assert properties
if 'description' in properties:
desc = properties['description']
properties['description'] = markdown(desc)
if 'short' not in properties:
properties['short'] = desc[:99].strip()+'…' if len(desc) > 100 else desc
if 'short' in properties:
properties['short'] = markdown(properties['short'][:100])
return properties
# team page
def render_team():
team = env.get_template('team.html')
with io.open('team.html', 'w', encoding='utf-8') as h:
h.write(team.render())
if '__main__' == __name__:
render_index()
render_team()