File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+ <urlset xmlns =" http://www.sitemaps.org/schemas/sitemap/0.9" >
3+ {% for page in pages %}
4+ <url >
5+ <loc >{{root_url}}/{{page['url']}}</loc >
6+ <lastmod >{{page['lastmod']}}</lastmod >
7+ <changefreq >{{freq}}</changefreq >
8+ </url >
9+ {% endfor %}
10+ </urlset >
Original file line number Diff line number Diff line change 33
44import os
55from pathlib import Path
6- from jinja2 import Template
6+ from jinja2 import Environment , FileSystemLoader
77from subprocess import check_output
88
99BASE_DIR = os .path .abspath (os .path .dirname (__file__ ))
@@ -31,13 +31,17 @@ def sitemap(suffix='.md'):
3131 p = p .with_suffix ('.html' )
3232 fn = p .as_posix ().lower ()
3333 page = {}
34- page ['date ' ] = date
34+ page ['lastmod ' ] = date
3535 page ['url' ] = fn
3636 pages .append (page )
3737 root_url = 'http://algorithm.yuanbin.me'
38- template = Template (os .path .join (BASE_DIR , 'sitemap.xml' ))
39- template .render (root_url = root_url , pages = pages )
40- # print(sitemap_xml)
38+ templates = os .path .join (BASE_DIR , 'sitemap' + os .sep + 'templates' )
39+ env = Environment (loader = FileSystemLoader (templates ))
40+ template = env .get_template ('sitemap.xml' )
41+ sitemap_xml = template .render (root_url = root_url , pages = pages , freq = 'daily' )
42+ sitemap_fn = os .path .join (ROOT_DIR , 'sitemap.xml' )
43+ with open (sitemap_fn , 'w' ) as sf :
44+ sf .write (sitemap_xml )
4145
4246
4347if __name__ == "__main__" :
You can’t perform that action at this time.
0 commit comments