Skip to content

Commit 5b1f5b4

Browse files
committed
Feat: 增加按 name、star、fork 数据排序,支持正序和倒序
Close #11
1 parent 53d5eae commit 5b1f5b4

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

assets/css/component-projects/repo-card.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
border-radius: var(--br-gh-repo-card);
4343
border-style: solid;
4444
border-width: var(--bw-gh-repo-card);
45+
// order: calc(-1 * var(--gh-repo-order, 0));
4546

4647
svg {
4748
display: inline-block;

layouts/section/projects.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,18 @@ <h2 id="{{ $group.title | anchorize }}" class="heading-element">
127127
{{- with $group.description -}}
128128
<p>{{- dict "Content" (. | $.RenderString) "Ruby" $params.ruby "Fraction" $params.fraction "Fontawesome" $params.fontawesome | partial "function/content.html" | safeHTML -}}</p>
129129
{{- end -}}
130+
{{- /* Order by name, star or fork */ -}}
131+
{{- $orderKeys := dict
132+
"name" "full_name"
133+
"star" "stargazers_count"
134+
"fork" "forks_count"
135+
-}}
136+
{{- with $group.orderby -}}
137+
{{- $orderKey := index $orderKeys . -}}
138+
{{- with $orderKey -}}
139+
{{- $repoInfoArr = sort $repoInfoArr . $group.order -}}
140+
{{- end -}}
141+
{{- end -}}
130142
{{- /* Repo cards */ -}}
131143
<div class="gh-repo-card-container">
132144
{{- range $repoInfo := $repoInfoArr -}}

projects.yml.example

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
- foo
88
collections:
99
- developed
10-
totalStars: false # whether to count total stars
10+
# whether to count total stars
11+
totalStars: false
12+
# Order by, optional values: ['default', 'name', 'star', 'fork']
13+
orderby: default
14+
# Order of repos, optional values: ['asc', 'desc']
15+
order: asc
1116
repos:
1217
- hugo-fixit/FixIt
1318
- title: My contributed
@@ -20,5 +25,7 @@
2025
collections:
2126
- contributed
2227
totalStars: false
28+
orderby: default
29+
order: asc
2330
repos:
2431
- gohugoio/hugo

0 commit comments

Comments
 (0)