render playlists pages
This commit is contained in:
parent
1c35e99ed2
commit
f0e8bafc4c
4 changed files with 242 additions and 0 deletions
67
generate-playlist-pages.sh
Executable file
67
generate-playlist-pages.sh
Executable file
|
|
@ -0,0 +1,67 @@
|
|||
#!/bin/bash
|
||||
|
||||
# ============================================
|
||||
# Generate Hugo Playlist Pages from JSON
|
||||
# ============================================
|
||||
|
||||
DATA_FILE="data/playlists/playlists.json"
|
||||
CONTENT_DIR="content/playlists"
|
||||
|
||||
# Check if data file exists
|
||||
if [ ! -f "$DATA_FILE" ]; then
|
||||
echo "❌ Error: $DATA_FILE not found. Run fetch-playlist.sh first."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create content directory
|
||||
mkdir -p "$CONTENT_DIR"
|
||||
|
||||
# Create _index.md if it doesn't exist
|
||||
if [ ! -f "$CONTENT_DIR/_index.md" ]; then
|
||||
cat > "$CONTENT_DIR/_index.md" << 'EOF'
|
||||
---
|
||||
title: "Playlists"
|
||||
---
|
||||
EOF
|
||||
fi
|
||||
|
||||
# Clear old playlist pages (keep _index.md)
|
||||
find "$CONTENT_DIR" -maxdepth 1 -type f -name "*.md" ! -name "_index.md" -delete
|
||||
|
||||
# Process each playlist
|
||||
cat "$DATA_FILE" | jq -c '.playlists[]' | while read -r playlist; do
|
||||
NAME=$(echo "$playlist" | jq -r '.name // "Untitled Playlist"')
|
||||
SLUG=$(echo "$NAME" | tr ' ' '-' | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9-]//g' | sed 's/--*/-/g' | sed 's/^-//;s/-$//')
|
||||
|
||||
# If slug is empty, use the ID
|
||||
if [ -z "$SLUG" ] || [ "$SLUG" = "untitled-playlist" ]; then
|
||||
SLUG=$(echo "$playlist" | jq -r '.id' | head -c 12)
|
||||
fi
|
||||
|
||||
DESCRIPTION=$(echo "$playlist" | jq -r '.description // ""')
|
||||
IMAGE=$(echo "$playlist" | jq -r '.image // ""')
|
||||
TRACKS=$(echo "$playlist" | jq -c '.tracks')
|
||||
PLAYLIST_ID=$(echo "$playlist" | jq -r '.id')
|
||||
CREATED_AT=$(echo "$playlist" | jq -r '.created_at')
|
||||
|
||||
# Convert created_at to date
|
||||
CREATED_DATE=$(date -d "@$CREATED_AT" "+%Y-%m-%d" 2>/dev/null || echo $(date "+%Y-%m-%d"))
|
||||
|
||||
cat > "$CONTENT_DIR/$SLUG.md" <<EOF
|
||||
---
|
||||
title: "$NAME"
|
||||
date: $CREATED_DATE
|
||||
draft: false
|
||||
playlist_id: "$PLAYLIST_ID"
|
||||
playlist_description: "$DESCRIPTION"
|
||||
playlist_image: "$IMAGE"
|
||||
playlist_tracks: $TRACKS
|
||||
playlist_created_at: $CREATED_AT
|
||||
---
|
||||
EOF
|
||||
|
||||
echo "✅ Generated: $CONTENT_DIR/$SLUG.md"
|
||||
done
|
||||
|
||||
echo ""
|
||||
echo "📊 Generated $(find "$CONTENT_DIR" -maxdepth 1 -type f -name "*.md" ! -name "_index.md" | wc -l) playlist pages"
|
||||
Loading…
Add table
Add a link
Reference in a new issue