Skip to content

Commit 8880002

Browse files
committed
feat(sorting): update, if necessary, instead of force-adding fields and values
1 parent 2c8cc63 commit 8880002

File tree

2 files changed

+39
-16
lines changed

2 files changed

+39
-16
lines changed

scripts/sort_themes.nu

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export def codeberg [
8989
export def clone [
9090
link: string # Git link of the repository.
9191
--temp: string = '/tmp/firefoxcss-store/' # Temporary folder to save themes.
92-
]: record<owner: string, name: string> -> record<pushed_at: string, stargazers_count: int, avatar: string> {
92+
]: record<owner: string, name: string> -> string {
9393

9494
mkdir $temp
9595

@@ -114,13 +114,7 @@ export def clone [
114114
cd $folder
115115
}
116116

117-
let pushed_at = ^git show --quiet --date='format-local:%Y-%m-%dT%H:%M:%SZ' --format="%cd"
118-
119-
{
120-
pushed_at: $pushed_at
121-
stargazers_count: -1
122-
avatar: ""
123-
}
117+
^git show --quiet --date='format-local:%Y-%m-%dT%H:%M:%SZ' --format="%cd"
124118
}
125119

126120
# Parse link of repository.
@@ -150,9 +144,11 @@ export def main [
150144
let data = open $source
151145
| each {|item|
152146

147+
mut item = $item
148+
153149
let link = $item.repository
154150

155-
print $"Cloning ($link)."
151+
print $"Retrieving information from '($link)'."
156152

157153
let info = if ($link | str contains 'github') {
158154
sleep $delay
@@ -165,18 +161,45 @@ export def main [
165161
$link | parse_link | codeberg $codeberg
166162
} else {
167163
print "Using git cloning."
168-
$link | parse_link | clone $link
164+
165+
let pushed_at = $link | parse_link | clone $link
166+
167+
# If this theme hasn't been manually updated yet,
168+
# which means, added the values for stars and avatar url,
169+
# then, assign default value.
170+
if not ('avatar' in $item) {
171+
print "Need to update 'avatar' and 'stargazers_count'."
172+
{
173+
pushed_at: $pushed_at
174+
stargazers_count: -1
175+
avatar: ''
176+
}
177+
# Default values for manually updated theme, but
178+
# the field 'pushed_at'.
179+
} else {
180+
{
181+
pushed_at: $pushed_at
182+
stargazers_count: $item.stargazers_count
183+
avatar: $item.avatar
184+
}
185+
}
169186
}
170187

188+
# Failed all attempts at retrieving information for this repository,
189+
# Probably needs removal or it's deleted already,
190+
# so it will remove automatically.
171191
if ($info | is-empty) {
172-
print $"Could not clone this repository."
192+
print $"Could not clone this repository!"
173193
print ""
174194
} else {
175195
print ""
176-
{
177-
...$item
178-
...$info
179-
}
196+
197+
# Update sorting columns.
198+
$item | update 'pushed_at' $info.pushed_at
199+
$item | update 'stargazers_count' $info.stargazers_count
200+
$item | update 'avatar' $info.avatar
201+
202+
$item
180203
}
181204
}
182205

themes.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2101,4 +2101,4 @@
21012101
"stargazers_count": 302,
21022102
"avatar": "https://avatars.githubusercontent.com/u/42596339?v=4"
21032103
}
2104-
]
2104+
]

0 commit comments

Comments
 (0)