Skip to content
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

Script: generate list of redirect URLs #8086

Merged
merged 3 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions bdocs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ OPTIONS:
release Create the release body text for monthly releases
transform Transform reference links to inline links on 1 or more pages
clean Remove reference links that are not being used on 1 or more pages
redirects List the old URLs for all new redirects in this branch
help Display this help message and exit

EOF
Expand Down Expand Up @@ -79,6 +80,9 @@ case $1 in
fi
ruby "$PROJECT_ROOT/scripts/remove_unused_reference_links.rb" "$2"
;;
redirects)
"$PROJECT_ROOT/scripts/list_redirect_urls.sh"
;;
help)
display_help
;;
Expand Down
33 changes: 33 additions & 0 deletions scripts/list_redirect_urls.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash
#
# For each new redirect in the current branch, the script uses the user-supplied
# base URL to list all old URLs so the user can open old links directly from
# the terminal to test redirects.
#
# Usage: ./bdocs redirects

# Fetch the latest changes from the remote.
git fetch origin develop --quiet

# Check new redirects by comparing the current branch to develop.
NEW_REDIRECTS=$(git diff develop -- $PROJECT_ROOT/assets/js/broken_redirect_list.js)

# If there's no differences, print an error message and exit.
if [[ -z "$NEW_REDIRECTS" ]]; then
echo "Error: No new redirects were found in this branch."
echo ""
exit 1
fi

echo "Which base URL would you like to use? Note: You can use a local or deployment base URL."
echo""

# Read input and remove any trailing '/' (if applicable), to avoid double '//'.
read BASE_URL
if [[ "$BASE_URL" == */ ]]; then
BASE_URL="${BASE_URL%/}"
fi

# List all old URLs using 'BASE_URL' so the user can open links from terminal.
echo ""
echo "$NEW_REDIRECTS" | grep '^+' | grep -v '+++' | grep -v '^+$' | sed "s/^+validurls\['\([^']*\)'\].*/\1/" | sed "s|^|$BASE_URL|"