Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 34 additions & 11 deletions .github/workflows/update-index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,47 @@ jobs:
with:
fetch-depth: 0

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y jq
wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq
chmod +x /usr/bin/yq

- name: Generate data index
run: |
cd data
# Get directories and their last modified dates, sort by date descending
dirs=$(for d in */; do
# Get last modified date of any file in directory
last_mod=$(git log -1 --format=%at -- "$d")
echo "$last_mod $d"
done | sort -rn | cut -d' ' -f2 | sed 's/\///g')

# Create JSON array
echo -n '['> index.json
echo "$dirs" | sed 's/^/ "/;s/$/",/' | sed '$s/,$//' >> index.json
# Initialize JSON array
echo -n '[' > index.json

# Iterate through directories and parse frontmatter
first=true
for d in */; do
# Check if README.md exists
if [ -f "$d/README.md" ]; then
# Extract frontmatter (between --- lines) and convert to JSON
frontmatter=$(awk '/^---$/{if (p) exit; p=1; next}p' "$d/README.md" | yq eval -o=json)

if [ ! -z "$frontmatter" ]; then
# Add comma if not the first entry
if [ "$first" = false ]; then
echo -n ',' >> index.json
fi
first=false

# Add directory name and frontmatter to JSON
echo -n "{\"directory\": \"${d%/}\", \"frontmatter\": $frontmatter}" >> index.json
fi
fi
done

# Close JSON array
echo ']' >> index.json

- name: Commit changes
run: |
git config --global user.name 'GitHub Actions'
git config --global user.email 'actions@github.com'
git checkout -b update-index || git checkout update-index
git add data/index.json
git diff --staged --quiet || (git commit -m "Update data index" && git push)
git diff --staged --quiet || (git commit -m "Update data index with frontmatter" && git push origin update-index)
Loading