Browse Source

Hide Title in link info if topic title is similar

merge-requests/85/head
Deimos 5 years ago
parent
commit
a9fe491ad2
  1. 7
      tildes/tildes/views/topic.py

7
tildes/tildes/views/topic.py

@ -5,6 +5,7 @@
from collections import namedtuple from collections import namedtuple
from decimal import Decimal from decimal import Decimal
from difflib import SequenceMatcher
from typing import Any, Dict, Optional, Union from typing import Any, Dict, Optional, Union
from marshmallow import missing, ValidationError from marshmallow import missing, ValidationError
@ -395,6 +396,12 @@ def get_topic(request: Request, comment_order: CommentTreeSortOption) -> dict:
fields_to_hide = ("Domain", "Description") fields_to_hide = ("Domain", "Description")
for field in fields_to_hide: for field in fields_to_hide:
content_metadata.pop(field, None) content_metadata.pop(field, None)
# don't include the title if it's pretty similar to the topic's title
if "Title" in content_metadata:
similarity = SequenceMatcher(a=content_metadata["Title"], b=topic.title)
if similarity.ratio() >= 0.6:
del content_metadata["Title"]
else: else:
content_metadata = None content_metadata = None

Loading…
Cancel
Save