11#! /bin/bash
22
33# 1. Capture the version from the first argument
4- VERSION =$1
4+ INPUT_VERSION =$1
55
66# 2. Check if a version was provided
7- if [ -z " $VERSION " ]; then
7+ if [ -z " $INPUT_VERSION " ]; then
88 echo " Usage: $0 <version>"
99 echo " Example: $0 1.28"
10+ echo " Example: $0 current"
1011 exit 1
1112fi
1213
13- # 3. Define paths relative to this script's location
14- # $(dirname "$0") is the 'hack' folder. /.. moves up to the root.
14+ # 3. Handle specific redirection mapping logic
15+ if [ " $INPUT_VERSION " == " current" ]; then
16+ # Map 'current' to 'devel'
17+ DEST_VERSION=" devel"
18+ elif [[ " $INPUT_VERSION " =~ -r c[0-9]+$ ]]; then
19+ # Strip -rc suffix (e.g., 1.27.0-rc1 -> 1.27.0)
20+ DEST_VERSION=$( echo " $INPUT_VERSION " | sed -E ' s/-rc[0-9]+$//' )
21+ else
22+ # Keep as is
23+ DEST_VERSION=" $INPUT_VERSION "
24+ fi
25+
26+ # 4. Define paths relative to this script's location
1527SCRIPT_DIR=" $( cd " $( dirname " $0 " ) " && pwd) "
1628ROOT_DIR=" $SCRIPT_DIR /.."
17- BASE_DIR=" $ROOT_DIR /assets/documentation/$VERSION "
18- BASE_URL=" https://cloudnative-pg.io/docs/$VERSION "
29+ BASE_DIR=" $ROOT_DIR /assets/documentation/$INPUT_VERSION "
30+ BASE_URL=" https://cloudnative-pg.io/docs/$DEST_VERSION "
1931
20- # Special handling of "current"
21- if [ $VERSION = " current" ]
22- then
23- BASE_URL=" https://cloudnative-pg.io/docs/devel"
24- fi
25-
26- # The message displayed to users
32+ # The message requested
2733MSG_TITLE=" CloudNativePG documentation has moved"
2834MSG_BODY=" CloudNativePG has changed the way we build and organize our documentation to provide a better experience."
2935
30- # 4 . Check if the target directory exists
36+ # 5 . Check if the target directory exists
3137if [ ! -d " $BASE_DIR " ]; then
3238 echo " Error: Directory not found at $BASE_DIR "
33- echo " Make sure you are passing the correct version and the assets folder exists."
3439 exit 1
3540fi
3641
37- echo " Searching for index.html files in: $BASE_DIR "
42+ echo " Source Version: $INPUT_VERSION "
43+ echo " Target URL Version: $DEST_VERSION "
44+ echo " Searching for index.html files..."
3845
39- # 5 . Find and process files
46+ # 6 . Find and process files
4047find " $BASE_DIR " -type f -name " index.html" | while read -r file; do
4148
4249 # Calculate the slug
43- # We strip the absolute path to the base directory to get the relative piece
4450 rel_path=${file# " $BASE_DIR /" }
45-
46- # Remove the filename suffix (/index.html)
4751 slug=${rel_path%/ index.html}
4852
4953 # Handle the root index.html case
@@ -53,9 +57,6 @@ find "$BASE_DIR" -type f -name "index.html" | while read -r file; do
5357 new_url=" $BASE_URL /$slug "
5458 fi
5559
56- echo " Updating: assets/documentation/$VERSION /$rel_path "
57- echo " -> $new_url "
58-
5960 # Overwrite the file
6061 cat << EOF > "$file "
6162<!DOCTYPE html>
7677done
7778
7879echo " ------------------------------------------------"
79- echo " Success: All files in $VERSION updated from the hack folder ."
80+ echo " Success: All files in $INPUT_VERSION have been updated ."
0 commit comments