www.byjp.me/tools/redirects/split.bash
JP Hastings-Spital 2991c30e20 Crypto-generated shortlink
- Every page now has a shortlink
- Shortlinks can be manually overridden with the shortlink frontmatter param
- A single "index.redirects" file is created at build time
- A "redirects" tool splits that one file into multiple `_redirects` files, as would be needed on a site like byjp.fyi
2024-07-16 21:28:33 +01:00

16 lines
381 B
Bash
Executable file

#!/bin/bash
rm **/_redirects
while IFS=$'\n' read -r line
do
# Extract the absolute file path
outdir=$(dirname $(echo "$line" | cut -d " " -f1) | cut -d "/" -f2)
if [[ -n "$outdir" ]]; then
[[ ! -d $outdir ]] && mkdir -p $outdir
echo $line | cut -c $((${#outdir}+2))- >> "./$outdir/_redirects"
else
echo $line >> "_redirects"
fi
done < "${1:-/dev/stdin}"