From 6a9d43e5eac67de468a7cbe0b6c10fc0f7573596 Mon Sep 17 00:00:00 2001 From: JP Hastings-Spital Date: Tue, 16 Jul 2024 23:05:59 +0100 Subject: [PATCH] Put all redirects in one file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit IPFS _redirects files have to be at the root — so put them all in the same place! --- content/curiosities.md | 1 + tools/redirects/update-shortlinks.bash | 17 +---------------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/content/curiosities.md b/content/curiosities.md index c913011b..c50801a5 100644 --- a/content/curiosities.md +++ b/content/curiosities.md @@ -7,6 +7,7 @@ summary: A list of the many curious things I've made over the years. sitemap: changefreq: weekly priority: 0.8 +shortlink: curiosities --- I'm a thoroughly [miriscient](https://www.miriscient.org) chap, and this often ends up in me creating toys, trinkets, projects and other artistic things. I've listed some out below. diff --git a/tools/redirects/update-shortlinks.bash b/tools/redirects/update-shortlinks.bash index 12658148..1bbe9ee4 100755 --- a/tools/redirects/update-shortlinks.bash +++ b/tools/redirects/update-shortlinks.bash @@ -18,28 +18,13 @@ cd $gitRoot mv public/_redirects public/_redirects.previous find public -type f -iname "_redirects" -delete -# Create local _redirects files -echo "Sorting shortlinks into different directory _redirects files…" - -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 "public/$outdir" - echo $line | cut -c $((${#outdir}+2))- >> "public/$outdir/_redirects" - else - echo $line >> "public/_redirects" - fi -done < /dev/stdin - # Combine new (root) _redirects and _redirects.previous echo "Merging with existing links…" start_line=$(awk '/^# From blog/{print NR; exit}' public/_redirects.previous) end_line=$(awk 'NR > '"$start_line"' && /^#/{print NR; exit}' public/_redirects.previous) +cp /dev/stdin public/_redirects sed "$((start_line + 1)),$((end_line - 2))d" public/_redirects.previous > old_removed.txt awk 'NR=='"$((start_line + 1))"'{system("cat public/_redirects")} 1' old_removed.txt > public/_redirects.new