Skip to content

Commit

Permalink
Fix github action, posts were not ordered by date
Browse files Browse the repository at this point in the history
Get post dates from the front matter metadata instead of git log, and also avoiding xargs, which are probably causing the error
  • Loading branch information
madacol committed Jul 6, 2024
1 parent ea10d65 commit 875aac0
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions bin/index.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

set -e

# Construct the index.html file

echo "Generating index.html"
Expand Down Expand Up @@ -35,10 +37,22 @@ htmlDoc="<!DOCTYPE html>
</head>
<body>
"
# Initialize an empty array to store the files
date_files=()

# Iterate over the arguments passed to the script
for file in "$@"
do
date=$(sed -n '/^---$/,/^---$/p' "$file" | sed -n 's/^date: //p')

# Append the file and its latest commit date to the files array
date_files+=("$date $file")
done

mapfile -t files < <(git ls-files -z "$@" | xargs -0 -I{} sh -c 'git log --follow --format="%ad {}" --date=short -- "{}" | tail -n 1' | sort -r | cut -d' ' -f2-)
# Sort the files array in reverse order based on the commit date
mapfile -t sorted_files < <(printf '%s\n' "${date_files[@]}" | sort -r | cut -d ' ' -f 2-)

for inputFile in "${files[@]}";
for inputFile in "${sorted_files[@]}"
do
echo "Parsing \"$inputFile\""

Expand Down

0 comments on commit 875aac0

Please sign in to comment.