#!/bin/bash

# List of GitHub repositories
repos=(
    "atas/ssg"
    "cfenollosa/bashblog"
    "venthur/blag"
    "spekulatius/laravel-commonmark-blog"
    "imfunniee/gitfolio"
    "dannyvankooten/gozer"
    "hexojs/hexo"
    "hyde/hyde"
    "styxlab/next-cms-ghost"
    "jekyll/jekyll"
    "kabukky/journey"
    "sunainapai/makesite"
    "imathis/octopress"
    "getpelican/pelican"
    "williamd1k0/sake"
    "spress/Spress"
    "nakkaya/static"
    "vladris/tinkerer"
    "leonstafford"
)

# Function to get the last commit date
get_last_commit_date() {
    curl -s "https://api.github.com/repos/$1/commits" | jq -r '.[0].commit.author.date // empty'
}

# Check and collect activity data
activity_data=()
for repo in "${repos[@]}"; do
    last_commit_date=$(get_last_commit_date "$repo")
    if [[ ! -z "$last_commit_date" ]]; then
        activity_data+=("$repo: $last_commit_date")
    else
        activity_data+=("$repo: No recent activity or inaccessible")
    fi
done

# Sort and print the activity data
IFS=$'\n' sorted_activity_data=($(sort -t: -k2 <<<"${activity_data[*]}"))
unset IFS

echo "Repository activity (sorted by date):"
for data in "${sorted_activity_data[@]}"; do
    echo "$data"
done