diff options
Diffstat (limited to '')
-rwxr-xr-x | pyblog | 56 | ||||
-rw-r--r-- | source/css/theme.css | 16 | ||||
-rw-r--r-- | templates/template.html | 7 |
3 files changed, 58 insertions, 21 deletions
@@ -259,33 +259,39 @@ def generate_index(feed): os.remove(tmppath) -def make_sitemap_url_element(atomlink, atomupdated, changefreq, priority): +def make_sitemap_url_element(link, updated=None, changefreq=None, priority=None): """Make a sitemap <url> element. Parameters ---------- - atomlink : xml.etree.ElementTree.Element - atom:link element, e.g., <link href="http://zmwangx.github.io/"/> - atomupdated : xml.etree.ElementTree.Element - atom:updated element, e.g., <updated>2015-05-05T22:38:42-07:00</updated> - changefreq : {"always", "hourly", "daily", "weekly", "monthly", "yearly", "never"} - priority : {1.0, 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1} + link : str or xml.etree.ElementTree.Element + If using an xml.etree.ElementTree.Element element, then it shall + be an atom:link element, e.g., <link href="http://zmwangx.github.io/"/>. + updated : str or xml.etree.ElementTree.Element, optional + If using an xml.etree.ElementTree.Element element, then it shall + be an atom:updated element, e.g., + <updated>2015-05-05T22:38:42-07:00</updated>. + changefreq : {"always", "hourly", "daily", "weekly", "monthly", "yearly", "never"}, optional + priority : {1.0, 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1}, optional """ urlelem = ET.Element("url") loc = ET.Element("loc") - loc.text = atomlink.attrib["href"] - lastmod = ET.Element("lastmod") - lastmod.text = atomupdated.text - changefreq_elem = ET.Element("changefreq") - changefreq_elem.text = changefreq - priority_elem = ET.Element("priority") - priority_elem.text = "%.1f" % priority + loc.text = link.attrib["href"] if isinstance(link, ET.Element) else link urlelem.append(loc) - urlelem.append(lastmod) - urlelem.append(changefreq_elem) - urlelem.append(priority_elem) + if updated is not None: + lastmod = ET.Element("lastmod") + lastmod.text = updated.text if isinstance(updated, ET.Element) else updated + urlelem.append(lastmod) + if changefreq is not None: + changefreq_elem = ET.Element("changefreq") + changefreq_elem.text = changefreq + urlelem.append(changefreq_elem) + if priority is not None: + priority_elem = ET.Element("priority") + priority_elem.text = "%.1f" % priority + urlelem.append(priority_elem) return urlelem @@ -294,6 +300,22 @@ def generate_sitemap(feed): sitemap = ET.Element("urlset", xmlns="http://www.sitemaps.org/schemas/sitemap/0.9") # index sitemap.append(make_sitemap_url_element(BLOG_HOME, feed.updated, "daily", 1.0)) + # other top level pages + for name in os.listdir(BUILDDIR): + if not name.endswith(".html") or name == "index.html": + continue + link = "{home}/{path}".format(home=BLOG_HOME, path=name) + fullpath = os.path.join(BUILDDIR, name) + # try to extract updated time + updated = None + with open(fullpath, encoding="utf-8") as htmlobj: + soup = bs4.BeautifulSoup(htmlobj.read()) + if soup.article.footer is not None: + updated_tag = soup.article.footer.find(attrs={"class": "updated"}) + if updated_tag is not None: + updated = updated_tag.text + sitemap.append(make_sitemap_url_element(link, updated, "monthly", 0.9)) + # blog entries for entry in feed.entries: sitemap.append(make_sitemap_url_element(entry.link, entry.updated, "monthly", 0.9)) diff --git a/source/css/theme.css b/source/css/theme.css index d7983bef..19930c0f 100644 --- a/source/css/theme.css +++ b/source/css/theme.css @@ -97,11 +97,19 @@ a { color: #333; } -footer { - text-align: right; +footer .lfooter { + float: left; +} + +footer .lfooter .updated:before { + content: "Last updated: " +} + +footer .rfooter { + float: right; } -footer .cc-icon { +footer .rfooter .cc-icon { width: 16px; height: 16px; padding: 0 4px; @@ -114,7 +122,7 @@ footer .cc-icon { font-size: 0; } -footer .feed-icon { +footer .rfooter .feed-icon { width: 16px; height: 16px; display: inline-block; diff --git a/templates/template.html b/templates/template.html index cab2c033..6e9329c2 100644 --- a/templates/template.html +++ b/templates/template.html @@ -73,9 +73,16 @@ $endif$ $body$ <footer> <hr> +$if(updated)$ +<span class="lfooter"> +<time class="updated" datetime="$updated$"><code>$updated$</code></span> +</span> +$endif$ +<span class="rfooter"> <a class="feed-icon" href="/atom.xml" target="_blank" title="Atom feed">Atom feed icon</a> <a class="cc-icon" href="https://creativecommons.org/licenses/by/4.0/" target="_blank" title="Released under the Creative Commons Attribution 4.0 International license.">Creative Commons icon</a> <a href="https://github.com/zmwangx" target="_blank">Zhiming Wang</a> +</span> </footer> </article> </body> |