Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
labmlai
GitHub Repository: labmlai/annotated_deep_learning_paper_implementations
Path: blob/master/utils/sitemap.py
4918 views
1
from pathlib import Path
2
3
import git
4
5
HOME = Path('./labml_nn')
6
REPO = git.Repo('.')
7
8
9
def collect(path: Path):
10
if path.is_file():
11
try:
12
commit = next(iter(REPO.iter_commits(paths=path)))
13
except StopIteration:
14
return []
15
16
html = path.relative_to(HOME)
17
if html.suffix not in {'.py'}:
18
return []
19
20
if html.stem == '__init__':
21
html = html.parent / 'index.html'
22
else:
23
html = html.parent / f'{html.stem}.html'
24
25
return [{'path': str(html), 'date': str(commit.committed_datetime.date())}]
26
27
urls = []
28
for f in path.iterdir():
29
urls += collect(f)
30
31
return urls
32
33
34
def main():
35
urls = []
36
for f in HOME.iterdir():
37
urls += collect(f)
38
39
urls = [f'''
40
<url>
41
<loc>https://nn.labml.ai/{u['path']}</loc>
42
<lastmod>{u['date']}T16:30:00+00:00</lastmod>
43
<priority>1.00</priority>
44
</url>
45
''' for u in urls]
46
47
urls = '\n'.join(urls)
48
xml = f'''
49
<?xml version="1.0" encoding="UTF-8"?>
50
<urlset
51
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
52
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
53
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
54
http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
55
{urls}
56
</urlset>
57
'''
58
59
with open(str(HOME.parent / 'docs' / 'sitemap.xml'), 'w') as f:
60
f.write(xml)
61
62
63
if __name__ == '__main__':
64
main()
65
66