-
Notifications
You must be signed in to change notification settings - Fork 9
/
build.py
48 lines (40 loc) · 1.38 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
import jinja2
import json
import os
from os import listdir
from os.path import isfile, join, splitext
EXCLUDE_FILES = ['navbar.html', 'header.html', 'footer.html', '404.html']
onlyfiles = [f for f in listdir() if splitext(f)[1]==".html"]
templateLoader = jinja2.FileSystemLoader(searchpath="./")
templateEnv = jinja2.Environment(loader=templateLoader)
def gen_templates():
for f in onlyfiles:
if EXCLUDE_FILES.__contains__(f):
continue
TEMPLATE_FILE = f
template = templateEnv.get_template(TEMPLATE_FILE)
print(template.render(),file=open(f,"w"))
def gen_sitemap():
sitemap_file = open("sitemap.xml","w")
sitemap_file.write('<?xml version="1.0" encoding="UTF-8"?>')
sitemap_file.write('<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">')
for f in onlyfiles:
if EXCLUDE_FILES.__contains__(f):
continue
sitemap_file.write(
'''
<url>
<loc>%s</loc>
</url>
'''
%("https://covidkashmir.org/"+f.replace("index","").replace(".html","")))
sitemap_file.write('</urlset>')
sitemap_file.close()
def gen_redirects():
redirects_file = open("_redirects","a")
for k,v in API_ENDPOINTS.items():
redirects_file.write("\n%s %s 200"%(v, os.getenv(k)))
redirects_file.close()
gen_redirects()
gen_templates()
gen_sitemap()