diff --git a/common/static/lib/js/tag-input.js b/common/static/lib/js/tag-input.js index dfea1edf..8070df31 100644 --- a/common/static/lib/js/tag-input.js +++ b/common/static/lib/js/tag-input.js @@ -114,7 +114,7 @@ function inputTags(configs) { tags_arr = []; for (let i = 0; i < tags.length; i++) { - tags_arr.push(tags[i].textContent.toLowerCase()); + tags_arr.push(tags[i].textContent.replace(/\s+/g, ' ').trim()); } this.tags_array = tags_arr; @@ -143,4 +143,4 @@ function inputTags(configs) { _privateMethods.init(configs); // return false; -} \ No newline at end of file +} diff --git a/journal/models.py b/journal/models.py index 1636ed86..af1e4d1f 100644 --- a/journal/models.py +++ b/journal/models.py @@ -963,10 +963,14 @@ class Tag(List): @staticmethod def cleanup_title(title, replace=True): - t = title.strip().lower() - # t = re.sub(r"\W", "_", title.strip().lower()) + t = re.sub(r"\s+", " ", title.strip()) return "_" if not title and replace else t + @staticmethod + def deep_cleanup_title(title): + """Remove all non-word characters, only for public index purpose""" + return re.sub(r"\W+", " ", title).strip() + class TagManager: @staticmethod @@ -978,7 +982,10 @@ class TagManager: .annotate(frequency=Count("owner")) .order_by("-frequency")[:20] ) - return sorted(list(map(lambda t: t["title"], tags))) + tag_titles = [ + t for t in set(map(lambda t: Tag.deep_cleanup_title(t["title"]), tags)) if t + ] + return tag_titles @staticmethod def all_tags_for_user(user, public_only=False):