+ for file, title, lead, tags in blog[key]:
+ if file.endswith(".tmpl"): file = file[:-len("tmpl")] + "html"
+ value = (year, month, day, file, title, lead)
+ all_titles_tags.append((year, month, day, file, title, lead, tags))
+ all_titles.append(value)
+ year_titles.append(value)
+ month_titles.append(value)
+ day_titles.append(value)
+ for tag in tags:
+ if tag in all_tags:
+ tag_links = all_tags[tag]
+ else:
+ tag_links = all_tags[tag] = []
+ tag_links.append(value)
+ write_template(3, year, month, day, day_titles)
+ write_template(2, year, month, day, month_titles)
+ write_template(1, year, month, day, year_titles)
+
+def by_count_rev_tag_link(t1, t2):
+ """Sort all_tags by count in descending order,
+ and by tags and links in ascending order
+ """
+ r = cmp(t1[0], t2[0])
+ if r:
+ return -r
+ return cmp((t1[1], t1[2]), (t2[1], t2[2]))
+
+all_tags = [(len(links), tag, links) for (tag, links) in all_tags.items()]
+all_tags.sort(by_count_rev_tag_link)
+
+write_template(0, year, month, day, all_titles[-20:], all_tags)
+
+new_text = ["""\
+## THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.
+#extends phd_pp_ru
+#implements respond
+#attr $Title = "Oleg Broytman's blog: tags"
+#attr $Description = "Broytman Russian Blog Tags Index Document"
+#attr $Copyright = 2006
+##
+#def body_html
+<h1>Теги</h1>
+
+<p class="head">
+<dl>
+"""]
+
+for count, tag, links in all_tags:
+ new_text.append("""\
+ <dt><a href="%s.html">%s (%d)</a></dt>
+""" % (tag, tag, count))
+
+ tag_text = ["""\
+## THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.
+#extends phd_pp_ru
+#implements respond
+#attr $Title = "Oleg Broytman's blog: tag %s"
+#attr $Description = "Broytman Russian Blog Tag %s Index Document"
+#attr $Copyright = 2006
+##
+#def body_html
+<h1>%s</h1>
+
+<p class="head">
+<ul>
+""" % (tag, tag, tag)]
+
+ count = 0
+ for year, month, day, filename, title, lead in reversed(links):
+ if lead:
+ lead = lead + ' '
+ else:
+ lead = ''
+ link = "../%s/%s/%s/%s" % (year, month, day, filename)
+ item_text = """<li><a href="%s">%s/%s/%s: %s%s</a></li>""" % (link, year, month, day, lead, title)
+
+ count += 1
+ if count <= 5:
+ new_text.append(" <dd>%s</dd>\n" % item_text)
+
+ tag_text.append(" %s\n" % item_text)
+
+ tag_text.append("""\
+</ul>
+</p>
+#end def
+$phd_pp_ru.respond(self)
+""")
+ write_if_changed(os.path.join(blog_root, "tags", tag+".tmpl"), ''.join(tag_text))
+
+new_text.append("""\
+</dl>
+</p>
+#end def
+$phd_pp_ru.respond(self)
+""")
+write_if_changed(os.path.join(blog_root, "tags", "index.tmpl"), ''.join(new_text))
+
+
+from atom_10 import atom_10
+from rss_20 import rss_20
+from news import NewsItem
+
+if blog_root:
+ baseURL = "http://phd.pp.ru/%s/" % blog_root
+else:
+ baseURL = "http://phd.pp.ru/"
+
+items = []
+for item in tuple(reversed(all_titles_tags))[:10]:
+ year, month, day, file, title, lead, tags = item
+ if lead:
+ lead = lead + ' '
+ else:
+ lead = ''
+ item = NewsItem(
+ "%s-%s-%s" % (year, month, day),
+ "%s%s" % (lead, title),
+ "%s/%s/%s/%s" % (year, month, day, file)
+ )
+ items.append(item)
+ item.baseURL = baseURL
+ item.categoryList = tags
+
+namespace = {
+ "title": "Oleg Broytman's blog",
+ "baseURL": baseURL,
+ "indexFile": "",
+ "description": "",
+ "lang": "ru",
+ "author": "Oleg Broytman",
+ "email": "phd@phd.pp.ru",
+ "generator": os.path.basename(sys.argv[0]),
+ "posts": items,
+}
+
+# For english dates
+locale.setlocale(locale.LC_TIME, 'C')
+
+atom_tmpl = str(atom_10(searchList=[namespace]))
+write_if_changed(os.path.join(blog_root, "atom_10.xml"), atom_tmpl)
+rss_tmpl = str(rss_20(searchList=[namespace]))
+write_if_changed(os.path.join(blog_root, "rss_20.xml"), rss_tmpl)