commit 4684ccd4ea9b997583069b118270e4b2532e69a3
parent 9105cbfa71b9ead90645a54ba69ffc8ebe308a06
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Tue, 26 Aug 2025 18:32:36 +0200
Manage URL redirects
Use hooks to generate HTML pages that redirect to new content or create
a link to a new archive location instead of using an .htaccess file
specific to Apache servers.
Diffstat:
6 files changed, 156 insertions(+), 50 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -13,3 +13,5 @@ man
*.hook
.hooks
.index
+solstice.html
+high-tune
diff --git a/htrdr/hooks/01-setup-redirections.sh b/htrdr/hooks/01-setup-redirections.sh
@@ -0,0 +1,82 @@
+#!/bin/sh
+
+# Copyright (C) 2017-2025 |Méso|Star> (contact@meso-star.com)
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. "../scripts/meso-web.sh"
+
+set -e
+
+redirections="\
+ high-tune/high-tune.html htrdr/htrdr.html
+ high-tune/starter-pack.html htrdr/htrdr-atmosphere-spk.html
+ high-tune/downloads/gas_opt_prop_en.pdf htrdr/downloads/gas_opt_prop_en.pdf
+ high-tune/downloads/High-Tune-Starter-Pack-0.1.1.tar.gz htrdr/downloads/High-Tune-Starter-Pack-0.1.1.tar.gz
+ high-tune/downloads/High-Tune-Starter-Pack-0.1.1.tar.gz.sig htrdr/downloads/High-Tune-Starter-Pack-0.1.1.tar.gz.sig
+ high-tune/downloads/High-Tune-Starter-Pack-0.2.0.tar.gz htrdr/downloads/High-Tune-Starter-Pack-0.2.0.tar.gz
+ high-tune/downloads/High-Tune-Starter-Pack-0.2.0.tar.gz.sig htrdr/downloads/High-Tune-Starter-Pack-0.2.0.tar.gz.sig
+ high-tune/downloads/High-Tune-Starter-Pack-0.3.0.tar.gz htrdr/downloads/High-Tune-Starter-Pack-0.3.0.tar.gz
+ high-tune/downloads/High-Tune-Starter-Pack-0.3.0.tar.gz.sig htrdr/downloads/High-Tune-Starter-Pack-0.3.0.tar.gz.sig
+ high-tune/downloads/High-Tune-Starter-Pack-0.4.0.tar.gz htrdr/downloads/High-Tune-Starter-Pack-0.4.0.tar.gz
+ high-tune/downloads/High-Tune-Starter-Pack-0.4.0.tar.gz.sig htrdr/downloads/High-Tune-Starter-Pack-0.4.0.tar.gz.sig
+ high-tune/downloads/High-Tune-Starter-Pack-0.5.0.tar.gz htrdr/downloads/High-Tune-Starter-Pack-0.5.0.tar.gz
+ high-tune/downloads/High-Tune-Starter-Pack-0.5.0.tar.gz.sig htrdr/downloads/High-Tune-Starter-Pack-0.5.0.tar.gz.sig
+ high-tune/downloads/High-Tune-Starter-Pack-0.6.0.tar.gz htrdr/downloads/High-Tune-Starter-Pack-0.6.0.tar.gz
+ high-tune/downloads/High-Tune-Starter-Pack-0.6.0.tar.gz.sig htrdr/downloads/High-Tune-Starter-Pack-0.6.0.tar.gz.sig
+ high-tune/man/man1/htpp.1.html htrdr/man/man1/htpp.1.html
+ high-tune/man/man1/htrdr.1.html htrdr/man/man1/htrdr.1.html
+ high-tune/man/man1/htrdr-atmosphere.1.html htrdr/man/man1/htrdr-atmosphere.1.html
+ high-tune/man/man1/htrdr-combustion.1.html htrdr/man/man1/htrdr-combustion.1.html
+ high-tune/man/man1/les2htcp.1.html htrdr/man/man1/les2htcp.1.html
+ high-tune/man/man5/atrri.5.html htrdr/man/man5/atrri.5.html
+ high-tune/man/man5/atrtp.5.html htrdr/man/man5/atrtp.5.html
+ high-tune/man/man5/htcp.5.html htrdr/man/man5/htcp.5.html
+ high-tune/man/man5/htmie.5.html htrdr/man/man5/htmie.5.html
+ high-tune/man/man5/htrdr-image.5.html htrdr/man/man5/htrdr-image.5.html
+ high-tune/man/man5/htrdr-materials.5.html htrdr/man/man5/htrdr-materials.5.html
+ high-tune/man/man5/htrdr-obj.5.html htrdr/man/man5/htrdr-obj.5.html
+ high-tune/man/man5/mrumtl.5.html htrdr/man/man5/mrumtl.5.html
+ high-tune/man/man5/sth.5.html htrdr/man/man5/smsh.5.html
+ htrdr/man/man1/htrdr-planeto.1.html htrdr/man/man1/htrdr-planets.1.html"
+
+redirection()
+{
+ sed -e "s;@REDIRECTION@;$1;g" -e 's;@TIME@;5;g' \
+ templates/redirect.html
+}
+
+cd .. # Move to the root of working directory
+
+printf "%s\n" "${redirections}" | \
+while read -r i; do
+
+ from="$(printf '%s\n' "${i}" | cut -d' ' -f1)"
+
+ # Set the destination file relative to the source file directory
+ to="$(printf '%s\n' "${i}" | cut -d' ' -f2)"
+ to="$(relpath_to_dir "${from}" "${PWD}")${to}"
+
+ >&2 printf 'Redirecting %s to %s\n' "${from}" "${to}"
+
+ mkdir -p "$(dirname "${from}")"
+
+ if [ "${from##*.}" = "html" ]; then
+ redirection "${to}" > "${from}"
+ else
+ ln -sf "${to}" "${from}"
+ fi
+
+ printf '%s\n' "${from}"
+done
diff --git a/scripts/meso-web.sh b/scripts/meso-web.sh
@@ -37,6 +37,39 @@ sections()
| sed -e 's/[[:space:]]/\\ /g'
}
+# Print the absolute dir of the input file
+absdir() # file
+{
+ if [ -d "$1" ]; then
+ cd -- "$1" || exit 1
+ else
+ cd -- "$(dirname "$1")" || exit 1
+ fi
+ echo "${PWD}"
+ cd "${OLDPWD}" || exit 1
+}
+
+# Print relative path from input file to a dir
+relpath_to_dir() # file, dir
+(
+ # Build directory from worktree to path
+ _dir0="$(absdir "$1")"
+ _dir1="$(absdir "$2")"
+
+ _dir0="$(printf '%s\n' "${_dir0}" | sed "s;^${_dir1}[/]\{0,\};;g")"
+
+ # Ensure that the directory is a subpath of the worktree
+ if ! [ -d "${_dir1}/${_dir0}" ]; then
+ >&2 printf '%s: %s is not a subdirectory of %s\n' \
+ "$0" "${_dir0}" "${_dir1}"
+ return 1
+ fi
+
+ echo "${_dir0}" | sed 's/\//\n/g' | while read -r _i; do
+ printf "../"
+ done
+)
+
# Inline the HTML formatting of a table listing archive to download
print_downloads() # section, archive_prefix, OS ...
(
@@ -147,36 +180,3 @@ print_downloads() # section, archive_prefix, OS ...
printf '</table>\n'
printf '\n'
)
-
-# Print the absolute dir of the input file
-absdir() # file
-{
- if [ -d "$1" ]; then
- cd -- "$1" || exit 1
- else
- cd -- "$(dirname "$1")" || exit 1
- fi
- echo "${PWD}"
- cd "${OLDPWD}" || exit 1
-}
-
-# Print relative path from input file to a dir
-relpath_to_dir() # file, dir
-(
- # Build directory from worktree to path
- _dir0="$(absdir "$1")"
- _dir1="$(absdir "$2")"
-
- _dir0="$(printf '%s\n' "${_dir0}" | sed "s;^${_dir1}[/]\{0,\};;g")"
-
- # Ensure that the directory is a subpath of the worktree
- if ! [ -d "${_dir1}/${_dir0}" ]; then
- >&2 printf '%s: %s is not a subdirectory of %s\n' \
- "$0" "${_dir0}" "${_dir1}"
- return 1
- fi
-
- echo "${_dir0}" | sed 's/\//\n/g' | while read -r _i; do
- printf "../"
- done
-)
diff --git a/solstice.html b/solstice.html
@@ -1,17 +0,0 @@
-<!DOCTYPE html>
-
-<html lang=en>
-<head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <meta http-equiv="Refresh" content="5; url=./solstice/solstice.html">
- <title>Solstice</title>
-</head>
-
-<body>
-<p>This web page moved to a new place.</p>
-
-<p>Your browser should automatically take you <a
-href="solstice/solstice.html">there</a> in 5 seconds.</p>
-
-</html>
-
diff --git a/solstice/hooks/xx-setup-redirections.sh b/solstice/hooks/xx-setup-redirections.sh
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+# Copyright (C) 2017-2025 |Méso|Star> (contact@meso-star.com)
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+set -e
+
+
+sed -e 's;@REDIRECTION@;solstice/solstice.html;g' -e 's;@TIME@;5;g' \
+ ../templates/redirect.html > ../solstice.html
+
+echo 'solstice.html'
diff --git a/templates/redirect.html b/templates/redirect.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html lang=en>
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <meta http-equiv="Refresh" content="@TIME@; url=@REDIRECTION@">
+ <title>Redirection</title>
+</head>
+
+<body>
+<p>This web page moved to a new place.</p>
+
+<p>Your browser should automatically take you <a
+href="@REDIRECTION@">there</a> in @TIME@ seconds.</p>
+
+</html>