Skip to content

Commit

Permalink
style(search): display the score
Browse files Browse the repository at this point in the history
  • Loading branch information
razonyang committed Aug 17, 2022
1 parent d616d65 commit e8ab7ab
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
5 changes: 3 additions & 2 deletions assets/main/scss/_search.scss
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,22 @@
}
}

.search-result-score {
.search-result-score-rating {
font-size: 20px;
position: relative;
width: fit-content;

&::before {
content: "★★★★★";
}

span {
color: var(--#{$prefix}primary);
left: 0;
overflow: hidden;
position: absolute;

&::before {
color: gold;
content: "★★★★★";
}
}
Expand Down
2 changes: 1 addition & 1 deletion assets/main/scss/post/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
font-size: 0.875rem;
word-break: break-all;

span {
> span {
&:not(:last-child) {
margin-right: 0.125rem;

Expand Down
2 changes: 1 addition & 1 deletion assets/search/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ export class Search {
}

static formatScore(value) {
return (100 * (1 - value)).toFixed(0) + '%';
return ((1 - value) * 5).toFixed(1);
}

highlight(id, titleKeywords, contentKeywords) {
Expand Down
8 changes: 6 additions & 2 deletions assets/search/templates/result.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
<h2 class="card-title search-result-title fs-4 mt-2 mb-1 text-surface"><a href="{{permalink}}">{{title}}</a></h2>
<p class="text-success user-select-all mb-1 text-nowrap overflow-hidden text-truncate">{{permalink}}</p>
<div class="post-meta mb-2">
<span class="search-result-score text-nowrap overflow-hidden">
<span style="width: {{score}}"></span>
<span class="search-result-score-wrapper">
<span class="search-result-score">{{score}}</span>
<span class="search-result-score-rating text-nowrap overflow-hidden">
<span style="width: calc({{score}}/5*100%);">
</span>
</span>
</span>
<span class="post-lang">{{langName}}</span>
<span class="post-date">{{date}}</span>
Expand Down

0 comments on commit e8ab7ab

Please sign in to comment.