Skip to content

Commit

Permalink
Merge pull request #204 from creativecommons/netlify-redirects
Browse files Browse the repository at this point in the history
Add script to convert symlinks into a Netlify _redirects file
  • Loading branch information
TimidRobot authored Jun 7, 2024
2 parents 9f8c39b + a225431 commit 043bb14
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions config/netlify_redirects.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash
#
# Convert symlinks into a Netlify _redirects file
#
# Configure the site in Netlify with:
#
# Build command: ./config/netlify_redirects.sh
#
set -o errexit
set -o errtrace
set -o nounset

# shellcheck disable=SC2154
trap '_es=${?};
printf "${0}: line ${LINENO}: \"${BASH_COMMAND}\"";
printf " exited with a status of ${_es}\n";
exit ${_es}' ERR

DIR_REPO="$(cd -P -- "${0%/*}/.." && pwd -P)"

for line in $(cd docs; find -- * -type l -ls | awk '{print $11"###"$13}')
do
symlink="${line%%#*}"
if [[ "${symlink}" =~ \/ ]]
then
basedir="${symlink%/*}"
else
basedir=''
fi
symlink=${symlink/\/index.html/}
target="${basedir}/${line##*#}"
target="${target/\/rdf/rdf}"
target="${target/licenses\/../}"
echo "/${symlink} /${target} 200"
echo "/${symlink%.html} /${target} 200"
done | sort -r -u | column -t > ${DIR_REPO}/docs/_redirects

0 comments on commit 043bb14

Please sign in to comment.