]> git.phdru.name Git - phdru.name/cgi-bin/blog-ru/search-tags.git/commitdiff
Feat: Allow space in tags, replace it with underscore
authorOleg Broytman <phd@phdru.name>
Sun, 16 Jun 2024 13:27:04 +0000 (16:27 +0300)
committerOleg Broytman <phd@phdru.name>
Sat, 22 Jun 2024 03:48:59 +0000 (06:48 +0300)
search-tags.py
tags.py

index a1380e7afaaf3dcef9c55ee74e123f130f589337..228866b8a8f5fa625dbc6d3bba5523351693a7c2 100755 (executable)
@@ -38,7 +38,8 @@ else:
             rtag = real_tag(tag)
             if rtag:
                 redirect(
-                    "/Russian/blog/tags/%s.html" % rtag, status="301 Moved")
+                    "/Russian/blog/tags/%s.html" % rtag.replace(' ', '_'),
+                    status="301 Moved")
                 sys.exit()
             status = "404 Tag not found"
             title = "Ошибка!"
diff --git a/tags.py b/tags.py
index a4ae88b15ce64e980f95c1577c491dcbdd8d0453..92a37060cc32c81f3bddb7838795cc683e8548e4 100644 (file)
--- a/tags.py
+++ b/tags.py
@@ -22,13 +22,13 @@ _new_dict = {}
 for (year, month, day), posts in blog_dict.items():
     _new_dict[year, month, day] = _posts = []
     for _file, _title, _lead, _tags in posts:
-        tags_lower = [tag.lower() for tag in _tags]
+        tags_lower = [tag.lower().replace(' ', '_') for tag in _tags]
         _posts.append((_file, _title, _lead, _tags, tags_lower))
 blog_dict = _new_dict
 
 
 def real_tag(tag):
-    ltag = tag.lower()
+    ltag = tag.lower().replace(' ', '_')
     for posts in blog_dict.values():
         for _file, _title, _lead, _tags, _tags_lower in posts:
             try:
@@ -36,7 +36,7 @@ def real_tag(tag):
             except ValueError:
                 continue
             else:
-                return _tags[ix]
+                return _tags[ix].replace(' ', '_')
 
 
 def _test_post(post, tree):
@@ -49,7 +49,7 @@ def _test_post(post, tree):
     if op == 'NAME':
         tag = tree[1]
         assert isinstance(tag, str)
-        return tag.lower() in post[4]
+        return tag.lower().replace(' ', '_') in post[4]
     elif op in ('AND', 'OR'):
         value1 = _test_post(post, tree[1])
         value2 = _test_post(post, tree[2])