Skip to content

Added Auto-Redirects System #326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 32 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e105444
Rename run-lighthouse.mdx to lighthouse-audits.mdx and add redirect
bdenham Jun 11, 2025
e965e32
Add test file
bdenham Jun 11, 2025
afc83c9
Rename test file - testing automated redirects
bdenham Jun 11, 2025
16ae172
Implement truly automated Git-based redirect generation - Replace cac…
bdenham Jun 11, 2025
6167146
Update documentation to reflect Git-based redirect system - Document …
bdenham Jun 11, 2025
3b6dbad
file name changes
bdenham Jun 11, 2025
09f65b0
Add test file for syntax fix
bdenham Jun 11, 2025
f97c9cf
Test redirect syntax generation
bdenham Jun 11, 2025
849b255
Fix redirect generation syntax bug - ensure proper template literal b…
bdenham Jun 11, 2025
61df131
Add test file for redirect testing
bdenham Jun 11, 2025
362a859
Rename test file to test redirect generation
bdenham Jun 11, 2025
cfb87ac
Clean up test file
bdenham Jun 11, 2025
cf4b3a6
renaming and testing redirect system
bdenham Jun 11, 2025
663a427
testing automated redirect system
bdenham Jun 11, 2025
b05c9f6
Add test file for redirect preservation test
bdenham Jun 11, 2025
8079709
Rename test file to verify redirect preservation
bdenham Jun 11, 2025
a531d23
Clean up redirect preservation test
bdenham Jun 11, 2025
7e31389
Fix critical redirect parsing bug and update documentation - Fixed ge…
bdenham Jun 12, 2025
434b27d
testing redirect system on file name change
bdenham Jun 12, 2025
ff347df
Add test file for redirect testing
bdenham Jun 12, 2025
485adbc
Rename test file to trigger redirect generation
bdenham Jun 12, 2025
40a09db
Add preservation test file
bdenham Jun 12, 2025
42202dd
Test redirect preservation
bdenham Jun 12, 2025
2757ab4
Test pre-commit hook
bdenham Jun 12, 2025
1df4866
Clean up test files
bdenham Jun 12, 2025
265a1ed
Add basic test file
bdenham Jun 12, 2025
2f05934
Test basic redirect generation
bdenham Jun 12, 2025
f5a7388
Add preservation test file
bdenham Jun 12, 2025
1547a70
Test redirect preservation
bdenham Jun 12, 2025
150c595
Add hook integration test file
bdenham Jun 12, 2025
55bff1b
Test Git hook redirect generation
bdenham Jun 12, 2025
341d95a
update PR_DESCRIPTION
bdenham Jun 12, 2025
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
42 changes: 42 additions & 0 deletions .githooks/post-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/sh

# Post-commit hook to verify redirects were properly handled

echo ""
echo "πŸ” Post-commit redirect verification..."

# Check if the last commit included astro.config.mjs changes
if git diff --name-only HEAD~1 HEAD | grep -q "astro.config.mjs"; then
echo "βœ… astro.config.mjs was updated in this commit"

# Show what redirects were added
echo "πŸ“‹ Redirect changes in this commit:"
git diff HEAD~1 HEAD astro.config.mjs | grep -E "^\+.*:" | sed 's/^+/ Added: /' || echo " (No new redirects detected in diff)"

echo ""
echo "🎯 Your redirects are now active! Old URLs will automatically redirect to new locations."

else
# Check if there were content changes but no config changes
content_changes=$(git diff --name-only HEAD~1 HEAD | grep -E "src/content/docs/|src/pages/")

if [ -n "$content_changes" ]; then
echo "ℹ️ Content files were changed but no redirects were added."
echo " This is normal if:"
echo " β€’ You only edited existing files (no moves/renames)"
echo " β€’ You added new files (no redirects needed)"
echo " β€’ Files were renamed with very similar names"
echo ""
echo " If you moved/renamed files and expected redirects, you can:"
echo " β€’ Run: pnpm redirects:generate"
echo " β€’ Check: pnpm redirects:test"
echo " β€’ Add manually to astro.config.mjs if needed"
fi
fi

echo ""
echo "πŸ’‘ Quick redirect commands:"
echo " β€’ Test all redirects: pnpm redirects:test"
echo " β€’ Generate missing redirects: pnpm redirects:generate"
echo " β€’ View current redirects: grep -A 20 'redirects:' astro.config.mjs"
echo ""
85 changes: 85 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/bin/sh

# Pre-commit hook to generate redirects automatically

echo "πŸ” Checking for content structure changes..."

# Check if any content files were moved, renamed, or deleted
content_changes=$(git diff --cached --name-status --diff-filter=DR -- 'src/content/docs/**' 'src/pages/**')

# Also check for renamed files (which might not show up in DR filter)
renamed_files=$(git diff --cached --name-status --diff-filter=R -- 'src/content/docs/**' 'src/pages/**')

# Check for any content files in the commit at all
any_content_changes=$(git diff --cached --name-status -- 'src/content/docs/**' 'src/pages/**')

if [ -n "$content_changes" ] || [ -n "$renamed_files" ] || [ -n "$any_content_changes" ]; then
if [ -n "$content_changes" ]; then
echo "πŸ“ Content deletions/moves detected:"
echo "$content_changes"
fi

if [ -n "$renamed_files" ]; then
echo "πŸ“ Content renames detected:"
echo "$renamed_files"
fi

echo ""
echo "πŸ”„ Running automatic redirect generation..."

# Run the redirect generation script in Git hook mode
export GIT_HOOK_MODE=1
if command -v pnpm >/dev/null 2>&1; then
pnpm redirects:generate
else
npm run redirects:generate
fi

redirect_exit_code=$?

if [ $redirect_exit_code -eq 0 ]; then
echo ""
echo "βœ… NEW REDIRECTS GENERATED!"
echo "πŸ“‹ The following redirects were added to astro.config.mjs:"
echo ""

# Show what redirects were added (if any)
if git diff --cached astro.config.mjs | grep -q "^+.*:"; then
git diff --cached astro.config.mjs | grep "^+.*:" | sed 's/^+/ /'
else
echo " (No new redirects detected in this commit)"
fi

echo ""
echo "🎯 These redirects ensure old URLs continue to work after your changes."
echo "βœ… astro.config.mjs has been staged with your commit."

echo ""
echo "πŸ§ͺ Testing redirects..."
if command -v pnpm >/dev/null 2>&1; then
pnpm redirects:test >/dev/null 2>&1 && echo "βœ… All redirects are working correctly!" || echo "⚠️ Some redirects may need attention"
else
npm run redirects:test >/dev/null 2>&1 && echo "βœ… All redirects are working correctly!" || echo "⚠️ Some redirects may need attention"
fi

echo ""
echo "βœ… Pre-commit redirect check completed!"
else
echo ""
echo "⚠️ Redirect generation encountered an issue."
echo " You can continue with the commit, but you may want to:"
echo " β€’ Check the redirect generation manually: pnpm redirects:generate"
echo " β€’ Test existing redirects: pnpm redirects:test"
echo ""
echo "Continue with commit anyway? [y/N]: "
read -r response
if [ "$response" != "y" ] && [ "$response" != "Y" ] && [ "$response" != "yes" ]; then
echo "Commit aborted. Please review and try again."
exit 1
fi
fi
else
echo "No content structure changes detected."
fi

echo ""
Loading