From 620370f52b6ff396a469f15c38d2574b437ccace Mon Sep 17 00:00:00 2001 From: Alvie Rahman Date: Sun, 13 Feb 2022 22:13:02 +0000 Subject: [PATCH] add internal link checker script --- internal_link_checker.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100755 internal_link_checker.sh diff --git a/internal_link_checker.sh b/internal_link_checker.sh new file mode 100755 index 0000000..4f995c1 --- /dev/null +++ b/internal_link_checker.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +# used to alert me if i've written a bad internal link or broken one by changing a header + +files="$(find $1 -name '*.html' -type f)" + +for filename in $files +do + links="$(grep -oP '' -h $filename | grep -oP '(?<=href="\#).*?(?=")')" + ids="$(grep -oP '(?<=id=").*?(?=")' -h $filename)" + + for link in $links + do + [[ "$ids" == *"$link"* ]] \ + || echo Found broken internal link in $filename: $link + done +done