From: Oleg Broytman
Date: Wed, 1 May 2024 14:57:08 +0000 (+0300)
Subject: Feat(blog): Encode tags
X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=0c0058d611f55ddae8c08726acb9952e5984f8da;p=phdru.name%2Fphdru.name.git
Feat(blog): Encode tags
A tag can be in Russian (koi8-r) with spaces.
---
diff --git a/phd_site.tmpl b/phd_site.tmpl
index 65bb058..67eb341 100644
--- a/phd_site.tmpl
+++ b/phd_site.tmpl
@@ -139,8 +139,12 @@ $style
#end if
$body
+#from urllib import quote
+#def encode_tag(tag):
+$quote(tag.decode('utf-8').encode('koi8-r').replace(' ', '_'))
+#end def
#def link_tag($tag)
-$tag
+$tag
#end def
#if $Tag
diff --git a/reindex_blog.py b/reindex_blog.py
index 0f1a8f5..0b7c2a6 100755
--- a/reindex_blog.py
+++ b/reindex_blog.py
@@ -2,9 +2,14 @@
# -*- coding: koi8-r -*-
__author__ = "Oleg Broytman "
-__copyright__ = "Copyright (C) 2006-2021 PhiloSoft Design"
+__copyright__ = "Copyright (C) 2006-2024 PhiloSoft Design"
import sys, os
+try:
+ from urllib.parse import quote
+except ImportError:
+ from urllib import quote
+
from Cheetah.Template import Template
from Cheetah.compat import string_type
from blog_db import blog_root, load_blog, save_blog
@@ -95,6 +100,8 @@ months_names_ru0 = ['', "
from news import write_if_changed
+def encode_tag(tag):
+ return quote(tag.replace(' ', '_'))
def write_template(level, year, month, day, titles, tags=None):
path = [blog_root]
@@ -234,7 +241,8 @@ def write_template(level, year, month, day, titles, tags=None):
first_tag = False
else:
new_text.append(' - ')
- new_text.append("""%s (%d)""" % (tag, tag, count))
+ new_text.append("""%s (%d)""" % (
+ encode_tag(tag), tag, count))
new_text.append('''
''')
@@ -362,7 +370,7 @@ linux
for i, (count, tag, links) in enumerate(all_tags):
new_text.append("""\
%s (%d)
-""" % (tag, tag, count))
+""" % (encode_tag(tag), tag, count))
first = all_tags[0][1]
if i == 0:
@@ -427,7 +435,9 @@ for i, (count, tag, links) in enumerate(all_tags):
#end def
$phd_site.respond(self)
""")
- write_if_changed(os.path.join(blog_root, "tags", tag+".tmpl"), ''.join(tag_text))
+ write_if_changed(os.path.join(blog_root, "tags",
+ tag.replace(' ', '_') + ".tmpl"),
+ ''.join(tag_text))
new_text.append("""\
@@ -545,7 +555,7 @@ for item in tuple(reversed(all_titles_tags))[:10]:
url_path)
items.append(item)
item.baseURL = baseURL
- item.categoryList = tags
+ item.categoryList = [t.decode('koi8-r').encode('utf-8') for t in tags]
body = bodies[(year, month, day, file)]
body = absolute_urls(body, baseURL + url_path)
try: