I hoped that my alma mater would keep my account open but that turned out to not be the case. University’s data got compromised and they pushed us to change our passwords. When I did attempt to change it the respective website didn’t work. After the password got deactivated I contacted the helpdesk which informed me my account will not be activated as I have no formal relation to the faculty and the alumni access is not yet implemented. Anyway, this made me revisit my old migration code and setup my page on GitHub ↗.

In the following, I present an upgraded version of my migration code that creates a website that for each html file contains a redirection to the proper new web address.

Template file for the redirection orig.html:

<!DOCTYPE html>
<html>
  <head>
    <title>Page Moved</title>
    <meta http-equiv="refresh" content="0; URL=base/address" />
  </head>
  <body>
    This page has moved. Click <a href="base/address">here</a> to go to the new page.
  </body>
</html>

Bash script migrate.sh that scans a directory and creates a folder with proper redirections:

#!/usr/bin/env bash

base="https://exampleaccount.github.io"

(cd ../dist/ && find . -iname "*.html" > ../migration/pages.txt)

rm -rf ./generated/
mkdir -p ./generated/
cat < ./pages.txt | while read -r line; do
    final_path="./generated/$line"
    final_dir="$(dirname "$final_path")"
    tmp_file="$(basename "$final_path")"
    address_file="$(basename "$line")"
    if [[ "$tmp_file" == "index.html" ]]; then
        address_file=""
    fi
    address_dir="$(dirname "$line")"
    if [[ "$address_dir" == "." ]]; then
        address_dir=""
    else
        address_dir="${address_dir:2:1000}/"
    fi
    mkdir -p "$final_dir"
    echo '---'
    echo "$final_path"
    echo "$final_dir"
    echo "$tmp_file"
    echo "$address_file"
    cp orig.html copy.html
    sed -i 's|base|'"$base"'|g' copy.html
    sed -i 's|address|'"$address_dir$address_file"'|g' copy.html
    cp copy.html "$final_path"
done
rm -f ./copy.html
rm -f ./pages.txt

The script assumes that the old website resides in folder ../dist/ and the script is in folder named migration. The result is placed into folder generated. There are a few if statements that make the address a little bit nicer, as hugo ignores index.html when creating a final page url.