Skip to content

Commit

Permalink
Remove redundant chown commands and strip hashes from CSS/JS references
Browse files Browse the repository at this point in the history
  • Loading branch information
paskal committed Nov 1, 2024
1 parent 4ec9cfc commit 65cfcf9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 42 deletions.
35 changes: 3 additions & 32 deletions .github/workflows/ci-build-site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ jobs:
-e DO_NOT_MINIFY_HUGO=true \
radio-t/site:previous
# Copy the generated manifest.json from the old build
cp ${{ steps.set-dirs.outputs.old_dir }}/hugo/data/manifest.json ${{ steps.set-dirs.outputs.old_dir }}/manifest.json
# chown everything to the calling user as otherwise it's not possible to change it with sed and prettier later
sudo chown -R $USER:$USER ${{ steps.set-dirs.outputs.old_dir }}/public
Expand All @@ -102,8 +100,6 @@ jobs:
-e DO_NOT_MINIFY_HUGO=true \
radio-t/site:current
# Copy the generated manifest.json from the new build
cp ${{ steps.set-dirs.outputs.new_dir }}/hugo/data/manifest.json ${{ steps.set-dirs.outputs.new_dir }}/manifest.json
# chown everything to the calling user as otherwise it's not possible to change it with sed and prettier later
sudo chown -R $USER:$USER ${{ steps.set-dirs.outputs.new_dir }}/public
Expand All @@ -125,35 +121,10 @@ jobs:
sed -i 's#<itunes:subtitle>.*</itunes:subtitle>##' ${{ steps.set-dirs.outputs.old_dir }}/public/podcast-archives.rss
sed -i 's#<itunes:subtitle>.*</itunes:subtitle>##' ${{ steps.set-dirs.outputs.new_dir }}/public/podcast-archives.rss
- name: Copy New Manifest and Retrieve Old Manifest
- name: Remove hashes from CSS and JS files references
run: |
# Define paths to old and new manifests
old_manifest="${{ steps.set-dirs.outputs.old_dir }}/manifest.json"
new_manifest="${{ steps.set-dirs.outputs.new_dir }}/manifest.json"
set -x
# Compare manifest.json files and handle ID replacements if they differ
if cmp -s "$old_manifest" "$new_manifest"; then
echo "No differences in manifest.json. Skipping ID replacements."
exit 0
fi
# Extract and replace differing IDs
while IFS= read -r old_line && IFS= read -r new_line <&3; do
if [[ "$old_line" != "$new_line" ]]; then
# Extract ID from both lines
old_id=$(echo "$old_line" | grep -oP 'id=\K[^"]+')
new_id=$(echo "$new_line" | grep -oP 'id=\K[^"]+')
# Perform replacement if IDs differ
if [[ -n "$old_id" && -n "$new_id" && "$old_id" != "$new_id" ]]; then
find ${{ steps.set-dirs.outputs.new_dir }}/public -name '*.html' -exec sed -i "s?id=$new_id?id=$old_id?g" {} +
fi
fi
done <"$old_manifest" 3<"$new_manifest"
sex +x
find ${{ steps.set-dirs.outputs.old_dir }}/public -type f -exec sed -i 's/\(js\|css\)?id=[^"']\+//g' {} +
find ${{ steps.set-dirs.outputs.new_dir }}/public -type f -exec sed -i 's/\(js\|css\)?id=[^"']\+//g' {} +
- name: Generate diff
run: |
Expand Down
10 changes: 0 additions & 10 deletions hugo/data/manifest.json

This file was deleted.

0 comments on commit 65cfcf9

Please sign in to comment.