From a9fe491ad25b34471eea32f8c8a995452d2b883f Mon Sep 17 00:00:00 2001 From: Deimos Date: Sun, 1 Dec 2019 19:02:56 -0700 Subject: [PATCH] Hide Title in link info if topic title is similar --- tildes/tildes/views/topic.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tildes/tildes/views/topic.py b/tildes/tildes/views/topic.py index 994676b..9e6358b 100644 --- a/tildes/tildes/views/topic.py +++ b/tildes/tildes/views/topic.py @@ -5,6 +5,7 @@ from collections import namedtuple from decimal import Decimal +from difflib import SequenceMatcher from typing import Any, Dict, Optional, Union from marshmallow import missing, ValidationError @@ -395,6 +396,12 @@ def get_topic(request: Request, comment_order: CommentTreeSortOption) -> dict: fields_to_hide = ("Domain", "Description") for field in fields_to_hide: 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: content_metadata = None