strip space for personal tags; deep clean non charactors for public tags

This commit is contained in:
Your Name 2023-06-06 21:24:06 -04:00 committed by Henri Dickson
parent a4177d4833
commit b576281126
2 changed files with 12 additions and 5 deletions

View file

@ -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;
}
}

View file

@ -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):