]> git.phdru.name Git - phdru.name/phdru.name.git/commitdiff
Feat(blog): Encode tags master
authorOleg Broytman <phd@phdru.name>
Wed, 1 May 2024 14:57:08 +0000 (17:57 +0300)
committerOleg Broytman <phd@phdru.name>
Wed, 1 May 2024 15:30:11 +0000 (18:30 +0300)
A tag can be in Russian (koi8-r) with spaces.

phd.py
phd_site.tmpl
reindex_blog.py

diff --git a/phd.py b/phd.py
index a68db56e5cb2b4f601bdc84f398ab7ecd93c4cd3..4aa206c47fc1637a83cc65b1b6955a9efbc1fbdd 100644 (file)
--- a/phd.py
+++ b/phd.py
@@ -166,7 +166,7 @@ class phd(Template):
             % quote_string(query)
 
     def lurkmoar(self, query):
-        return "https://lurkmore.to/%s" % quote_string(
+        return "http://lurklurk.com/%s" % quote_string(
             query.replace(' ', '_'), ext_safe=',')
 
 
index 65bb058a079d02463b720786570452ecbeac1367..67eb3412546901353bbb619c3e55bad2b3373f4b 100644 (file)
@@ -139,8 +139,12 @@ $style
 #end if
 </p>
 $body
+#from urllib import quote
+#def encode_tag(tag):
+$quote(tag.decode('utf-8').encode('koi8-r').replace(' ', '_'))
+#end def
 #def link_tag($tag)
-<a href="../../../tags/${tag}.html">$tag</a>
+<a href="../../../tags/${encode_tag(tag)}.html">$tag</a>
 #end def
 #if $Tag
 <hr width="90%">
index 0f1a8f5f9b185fe34ccecbdf8f2b297f3bd0b3d0..0b7c2a6dd9fbf39af81f038f172c0b998470b84b 100755 (executable)
@@ -2,9 +2,14 @@
 # -*- coding: koi8-r -*-
 
 __author__ = "Oleg Broytman <phd@phdru.name>"
-__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("""<a href="tags/%s.html">%s (%d)</a>""" % (tag, tag, count))
+         new_text.append("""<a href="tags/%s.html">%s (%d)</a>""" % (
+             encode_tag(tag), tag, count))
       new_text.append('''
 </p>
 ''')
@@ -362,7 +370,7 @@ linux 
 for i, (count, tag, links) in enumerate(all_tags):
    new_text.append("""\
    <dt><a href="%s.html">%s (%d)</a></dt>
-""" % (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("""\
 </dl>
@@ -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: