-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.py
177 lines (160 loc) · 6.36 KB
/
build.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#! /usr/bin/env python
import os
import subprocess
import jinja2
HERE = os.path.abspath(os.path.dirname(__file__))
LAYOUT_ROOT = os.path.join(HERE, "layout")
CONTENTS_ROOT = os.path.join(HERE, "contents")
ROOT_PATH = "academy"
BUILD_DIR = os.path.join(HERE, "_build", ROOT_PATH)
RESOURCES = [
# Resource template
# {
# # mandatory
# "title": "My Title",
# "src": "filename or url",
# "description": "Will be trimmed to 3 lines",
# "type": "Tutorial/Guide/Video/Analysis",
# "category": "General/Development/DevOps/User experience",
# # optional
# "target_audience": [],
# "learning_outcomes": [],
# },
{
"title": "Creating and Running an Accessible Online Course: A Primer",
"src": "accessible-course",
"description": "This video is an essential resource for educators and course creators aiming to make online learning accessible to everyone, including learners with disabilities. It offers actionable insights and practical steps.",
"type": "Video",
"category": "General",
},
{
"title": "Achieving double completion rates through Hyper Personalized Nudge Emails",
"src": "nudge-emails",
"description": "John Swope outlines the importance of learner engagement and the challenges faced by educational platforms in maintaining participation and course completion rates.",
"type": "Video",
"category": "General",
},
{
"title": "Upgrading Open edX from Quince To Redwood ",
"src": "redwood-upgrade",
"description": "Step-by-step instructions on upgrading an existing Open edX platform from Quince to Redwood",
"type": "Tutorial",
"category": "Devops",
},
{
"title": "Tutor Indigo - Customize the user experience by branding Open edX",
"src": "tutorindigo",
"type": "Guide",
"description": "Tutor Indigo is a theme designed for use with Tutor, to give a new look to Open edX platform",
"category": "UI/UX",
},
{
"title": "Docker 101",
"src": "docker101",
"description": "Learn the basics of Docker and Docker Compose in this general, beginner-level tutorial.",
"type": "Tutorial",
"category": "Development",
},
{
"title": "What is Tutor?",
"src": "what-is-tutor",
"description": "Why does Tutor exist and how does it work?",
"type": "Video",
"category": "General",
},
{
"title": "Install Open edX with Tutor",
"src": "openedx-install",
"description": "Step-by-step instructions for an installation from scratch on a production server. The last guide you will ever need to install Open edX.",
"type": "Video",
"category": "Devops",
},
{
"title": "Tutor plugins",
"src": "tutor-plugins",
"description": "Learn what Tutor plugins are, how to use them and how to create your own plugins.",
"type": "Guide",
"category": "Devops",
},
{
"title": "Changing the appearance of Open edX",
"src": "https://docs.tutor.edly.io/tutorials/theming.html",
"type": "Tutorial",
"description": "Customize the visual appearance of your Open edX platform with comprehensive theming.",
"category": "UI/UX",
},
{
"title": "Running Open edX at scale",
"src": "https://docs.tutor.edly.io/tutorials/scale.html",
"type": "Guide",
"description": "What happens when your monthly active users are multiplied by 10, 100, 1000? Follow this short guide to find out.",
"category": "Devops",
},
{
"title": "Open edX installation speedrun",
"src": "https://www.youtube.com/watch?v=eXPFx_h1hn4",
"type": "Video",
"description": "How fast can we install Open edX on a live production server? Watch this video to find out :)",
"category": "Devops",
},
{
"title": "Reaching 50k concurrent users on Open edX with Oracle Cloud",
"src": "project-50k",
"description": "Read all about this achievement in this interview of the Edly DevOps team.",
"type": "Analysis",
"category": "DevOps",
},
]
VARIABLES = {
"URL_ROOT": f"/{ROOT_PATH}",
"CATEGORIES": ["all"] + list(sorted(set(r["category"] for r in RESOURCES))),
"RESOURCE_TYPES": ["all"] + list(sorted(set(r["type"] for r in RESOURCES))),
}
def main():
environment = jinja2.Environment(
loader=jinja2.FileSystemLoader([LAYOUT_ROOT]),
undefined=jinja2.StrictUndefined,
)
build_content_docs()
render_site(environment)
def build_content_docs():
for resource in RESOURCES:
src = resource["src"]
if src and not resource["src"].startswith("http"):
src_path = os.path.join(CONTENTS_ROOT, f"{resource['src']}.rst")
dst_path = os.path.join(CONTENTS_ROOT, "_build", f"{resource['src']}.html")
ensure_file_directory_exists(dst_path)
print(f"Converting {src_path} -> {dst_path}...")
subprocess.check_call(
["pandoc", "--shift-heading-level-by=2", src_path, "-o", dst_path]
)
def render_site(environment):
render_to(environment, "index.html", "index.html", resources=RESOURCES)
for resource in RESOURCES:
src = resource["src"]
if src and not src.startswith("http"):
with open(
os.path.join(CONTENTS_ROOT, "_build", f"{src}.html"),
encoding="utf8",
) as f:
resource_html = f.read()
render_to(
environment,
"resource.html",
os.path.join(src, "index.html"),
resource=resource,
resource_html=resource_html,
)
def render_to(environment, template_path, dst_path, **local_variables):
print(f"rendering {template_path} --> {dst_path}...")
template = environment.get_template(template_path)
dst_abs_path = os.path.join(BUILD_DIR, dst_path)
ensure_file_directory_exists(dst_abs_path)
with open(dst_abs_path, "w", encoding="utf8") as f:
f.write(template.render(**VARIABLES, **local_variables))
def ensure_file_directory_exists(path):
dirname = os.path.dirname(path)
if not os.path.exists(dirname):
os.makedirs(dirname)
if __name__ == "__main__":
main()