Skip to content

Commit

Permalink
Update search page
Browse files Browse the repository at this point in the history
  • Loading branch information
razonyang committed Nov 17, 2020
1 parent 9406ebc commit 5f02bd0
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion assets/css/main.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/js/search.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions layouts/_default/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ <h2 class="search-result-title mb-4">
{{- end -}}
</div>
<div class="search-result-meta mb-3">
<span class="search-result-score"><i class="fas fa-fw fa-star"></i> {{ printf "{{score}}%%" }}</span>
<span class="search-result-score"><i class="fas fa-fw fa-star"></i> {{ printf "{{{score}}}" }}</span>
</div>
</div>
</script>
Expand All @@ -66,6 +66,6 @@ <h2 class="search-result-title mb-4">
{{ i18n "search_no_results" }}
</script>
<script type="text/html" id="templateStat">
{{ i18n "search_stat" (dict "Total" "<span class=\"search-keyword\">{{total}}</span>") | safeHTML }}
{{ i18n "search_stat" (dict "Total" "<span class=\"text-accent\">{{total}}</span>") | safeHTML }}
</script>
{{ end }}
6 changes: 6 additions & 0 deletions src/scss/_color.scss
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,9 @@ $yellow-primary-light: #ffb04c;
.bg-yellow {
background-color: #{$yellow-primary} !important;
}

/* text colors */

.text-accent {
color: var(--hbs-accent) !important;
}
4 changes: 0 additions & 4 deletions src/search/index.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.search-keyword {
color: var(--hbs-accent);
}

.search-stat,
.search-result-content {
color: var(--hbs-secondary-text);
Expand Down
13 changes: 11 additions & 2 deletions src/search/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class Search {

public highlightOptions = {
element: 'span',
className: 'search-keyword',
className: 'text-accent',
};

public tmplMissingKeywords: string;
Expand Down Expand Up @@ -194,7 +194,7 @@ export class Search {
categories: result.item.categories,
tags: result.item.tags,
series: result.item.series,
score: (100*(1-result.score)).toFixed(2),
score: instance.formatScore(result.score),
url: function() {
return instance.normalizeTaxonomy;
}
Expand All @@ -209,6 +209,15 @@ export class Search {
this.page += 1;
}

formatScore(score) {
score = 100*(1-score)
if (score < 90) {
return score.toFixed(2) + '%'
}

return `<span class="text-accent">${score.toFixed(2)}%</span>`
}

highlight(id, titleKeywords, contentKeywords) {
const titleHighlighter = new Mark(document.querySelectorAll(`#${id} .search-result-title`));
titleHighlighter.mark(titleKeywords, this.highlightOptions);
Expand Down

0 comments on commit 5f02bd0

Please sign in to comment.