-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #204 from creativecommons/netlify-redirects
Add script to convert symlinks into a Netlify _redirects file
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |