]> git.phdru.name Git - phdru.name/phdru.name.git/blobdiff - reindex_blog.py
Added Lead.
[phdru.name/phdru.name.git] / reindex_blog.py
index 5c14d4693590138f44db0fe794b8f95ca8339e39..fd82c1839111ae59ddcd7a7e86eace33d7b9a715 100755 (executable)
@@ -39,6 +39,11 @@ else:
 blog = {}
 years = {}
 
+# excerpts nd bodies are dictionaries mapping file => excerpt/body
+
+excerpts = {}
+bodies = {}
+
 # Walk the directory recursively
 for dirpath, dirs, files in os.walk(blog_root):
    d = os.path.basename(dirpath)
@@ -77,6 +82,10 @@ for dirpath, dirs, files in os.walk(blog_root):
 
          if day not in days: days.append(day)
 
+         file = file[:-len("tmpl")] + "html"
+         key = (year, month, day, file)
+         excerpts[key] = template.get_first_p()
+         bodies[key] = template.Body
 
 # Need to save the blog?
 if blog <> old_blog:
@@ -130,8 +139,12 @@ def write_template(level, year, month, day, titles, tags=None):
 #attr $Title = "Oleg Broytman's blog"
 #attr $Description = "Broytman Russian Blog Index Document"
 #attr $Copyright = %(cyear)s
-#attr $alternates = (("News [Atom 1.0]", "application/atom+xml", "atom_10.xml"),
-                     ("News [RSS 2.0]",  "application/rss+xml",  "rss_20.xml")
+#attr $alternates = (("Новости [Atom 1.0] только заголовки", "application/atom+xml", "atom_10_titles.xml"),
+                     ("Новости [Atom 1.0]", "application/atom+xml", "atom_10.xml"),
+                     ("Новости [Atom 1.0] полные тексты", "application/atom+xml", "atom_10_full.xml"),
+                     ("Новости [RSS 2.0] только заголовки",  "application/rss+xml",  "rss_20_titles.xml"),
+                     ("Новости [RSS 2.0]",  "application/rss+xml",  "rss_20.xml"),
+                     ("Новости [RSS 2.0] полные тексты",  "application/rss+xml",  "rss_20_full.xml"),
 )
 ##
 #def body_html
@@ -222,8 +235,14 @@ def write_template(level, year, month, day, titles, tags=None):
 <hr>
 
 <p class="head">Новостевая лента в форматах
-<A HREF="atom_10.xml">Atom 1.0 <img src="../../Graphics/atom_10.jpg" border=0></A>
-и <A HREF="rss_20.xml">RSS 2.0 <img src="../../Graphics/rss_20.jpg" border=0></A>.
+<img src="../../Graphics/atom_10.jpg" border=0>
+<A HREF="atom_10_titles.xml">Atom 1.0 только заголовки</A> /
+<A HREF="atom_10.xml">Atom 1.0</A> /
+<A HREF="atom_10_full.xml">Atom 1.0 полные тексты</A>
+и <img src="../../Graphics/rss_20.jpg" border=0>
+<A HREF="rss_20_titles.xml">RSS 2.0 только заголовки</A> /
+<A HREF="rss_20.xml">RSS 2.0</A> /
+<A HREF="rss_20_full.xml">RSS 2.0 полные тексты</A>.
 </p>
 """)
 
@@ -334,17 +353,49 @@ new_text = ["""\
 <dl>
 """]
 
-for count, tag, links in all_tags:
+for i, (count, tag, links) in enumerate(all_tags):
    new_text.append("""\
    <dt><a href="%s.html">%s (%d)</a></dt>
 """ % (tag, tag, count))
 
+   first = all_tags[0][1]
+   if i == 0:
+      prev = None
+   else:
+      prev = all_tags[i-1][1]
+   if i >= len(all_tags)-1:
+      next = None
+   else:
+      next = all_tags[i+1][1]
+   last = all_tags[-1][1]
+
    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"
+""" % (tag, tag)]
+
+   tag_text.append("""\
+#attr $First = "%s"
+""" % first)
+
+   if prev:
+      tag_text.append("""\
+#attr $Prev = "%s"
+""" % prev)
+
+   if next:
+      tag_text.append("""\
+#attr $Next = "%s"
+""" % next)
+
+   tag_text.append("""\
+#attr $Last = "%s"
+""" % last)
+
+   tag_text.append("""\
 #attr $Copyright = 2006
 ##
 #def body_html
@@ -352,7 +403,7 @@ for count, tag, links in all_tags:
 
 <p class="head">
 <ul>
-""" % (tag, tag, tag)]
+""" % tag)
 
    count = 0
    for year, month, day, filename, title, lead in reversed(links):
@@ -410,6 +461,8 @@ for item in tuple(reversed(all_titles_tags))[:10]:
    items.append(item)
    item.baseURL = baseURL
    item.categoryList = tags
+   item.excerpt = excerpts[(year, month, day, file)]
+   item.body = bodies[(year, month, day, file)]
 
 namespace = {
    "title": "Oleg Broytman's blog",
@@ -430,3 +483,19 @@ 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)
+
+for item in items:
+    item.excerpt = None
+
+atom_tmpl = str(atom_10(searchList=[namespace]))
+write_if_changed(os.path.join(blog_root, "atom_10_titles.xml"), atom_tmpl)
+rss_tmpl = str(rss_20(searchList=[namespace]))
+write_if_changed(os.path.join(blog_root, "rss_20_titles.xml"), rss_tmpl)
+
+for item in items:
+    item.content = item.body
+
+atom_tmpl = str(atom_10(searchList=[namespace]))
+write_if_changed(os.path.join(blog_root, "atom_10_full.xml"), atom_tmpl)
+rss_tmpl = str(rss_20(searchList=[namespace]))
+write_if_changed(os.path.join(blog_root, "rss_20_full.xml"), rss_tmpl)