From b25d39da7f0c82ada38a343542f5c23e5c7d03bd Mon Sep 17 00:00:00 2001 From: Jason Date: Sat, 12 Apr 2025 09:40:56 -0500 Subject: [PATCH 1/2] upd(ci): Update update-index.yml --- .github/workflows/update-index.yml | 43 ++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/.github/workflows/update-index.yml b/.github/workflows/update-index.yml index 98ab0f6..61e0bcd 100644 --- a/.github/workflows/update-index.yml +++ b/.github/workflows/update-index.yml @@ -18,24 +18,45 @@ jobs: with: fetch-depth: 0 + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y yq jq + - 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) From 4217831d7cb90335a7325688436779ba26651106 Mon Sep 17 00:00:00 2001 From: Jason Date: Sat, 12 Apr 2025 09:45:02 -0500 Subject: [PATCH 2/2] fix: Add yq --- .github/workflows/update-index.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/update-index.yml b/.github/workflows/update-index.yml index 61e0bcd..45238d2 100644 --- a/.github/workflows/update-index.yml +++ b/.github/workflows/update-index.yml @@ -21,7 +21,9 @@ jobs: - name: Install dependencies run: | sudo apt-get update - sudo apt-get install -y yq jq + 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: |