2017-07-23 04:59:47 -07:00
|
|
|
#!/bin/bash
|
|
|
|
# rank_hugo_themes.bash
|
|
|
|
|
|
|
|
REPOS_API_URL="https://api.github.com/repos"
|
|
|
|
|
|
|
|
# initialize an empty array
|
|
|
|
HUGO_THEME_REPOS=
|
|
|
|
|
|
|
|
# and now populate HUGO_THEME_REPOS list
|
|
|
|
for hugo_theme_commit_url in \
|
|
|
|
"$(curl -s https://api.github.com/repos/gohugoio/hugoThemes/contents/ \
|
|
|
|
| grep git_url | grep -v null | grep -v gohugoio | awk '{print $2}' \
|
|
|
|
| sed -e 's/git\/trees/commits/g' | sed -e 's/,$//g')"
|
|
|
|
do
|
|
|
|
HUGO_THEME_REPOS+=($hugo_theme_commit_url)
|
|
|
|
done
|
|
|
|
|
|
|
|
HUGO_THEME_REPOS_LIST_LENGTH="${#HUGO_THEME_REPOS[@]}"
|
|
|
|
|
2017-07-26 23:07:14 -07:00
|
|
|
# Test Make Sure We Have A HUGO_THEME_REPOS list
|
|
|
|
[[ "${HUGO_THEME_REPOS_LIST_LENGTH}" -gt 20 ]] || { echo "error: HUGO_THEME_REPOS_LIST not parsed" ; exit ;}
|
|
|
|
|
2017-07-23 04:59:47 -07:00
|
|
|
# just a few at a time because of github api limit
|
|
|
|
|
|
|
|
for num in {1..4}
|
|
|
|
do
|
|
|
|
# pick a random hugo theme repo
|
2017-07-26 23:07:14 -07:00
|
|
|
url=""
|
2017-07-23 04:59:47 -07:00
|
|
|
url=${HUGO_THEME_REPOS[$((RANDOM%$HUGO_THEME_REPOS_LIST_LENGTH))]}
|
2017-07-26 23:07:14 -07:00
|
|
|
[[ -n "${url}" ]] || continue
|
|
|
|
|
|
|
|
hugo_theme_user=""
|
2017-07-23 04:59:47 -07:00
|
|
|
hugo_theme_user=$(echo $url | awk -F"/" '{print $5}')
|
2017-07-26 23:07:14 -07:00
|
|
|
[[ "${#hugo_theme_user}" -gt 2 ]] || continue
|
|
|
|
|
|
|
|
hugo_theme=""
|
2017-07-23 04:59:47 -07:00
|
|
|
hugo_theme=$(echo $url | awk -F"/" '{print $6}')
|
2017-07-26 23:07:14 -07:00
|
|
|
[[ "${#hugo_theme_user}" -gt 2 ]] || continue
|
|
|
|
|
|
|
|
commit_hash=""
|
2017-07-23 04:59:47 -07:00
|
|
|
commit_hash=$(echo $url | awk -F"/" '{print $8}' | sed -e 's/"//g')
|
2017-07-26 23:07:14 -07:00
|
|
|
[[ "${#commit_hash}" -gt 2 ]] || continue
|
|
|
|
|
|
|
|
stars=""
|
2017-07-23 04:59:47 -07:00
|
|
|
stars=$(curl -s "${REPOS_API_URL}/${hugo_theme_user}/${hugo_theme}" \
|
2017-07-31 06:45:01 -07:00
|
|
|
| grep stargazers_count | head -1 | awk '{print $2}' \
|
|
|
|
| sed -e 's/,$//g')
|
2017-07-26 23:07:14 -07:00
|
|
|
[[ -n "${stars}" ]] || continue
|
|
|
|
|
|
|
|
last_commit_date=""
|
2017-07-23 04:59:47 -07:00
|
|
|
last_commit_date=$(curl -s \
|
|
|
|
"${REPOS_API_URL}/${hugo_theme_user}/${hugo_theme}/commits/${commit_hash}" \
|
|
|
|
| grep date | head -1 | awk '{print $2}' | sed -e 's/"//g')
|
2017-07-26 23:07:14 -07:00
|
|
|
[[ -n "${last_commit_date}" ]] || continue
|
|
|
|
printf "%-30s %-30s %-30s %30s\n" "$stars" "$hugo_theme" \
|
2017-07-23 04:59:47 -07:00
|
|
|
"$hugo_theme_user" "$last_commit_date" >> ~/bin/rank_hugo_themes.log
|
|
|
|
done
|
|
|
|
|
|
|
|
# modify to taste
|
2017-09-21 00:10:39 -07:00
|
|
|
sort -rn ~/bin/rank_hugo_themes.log | uniq > ~/bin/rank_hugo_themes.report
|