what to do if your tiddlywiki is saving .tid files instead of markdown
I am really writing this just so someone who has this same problem maybe has a bit of an easier time searching for the answer. I am going to be a bit verbose with the idea that it will help that searchability.
I have a Tiddlywiki running the Node.js server. That’s TiddlyWiki5. I had always found it to be the case that my tiddlers saved as separate .md
files, with metadata in a file with extension .md.meta
. This was the intended behavior; I create tiddlers with the type text/x-markdown
, and I had some automation depending on those .md
files.
To my horror, I discovered that some of my automation wasn’t working because the files that were being created were actually .tid
files. They had the equivalent lines of .md.meta
in them and then the equivalent contents of the .md
file, as is standard for this file type. Since this was not the behavior I was used to and since everything I could find suggested it shouldn’t be happening, I was at a loss.
Then I found the right Google Groups email.
if you use the server option, you need to make sure you update the generated tiddlywiki.info
file with the plugins that are relevant to how files should be saved1.
That will look something like
"plugins": [
"tiddlywiki/markdown"
]
All right, so now you fixed it but you still have a lot of .tid
files you wish were .md
files. How can you convert them? If you are using a computer that has a unixy terminal and you know a bit about how to use it….
This is what I used to convert the accidental markdown .tid
files. It is not representative of my professional code and you should only run it after you’ve made a backup copy of your whole wiki folder and I provide no warranty and you’re lucky it has any comments at all.
I will also note that this leave blank lines above your markdown. I didn’t notice on the first pass and then wrote a separate awk
dealio to handle it because I had a use case where it mattered. You could handle this by changing that header
variable in the awk
script to have three cases instead of two, yada yada, but I am only pasting this in to maybe be helpful to someone who doesn’t want to look up awk
flags.
# the IFS nonsense is only necessary because I have filenames with spaces
OLD_IFS=${IFS}
IFS=$'\n'
PATH_TO_YOUR_WIKI= < here >
for blah in `find $PATH_TO_YOUR_WIKI/tiddlers/ | grep "tid$" | grep -v 'tiddlers\/\$_'` ; do # list out tiddlers, exclude system ones, yes I know I could have looked up find flags for the file extension, yes I know it could have been ls, leave me alone
if grep "^type: .*markdown$" $blah &>/dev/null ; then # you meant it to be markdown
if ! grep -A1 "^type: .*markdown$" $blah | tail -n+2 | grep '[^\s]' ; then # the line after the type declaration is blank; this seemed in the ones I spot checked to always be the end of the metadata but YOUR MILEAGE MAY VARY
BASE_PATH=`echo $blah | sed 's/.tid$//'`
MD_PATH=`echo $BASE_PATH | sed 's/$/.md/'`
HEADER_PATH=`echo $MD_PATH | sed 's/$/.meta/'`
touch $MD_PATH $HEADER_PATH
awk -v "md=$MD_PATH" -v "hp=$HEADER_PATH" ' BEGIN {
print "" > md;
print "" > hp;
header=0
}
{ if (header == 0) { print >> hp }
else { print >> md }
if ( $0 ~ /type: .*markdown$/ ) {header=1}
}
' $blah
rm $blah
fi
fi
done
IFS=${OLD_IFS}
Well, it is representative of my professional code in that my placeholder names for scripts have… uh… personality.
-
The email chain claims that it’s necessary to add all the plugins you install there. I … hope this is not true, but that’s sort of beside the point. ↩