outfile.close()
-def write_template(level, year, month, day, titles):
+def write_template(level, year, month, day, titles, tags=None):
path = []
if level >= 1:
path.append(year)
years = {}
for year, month, day, file, title, lead in save_titles:
years[year] = True
- first_year = True
new_text.append('''
<hr>
-<p class="years">
+<p class="noindent"><a href="tags/">Теги</a>:
+''')
+ first_tag = True
+ for count, tag, links in all_tags:
+ if first_tag:
+ first_tag = False
+ else:
+ new_text.append(' - ')
+ new_text.append("""<a href="tags/%s.html">%s (%d)</a>""" % (tag, tag, count))
+ new_text.append('''
+</p>
+''')
+
+ new_text.append('''
+<p class="noindent">По годам:
''')
+ first_year = True
for year in sorted(years.keys()):
if first_year:
first_year = False
tag_links = all_tags[tag]
else:
tag_links = all_tags[tag] = []
- tag_links.append('/'.join(("..", year, month, day, file)))
+ 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)
-write_template(0, year, month, day, all_titles[-20:])
all_tags = [(len(links), tag, links) for (tag, links) in all_tags.items()]
all_tags.sort()
+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
##
#def body_html
<H1>Теги</H1>
+
+<p class="head">
+<dl>
"""]
for count, tag, links in all_tags:
- new_text.append("""
-<p class="head"><a href="%s.html">%s (%d)</a></p>
+ new_text.append("""\
+ <dt><a href="%s.html">%s (%d)</a></dt>
""" % (tag, tag, count))
tag_text = ["""\
##
#def body_html
<H1>%s</H1>
+
+<p class="head">
+<ul>
""" % (tag, tag, tag)]
- for link in links:
- junk, year, month, day, filename = link.split('/')
- tag_text.append("""
-<p class="head"><a href="%s">%s/%s/%s: %s</a></p>
-""" % (link, year, month, day, filename))
+ 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("tags", tag+".tmpl"), ''.join(tag_text))
new_text.append("""\
+</dl>
+</p>
#end def
$phd_pp_ru.respond(self)
""")