12
12
13
13
# Update README with a list of all cheat sheets defined
14
14
readme_update () {
15
+
16
+ # Check "last_updated" field to update stars/forks in extra-cheat-sheets.json
17
+ max_updates=15
18
+ jq -c ' . | to_entries[]' extra-cheat-sheets.json | while read -r entry; do
19
+ # Eventual consistency, do no update to much to not hit GitHub API quota
20
+ if [ " $max_updates " -le 0 ]; then
21
+ break
22
+ fi
23
+
24
+ key=$( echo " $entry " | jq -r ' .key' )
25
+ value=$( echo " $entry " | jq -r ' .value' )
26
+ last_updated=$( echo " $value " | jq -r ' .last_updated // empty' )
27
+
28
+ if [ -z " $last_updated " ] || [ " $( date -d " $last_updated " +%s 2> /dev/null || echo 0) " -lt " $( date -d ' 30 days ago' +%s) " ]; then
29
+ echo " Updating stats for $key "
30
+ max_updates=$(( max_updates - 1 ))
31
+
32
+ repo=$( echo " $value " | jq -r ' .github' )
33
+ if [ -n " $repo " ]; then
34
+ repo_api_url=" https://api.github.com/repos/$repo "
35
+ repo_data=$( curl -s " $repo_api_url " )
36
+ stars=$( echo " $repo_data " | jq -r ' .stargazers_count // 0' )
37
+ forks=$( echo " $repo_data " | jq -r ' .forks_count // 0' )
38
+
39
+ jq --arg key " $key " --arg stars " $stars " --arg forks " $forks " --arg date " $( date -I) " \
40
+ ' .[$key] |= . + {stars: ($stars | tonumber), forks: ($forks | tonumber), last_updated: $date}' extra-cheat-sheets.json > tmp.json && mv tmp.json extra-cheat-sheets.json
41
+ set +x
42
+ fi
43
+ fi
44
+ done
45
+
15
46
sed -i ' /<!-- marker -->/,$ d' README.md
16
47
(
17
48
echo ' <!-- marker -->'
@@ -35,11 +66,11 @@ readme_update() {
35
66
# Append extra sheet sheets
36
67
printf " \n## Installable External Cheat Sheets\n\n"
37
68
printf " \nIt is impossible to cover all important topics, so [lzone.de](https://lzone.de) supports adding all the following content too.\n\n"
38
- printf " | Cheat Sheet | Type | Category |\n"
39
- printf " | --- | --- | --- |\n"
69
+ printf " | Cheat Sheet | Stars | Type | Category |\n"
70
+ printf " | --- | --- | --- | --- | \n"
40
71
41
72
while read extra; do
42
- jq -r ' . | to_entries[] | select(.key == "' " $extra " ' ") | .value | "| [' " $extra " ' ]("+(.github)+") | "+(.type)+" | "+(.category)+" | "' extra-cheat-sheets.json || true
73
+ jq -r ' . | to_entries[] | select(.key == "' " $extra " ' ") | .value | "| [' " $extra " ' ]("+(.github)+") | ⭐"+(.stars // "unknown" | tostring)+" | "+(.type)+" | "+(.category)+" | "' extra-cheat-sheets.json || true
43
74
done < <( jq -r " . | to_entries[] | .key" extra-cheat-sheets.json | LANG=C sort) | \
44
75
sed -e " s/| Tutorial |/| 💡 Tutorial |/g" \
45
76
-e " s/| Book |/| 📕 Book |/g" \
0 commit comments