From 2d61fd654b3c829ba6f2ac99aa04c0b03d668e81 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Sun, 16 Jun 2024 16:27:04 +0300 Subject: [PATCH] Feat: Allow space in tags, replace it with underscore --- search-tags.py | 3 ++- tags.py | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/search-tags.py b/search-tags.py index a1380e7..228866b 100755 --- a/search-tags.py +++ b/search-tags.py @@ -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 a4ae88b..92a3706 100644 --- 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]) -- 2.39.2