Skip to content
This repository has been archived by the owner on Apr 3, 2022. It is now read-only.

Commit

Permalink
[REPEKA-1033] Display whole title and author in search results
Browse files Browse the repository at this point in the history
Change-Id: I3c194b5dc0f9940af3207b4c7dd081ba1cf37e83
  • Loading branch information
lendek57 authored and fracz committed May 8, 2019
1 parent f77a921 commit 396843e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
32 changes: 19 additions & 13 deletions app/Resources/views/redo/resources-list-element.twig
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,22 @@
<h2 class="resource-name no-margin-top no-margin-bottom">
<a href="/resources/{{ resource.id }}">
{% if highlightedMetadata is defined and highlightedMetadata.tytul is defined %}
{{ highlightedMetadata.tytul.highlights[0] | raw }}
{{ valueWithHighlights(resource | m('tytul'), highlightedMetadata.tytul.highlights[0]) | raw }}
{% set highlightedMetadata = arrayWithoutItem(highlightedMetadata, 'tytul') %}
{% else %}
{{ resource | metadata('tytul') | default(resource | metadata('label')) }}
{% endif %}
</a>
</h2>
{% if resource | metadata('autor') is not empty %}
<div class="resource-author">{{ resource | metadata('autor') }}</div>
{% endif %}
<div class="resource-author">
{% set author = resource | m('autor') %}
{% if highlightedMetadata is defined and highlightedMetadata.autor is defined %}
{{ valueWithHighlights(author, highlightedMetadata.autor.highlights[0]) | raw }}
{% set highlightedMetadata = arrayWithoutItem(highlightedMetadata, 'autor') %}
{% elseif author is not empty %}
{{ author }}
{% endif %}
</div>
<div>
<span class="metadata-label">{{ 'Type'| trans }}:</span> {{ resource.kind.label | inCurrentLanguage }}
</div>
Expand Down Expand Up @@ -77,18 +83,18 @@
<span class="metadata-label">{{ 'page' | trans }} {{ highlight.pageNumber }}</span>
{{ highlight.highlight | raw }}
</a>
{% else %}
{{ highlight | raw }}
{% endif %}
{% else %}
<div class="metadata-details">
{% if resourceAvailable %}
<span class="metadata-label">{{ 'page' | trans }} {{ highlight.pageNumber }}</span>
{{ highlight.highlight | raw }}
{% else %}
<span class="metadata-label">{{ 'File' | trans }}</span>
{{ highlight | raw }}
{% endif %}
{% else %}
<div class="metadata-details">
{% if resourceAvailable %}
<span class="metadata-label">{{ 'page' | trans }} {{ highlight.pageNumber }}</span>
{{ highlight.highlight | raw }}
{% else %}
<span class="metadata-label">{{ 'File' | trans }}</span>
{{ highlight | raw }}
{% endif %}
</div>
{% endif %}
{% endfor %}
Expand Down
6 changes: 6 additions & 0 deletions src/Repeka/Plugins/Redo/Twig/TwigRedoExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function getFunctions() {
return [
new \Twig_Function('getUserDataMapping', [$this, 'getUserDataMapping']),
new \Twig_Function('insertLinks', [$this, 'insertLinks']),
new \Twig_Function('valueWithHighlights', [$this, 'addHighlightsToMetadataValue']),
];
}

Expand Down Expand Up @@ -62,4 +63,9 @@ public function insertLinks(MetadataValue $value, iterable $keywordMetadataList)
}
return $value->withNewValue($str);
}

public function addHighlightsToMetadataValue(string $value, string $highlight): string {
$valueWithoutHighlights = preg_replace('%</?em>%', '', $highlight);
return preg_replace("/$valueWithoutHighlights/", $highlight, $value);
}
}

0 comments on commit 396843e

Please sign in to comment.