-
Notifications
You must be signed in to change notification settings - Fork 2
/
sitemap.py
37 lines (25 loc) · 932 Bytes
/
sitemap.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
"""Create sitemap for HTML files."""
import os
import jinja2
from datetime import date
import stat
loader = jinja2.FileSystemLoader(os.getcwd())
env = jinja2.Environment(loader=loader)
sitemap_files = []
os.chdir("output")
for root, dirs, files in os.walk(".", topdown=False, followlinks=True):
for name in files:
if root.startswith("./theme"):
continue
if name.endswith(".html"):
path = os.path.join(root, name)
statbuf = os.stat(path)
fdate = date.fromtimestamp(statbuf[stat.ST_MTIME])
lastmod = fdate.strftime('%Y-%m-%d')
# Remove ./output
path = path[len("."):]
sitemap_files.append(dict(path=path, lastmod=lastmod))
template = env.get_template('sitemap.xml')
doc = template.render(files=sitemap_files, site="https://operationssecurity.org")
with open("sitemap.xml", "wt") as out:
out.write(doc)