X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=tags.py;h=a4ae88b15ce64e980f95c1577c491dcbdd8d0453;hb=a269183254b03e72131d9060adad7ea0ee40ac56;hp=3fe860bdfab7fcfaa196726a11fc9bcae95ca7b0;hpb=8b3def415a8d3a454f522238396864aaffbd93d5;p=phdru.name%2Fcgi-bin%2Fblog-ru%2Fsearch-tags.git diff --git a/tags.py b/tags.py index 3fe860b..a4ae88b 100644 --- a/tags.py +++ b/tags.py @@ -17,12 +17,26 @@ else: # blog_dict is a mapping # (year, month, day) => [list of (file, title, lead, tags)] -def tag_exists(tag): +# Add lower-case tags +_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] + _posts.append((_file, _title, _lead, _tags, tags_lower)) +blog_dict = _new_dict + + +def real_tag(tag): + ltag = tag.lower() for posts in blog_dict.values(): - for _file, _title, _lead, _tags in posts: - if tag in _tags: - return True - return False + for _file, _title, _lead, _tags, _tags_lower in posts: + try: + ix = _tags_lower.index(ltag) + except ValueError: + continue + else: + return _tags[ix] def _test_post(post, tree): @@ -35,8 +49,7 @@ def _test_post(post, tree): if op == 'NAME': tag = tree[1] assert isinstance(tag, str) - _tags = post[3] - return tag in _tags + return tag.lower() in post[4] elif op in ('AND', 'OR'): value1 = _test_post(post, tree[1]) value2 = _test_post(post, tree[2])