Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] Remove prefix and suffix from site-search result titles #6033

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions fec/home/templatetags/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ def web_app_url(path):
return "{}{}".format(settings.FEC_APP_URL, path)


@register.filter(name='remove_title_pre_suf_fix')
def remove_title_pre_suf_fix(str):
"""
Removes 'FEC | ' prefix and ' - FEC.gov' suffix' from search.gov search result title
"""
str = re.sub(r'(^FEC \| | - FEC\.gov$)', '', str)
return str


@register.filter()
def highlight_matches(text):
"""
Expand Down Expand Up @@ -189,3 +198,5 @@ def get_file_type(value):
file_type = "EXCEL" if xl else file_extension

return file_type


2 changes: 1 addition & 1 deletion fec/search/templates/search/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ <h2 class="u-float-left u-no-margin">Other pages</h2>
{% for result in results.site.results %}
<li class="post post--icon">
<h3>
<i class="icon icon--inline--left {% if result.icon == 'page' %}i-document{% else %}i-table{% endif %}"></i><a href="{{ result.url }}">{{ result.title | highlight_matches }}</a>
<i class="icon icon--inline--left {% if result.icon == 'page' %}i-document{% else %}i-table{% endif %}"></i><a href="{{ result.url }}">{{ result.title | remove_title_pre_suf_fix | highlight_matches }}</a>
</h3>
<div class="post__path t-small t-sans">{{ result.url }}</div>
<p class="post__preview t-note">{{ result.snippet | highlight_matches }}</p>
Expand Down