diff --git a/content/posts/archiving-instagram-posts/index.md b/content/posts/archiving-instagram-posts/index.md index b1bdb575..a7f6085a 100644 --- a/content/posts/archiving-instagram-posts/index.md +++ b/content/posts/archiving-instagram-posts/index.md @@ -10,6 +10,7 @@ tags: topics: - IndieWeb summary: Archiving my Instagram account, and releasing the code that imported it to this Hugo-driven site. +shortlink: insta --- I spent a little time this weekend reminding myself of what writing code is like (before I start work again on Tuesday, after [4 months travelling](https://adventure.awaits.us)). After my recent post on [leaving Meta's social networks](/posts/goodbye-big-social) I decided to create a script to convert the GDPR-provided archive of all my activity on Instagram into this blog. diff --git a/todo.md b/todo.md index ad5b2781..08a8ddc3 100644 --- a/todo.md +++ b/todo.md @@ -35,8 +35,8 @@ Things I might work on within my personal blog's software. - [x] Create suitable `_redirects` files - [x] Import pre-existing shortlinks - [x] Add shortlink as `` on all relevant pages + - [x] Add additional logic to _combine_ the redirects files as needed - [ ] Upload new redirects to byjp.fyi repo - - [ ] Add additional logic to _combine_ the redirects files as needed ### Done ✓ diff --git a/tools/redirects/split.bash b/tools/redirects/split.bash deleted file mode 100755 index a0b85034..00000000 --- a/tools/redirects/split.bash +++ /dev/null @@ -1,16 +0,0 @@ -#!/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}" diff --git a/tools/redirects/update-shortlinks.bash b/tools/redirects/update-shortlinks.bash new file mode 100755 index 00000000..230c9306 --- /dev/null +++ b/tools/redirects/update-shortlinks.bash @@ -0,0 +1,44 @@ +#!/bin/bash +# Usage: +# 1. Build www.byjp.me +# 2. Clone and enter a local copy of the byjp.fyi repo +# 3. `cat www.byjp.me/public/index.redirects | www.byjp.me/tools/redirects/update-shortlinks.bash`` +# 4. `git commit -am "Update blog redirects" && git push` + +# This script assumes it is being executed at the root of the byjp.fyi repo +gitRoot=$(git rev-parse --show-toplevel) || { echo "Please run inside the byjp.fyi git repo"; exit 1; } +if [[ "$(git remote get-url origin)" != "https://github.com/by-jp/byjp.fyi.git" ]]; then + echo "This repo doesn't have the byjp.fyi repo as the origin" + exit 2 +fi +cd $gitRoot + +# Prepare existing files for new _redirects info +mv public/_redirects public/_redirects.previous +find public -type f -iname "_redirects" -delete + +# Create local _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 < "${1:-/dev/stdin}" + +# Combine new (root) _redirects and _redirects.previous +start_line=$(awk '/^# From blog/{print NR; exit}' public/_redirects.previous) +end_line=$(awk 'NR > '"$start_line"' && /^#/{print NR; exit}' public/_redirects.previous) + +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 + +# Remove temporary files +mv public/_redirects.new public/_redirects +rm public/_redirects.previous +rm old_removed.txt