In Gollum wiki, how do I find orphan pages - that is pages that don't have a link to them?
I have tried to write a bash script (see below) but it seems to not work good with pages that have special characters (, ), / in the name.
#!/bin/bash
found=""
find . -name HelpPages -prune -o -name '*.md' -type f -print0 | while IFS= read -r -d '' f; do
escaped=$(echo $f | sed -e "s/.md//g")
escaped=$(echo $escaped | sed -e "s/.\///g")
escaped=$(echo $escaped | sed -e "s/(/\\\\(/g")
escaped=$(echo $escaped | sed -e "s/)/\\\\)/g")
escaped=$(echo $escaped | sed -e "s/\.\///g")
escaped=$(echo $escaped | sed -E 's/[- ]/\[- \/\]/g')
escaped=$(echo $escaped | sed -E 's/ /\\ /g')
found=$(grep -i -r "[\|\[]$escaped\]" *.md)
echo "_________"
echo "Processing $escaped file..."
if [ -n "$found" ]; then
echo "found: $f"
echo "$found"
else
echo "NOT found: $f"
fi
done
This script first finds files within a directory that match *.md
filename pattern. Then, for every filename, like The-event-log-(errors-warnings).md
, the script needs to find the link, which can be any of the following:
[[The event log (errors/warnings)]]
[[The event log (errors warnings)]]
[[The-event-log-(errors-warnings)]]
[[The event log|The-event-log-(errors-warnings)]]
Turned out I had some bad escaping of special characters. Ready script (also available in Gist):