Deth

Fitness and everything else

Quick Script To Convert All My Markdown Files To AsciiDoc

As I posted yesterday I am strongly considering going back to Hugo and AsciiDoc for my front matter. I went into the the pros and cons and why I think it may be worth my trouble yesterday.

The first order of business was converting my old markdown files to the new format. I ran into some roadblocks with that. First I tried using kramdoc but that would eat the front matter or somehow mess it up. I looked through their GitHub page and didn’t really see anything to help me with that.

I then decided to give pandoc a try. With some trial and error, I got it working and then threw together a script to iterate through all of my markdown files and convert them.

#!/usr/local/bin/fish
for file in **.md;
 set new (path change-extension .adoc $file) ## (basename $file .md).adoc
pandoc --from=commonmark_x-smart --to=asciidoc --no-highlight --wrap=preserve -o "$new" -s "$file"
end

I’ll keep this script around as I’ve needed to mass rename or any other very repetitive command file multiple times, and this would be easy enough to modify to fit my needs. There have been so many times when I have had to manipulate multiple files, and this time the count was in the thousands with my nearly twenty-five years worth of posts and other pages.

That recursive wildcard (**) feature in the fish shell is pretty cool. I’ll have to be careful with that, though, since it could get me into trouble with my fat fingers.