forked from craigkerstiens/postgresguide.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sitemap.py
72 lines (60 loc) · 2.16 KB
/
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
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
import os
import time
from jinja2 import Environment
from jinja2 import PackageLoader, FileSystemLoader
SITE_ROOT = os.path.realpath(os.path.dirname(__file__))
TEMPLATE_ROOT = os.path.join(SITE_ROOT, 'media')
jinja_env = Environment(loader= FileSystemLoader(os.path.join(SITE_ROOT, 'source/_templates')))
class FileInfo(object):
"""Wrapper around filesystem file: collects info"""
def __init__(self, dirpath, filename):
fullpath = os.path.join(dirpath, filename)
self.path = dirpath.replace('build/html', '')
self.path = self.path + '/' + filename
self.last_modified = time.gmtime(os.path.getmtime(fullpath))
self.last_modified = time.strftime('%Y-%m-%d', self.last_modified)
@property
def priority(self):
if '/weblog/tags' in self.path:
return '0.1'
if self.path in ['/index.html',
'/weblog/index.html']:
return '1.0'
if '/me/' in self.path:
return '0.8'
if '/bc/' in self.path:
return '0.8'
if '/ligfiets/' in self.path:
return '0.9'
return '0.5'
@property
def changefreq(self):
if self.path in ['/index.html',
'/weblog/index.html']:
return 'hourly'
return 'monthly'
def files():
for dirpath, dirnames, filenames in os.walk('build/html'):
if '_sources' in dirpath:
continue
if '_static' in dirpath:
continue
if '.svn' in dirpath:
continue
for filename in filenames:
if filename in ['favicon.ico',
'genindex.html',
'objects.inv',
'search.html',
'.buildinfo',
'.DS_Store',
'searchindex.js']:
continue
yield FileInfo(dirpath, filename)
def main():
outfile = open('build/html/sitemap.xml', 'w')
sitemap_templ = jinja_env.get_template('sitemap.xml')
outfile.write(sitemap_templ.render(files=files()))
outfile.close()
if __name__ == "__main__":
main()