X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=reindex_blog.py;h=beba7c12823ae151a8f5de6619c9776758b9d713;hb=c58548208c6b0e6ca029b3d3b34c6e01ddbea247;hp=92a02272ea79c60a9f79b0ae21fe8733d6fa47f2;hpb=6d775fb85dad6e10928e0e418645124a804a4275;p=phdru.name%2Fphdru.name.git diff --git a/reindex_blog.py b/reindex_blog.py index 92a0227..beba7c1 100755 --- a/reindex_blog.py +++ b/reindex_blog.py @@ -5,7 +5,7 @@ __version__ = "$Revision$"[11:-2] __revision__ = "$Id$"[5:-2] __date__ = "$Date$"[7:-2] __author__ = "Oleg Broytman " -__copyright__ = "Copyright (C) 2006 PhiloSoft Design" +__copyright__ = "Copyright (C) 2006-2010 PhiloSoft Design" import sys, os @@ -39,6 +39,10 @@ else: blog = {} years = {} +# bodies is a dictionary mapping file => body + +bodies = {} + # Walk the directory recursively for dirpath, dirs, files in os.walk(blog_root): d = os.path.basename(dirpath) @@ -51,7 +55,7 @@ for dirpath, dirs, files in os.walk(blog_root): template = Template(file=fullpath) title_parts = template.Title.split() title = ' '.join(title_parts[6:]) - lead = getattr(template, "Lead", None) + lead = template.Lead tags = template.Tag if isinstance(tags, basestring): @@ -77,6 +81,9 @@ 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) + bodies[key] = template.body() # Need to save the blog? if blog <> old_blog: @@ -130,8 +137,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 = (("application/atom+xml", "News [Atom 1.0]", "atom_10.xml"), - ("application/rss+xml", "News [RSS 2.0]", "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 @@ -167,11 +178,6 @@ def write_template(level, year, month, day, titles, tags=None): iday = int(day) imonth = int(month) - new_text.append("""\ -#attr $Next = "%s" -""" % titles[0][3]) - - if len(titles) == 1: new_text.append("""\ #attr $refresh = "0; URL=%s" @@ -212,23 +218,25 @@ def write_template(level, year, month, day, titles, tags=None): else: new_text.append('\n

%s %s

' % (day, months_names_ru[int(month)])) save_date = year, month, day - if lead: - lead = lead + ' ' - else: - lead = '' new_text.append('''

%s%s.

-''' % (lead, href, title)) +''' % (lead+' ' if lead else '', href, title)) if level == 0: new_text.append("""

îÏ×ÏÓÔÅ×ÁÑ ÌÅÎÔÁ × ÆÏÒÍÁÔÁÈ -Atom 1.0 RSS 2.0 . + +Atom 1.0 ÔÏÌØËÏ ÚÁÇÏÌÏ×ËÉ / +Atom 1.0 / +Atom 1.0 ÐÏÌÎÙÅ ÔÅËÓÔÙ +RSS 2.0 ÔÏÌØËÏ ÚÁÇÏÌÏ×ËÉ / +RSS 2.0 / +RSS 2.0 ÐÏÌÎÙÅ ÔÅËÓÔÙ.

""") @@ -339,17 +347,49 @@ new_text = ["""\
"""] -for count, tag, links in all_tags: +for i, (count, tag, links) in enumerate(all_tags): new_text.append("""\
%s (%d)
""" % (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 @@ -357,16 +397,12 @@ for count, tag, links in all_tags: