-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgenerate_site_map.py
More file actions
33 lines (27 loc) · 1.17 KB
/
generate_site_map.py
File metadata and controls
33 lines (27 loc) · 1.17 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
import os
import sys
from collections import OrderedDict
from pathlib import Path
from urllib.parse import urljoin
cwd = os.getcwd()
if __name__ == '__main__':
site_path = sys.argv[1]
flows = [val for sublist in [[os.path.join(os.path.relpath(dir_, cwd), file) for file in files]
for dir_, _, files in os.walk(cwd)] for val in sublist]
site_map = [
urljoin(site_path, flow).replace('index.html', '') for flow in flows
if 'index.html' in flow and 'src/' not in flow and '.blog' not in flow
]
locale_root = Path('locale')
locale_dirs = [dir_ for dir_ in locale_root.iterdir() if dir_.is_dir()]
for loc in locale_dirs:
locale = loc.name if loc.name != 'ja_JP' else 'jp'
site_map.extend([
urljoin(urljoin(site_path, locale) + '/', flow).replace('index.html', '') for flow in flows
if 'index.html' in flow and 'src/' not in flow and '.blog' not in flow
])
# Hacky deduplicating of the urls
site_map_dict = d = OrderedDict.fromkeys(site_map)
with open('sitemap/sitemap.txt', 'w') as f:
for item in site_map_dict.keys():
f.write("%s\n" % item)