diff --git a/bdocs b/bdocs index a3ae44c966a..841d8d5c276 100755 --- a/bdocs +++ b/bdocs @@ -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 @@ -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 ;; diff --git a/scripts/list_redirect_urls.sh b/scripts/list_redirect_urls.sh new file mode 100755 index 00000000000..c01e63fdc64 --- /dev/null +++ b/scripts/list_redirect_urls.sh @@ -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|"