Closed suliveevil closed 1 year ago
What is wrong with the Find broken links
command?
It's great but I have about 1000 broken links in broken links output
, I have to click on these links one by one or learn how to use some script to create files for these broken links.
Oh, you mean to create the files of that broken links. Sorry, misunderstood you.
😂 In the forum I found a great script to do this, this function will be awesome integrated in find-unlinked-files
#!/usr/bin/env bash
# Create empty notes for anything linked
archive=${OBSIDIAN_ARCHIVE:-$HOME/Documents/GitHub/Obsidian}
ext=md
placeholder="#placeholder"
cd "$archive"
# note this is one long pipeline
grep --include '*.'$ext --exclude-dir '.obsidian' -orh '\[\[[^]]*]]' . | # get all links with brackets
grep -oh '[^][]\{1,\}' | # remove the brackets
grep -oh '[^|]*' | # remove the aliases
sed 's/^ *//;s/ $//' | # trim spaces
sort | uniq | # make unique
while read -r file; # for each expected file
do
if [[ "$file" == *../* ]] # if it contains a parent ../ link in it anywhere we can't process it
then
echo "'[[$file]]' has a parent directory in its path and will not be processed"
elif ! find . -ipath "*/$file.$ext*" | grep . > /dev/null # if it's not in the notes tree
then
echo "$file.$ext does not exist and is being created"
echo "# ${file##*/}" > "$file.$ext" # create with an H1 placeholder of its own name
echo "$placeholder" >> "$file.$ext" # add any custom placeholder text, plus an eol
fi
done
I was using this plugin for creating files, which is a little bit laggy but can create files to certain folder.
https://github.com/ivaneye/obsidian-files-cooker
Tested creating 1000 files using file-cooker found by find-unlinked-files.
I upgrade find-unlinked-files and found another 7 broken links 😂 the creating file function is great!
You can now set a whitelist of directories, which should allow you just that.
find-unlinked-files is my favorite obsidian-plugin! It will be even more awesome if we can create files for broken links.