diff options
author | Achilleas Pipinellis <axil@gitlab.com> | 2023-03-28 12:41:59 +0300 |
---|---|---|
committer | Achilleas Pipinellis <axil@gitlab.com> | 2023-03-28 12:41:59 +0300 |
commit | 743fbcc863c1c4d1a4649c2208401deadbed3457 (patch) | |
tree | 9e6c4760840b016f1885d716cd3fce799ad6595f | |
parent | 55761258d91c46d343e307563d4c6b1e03327da6 (diff) | |
parent | f5f318646328d3fa8c7958ebdc2cb42bc6f6b25a (diff) |
Merge branch 'eread/add-color-to-normalize-links-script' into 'main'
Add color to normalize links script
See merge request https://gitlab.com/gitlab-org/gitlab-docs/-/merge_requests/3707
Merged-by: Achilleas Pipinellis <axil@gitlab.com>
Approved-by: Achilleas Pipinellis <axil@gitlab.com>
Co-authored-by: Evan Read <eread@gitlab.com>
-rwxr-xr-x | scripts/normalize-links.sh | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/scripts/normalize-links.sh b/scripts/normalize-links.sh index bfaf2bd7..69eff755 100755 --- a/scripts/normalize-links.sh +++ b/scripts/normalize-links.sh @@ -1,5 +1,9 @@ #!/usr/bin/env bash +COLOR_RED="\e[31m" +COLOR_GREEN="\e[32m" +COLOR_RESET="\e[39m" + TARGET="$1" # The directory that has all the HTML files including versions. # Usually public/ locally and /site in the Docker image. @@ -15,8 +19,8 @@ if [ "$(uname)" == "Darwin" ]; then if hash gsed 2>/dev/null; then SED="gsed" else - echo "✖ ERROR: The built-in sed in macOS is not supported. - Install gnu-sed instead: 'brew install gnu-sed'." >&2 + # shellcheck disable=2059 + printf "${COLOR_RED}ERROR: The built-in sed in macOS is not supported. Run 'make setup'.${COLOR_RESET}\n" >&2 exit 1 fi else @@ -26,19 +30,22 @@ fi if [ -z "$TARGET" ]; then echo "Usage: $0 <target> <version>" echo "Example: $0 public 13.0" - echo "No target provided. Exiting." + # shellcheck disable=2059 + printf "${COLOR_RED}ERROR: No target provided.${COLOR_RESET}\n" exit 1 fi if [ -z "$VER" ]; then echo "Usage: $0 <target> <version>" echo "Example: $0 public 13.0" - echo "No version provided. Exiting." + # shellcheck disable=2059 + printf "${COLOR_RED}ERROR: No version provided.${COLOR_RESET}\n" exit 1 fi if ! [ -d "$TARGET/$VER" ]; then - echo "Target directory $TARGET/$VER does not exist. Exiting." + # shellcheck disable=2059 + printf "${COLOR_RED}ERROR: Target directory $TARGET/$VER does not exist.${COLOR_RESET}\n" exit 1 fi @@ -50,7 +57,9 @@ fi ## ## Relative URLs ## -echo "=> Replace relative URLs in $TARGET/$VER for HTML files" + +# shellcheck disable=2059 +printf "${COLOR_GREEN}INFO: Replacing relative URLs in $TARGET/$VER for HTML files...${COLOR_RESET}\n" find "${TARGET}/$VER" -type f -name '*.html' -print0 | xargs -0 "$SED" -i -e 's|href="/ee/|href="/'"$VER"'/ee/|g' \ -e 's|href="/runner/|href="/'"$VER"'/runner/|g' \ -e 's|href="/omnibus/|href="/'"$VER"'/omnibus/|g' \ @@ -61,21 +70,26 @@ find "${TARGET}/$VER" -type f -name '*.html' -print0 | xargs -0 "$SED" -i -e 's| -e 's|<a href="/">|<a href="/'"$VER"'/">|g' \ -e 's|href="/opensearch.xml|href="/'"$VER"'/opensearch.xml|g' -echo "=> Replace relative URLs in $TARGET/$VER for CSS files" +# shellcheck disable=2059 +printf "${COLOR_GREEN}INFO: Replacing relative URLs in $TARGET/$VER for CSS files...${COLOR_RESET}\n" find "${TARGET}/$VER" -type f -name '*.css' -print0 | xargs -0 "$SED" -i 's|/assets/|/'"$VER"'/assets/|g' -echo "=> Replace relative URLs in $TARGET/$VER for JavaScript files" +# shellcheck disable=2059 +printf "${COLOR_GREEN}INFO: Replacing relative URLs in $TARGET/$VER for JavaScript files...${COLOR_RESET}\n" find "${TARGET}/$VER" -type f -name '*.js' -print0 | xargs -0 "$SED" -i -e 's|/search/|/'"$VER"'/search/|g' \ -e 's|/assets/|/'"$VER"'/assets/|g' ## ## Full URLs ## -echo "=> Replace full URLs in $TARGET/$VER for HTML files" + +# shellcheck disable=2059 +printf "${COLOR_GREEN}INFO: Replacing full URLs in $TARGET/$VER for HTML files...${COLOR_RESET}\n" find "${TARGET}/$VER" -type f -name '*.html' -print0 | xargs -0 "$SED" -i -e 's|href="https://docs.gitlab.com/ee/|href="/'"$VER"'/ee/|g' \ -e 's|href="https://docs.gitlab.com/runner/|href="/'"$VER"'/runner/|g' \ -e 's|href="https://docs.gitlab.com/omnibus/|href="/'"$VER"'/omnibus/|g' \ -e 's|href="https://docs.gitlab.com/charts/|href="/'"$VER"'/charts/|g' \ -e 's|href="https://docs.gitlab.com/operator/|href="/'"$VER"'/operator/|g' -echo "=> Fix URLs inside the sitemap" +# shellcheck disable=2059 +printf "${COLOR_GREEN}INFO: Fixing URLs inside the sitemap...${COLOR_RESET}\n" find "${TARGET}/$VER" -type f -name 'sitemap.xml' -print0 | xargs -0 "$SED" -i 's|docs.gitlab.com/|docs.gitlab.com/'"$VER"'/|g' |