My blogging setup

I recently started a blog for which I made my own blogging script, as I wanted to be able to directly convert my vimwiki documents into blog posts.

The source code is available at https://git.fossworld.hu/AdamOnLinux/blogger

I recently made a change to the script, which visually changes nothing, but makes it a bit easier for me by automatically exporting to HTML, without having to open vim.

How the script works, step by step:

[ ! -f "/home/adam/.cache/vimwiki/blog/$2.wiki" ] && exit 1

If the file does not exist, exit immediately

(I honestly don't know why I have my vimwiki folder in .cache lol)

mkdir /home/adam/Projects/personal_site/blog/"$2"

Create a directory for the blog post

post_title="$(cat /home/adam/.cache/vimwiki/blog/"$2".wiki | head -1 | sed -e 's|= ||' -e 's| =||')"

Get the title of the post, which I always write on the first line of the file between two = characters.

Then the conversion begins.

sed -r -e 's/(\[.+\])\(([^)]+)\)/\1(\2.html)/g' -e '1,2d' <"/home/adam/.cache/vimwiki/blog/$2.wiki" | pandoc -s -f vimwiki -t html -c /home/adam/Projects/personal_site/blog/post_style.css --metadata title="$post_title" | sed -r 's/<li>(.*)\[ \]/<li class="todo done0">\1/g; s/<li>(.*)\[X\]/<li class="todo done4">\1/g' >"/home/adam/Projects/personal_site/blog/$2/index.html"

First, I remove the two lines of the file on which the title is visible, because pandoc automatically adds that to the HTML.

Then pandoc creates the HTML file.

sed -i -e 's|<body>|<body><div class="navbar"><ul class="menu"><li class="unselectable" unselectable="on"><a href="../..">Home</a></li><li class="unselectable" unselectable="on"><a href="../../services">Services on this server</a></li><li class="unselectable" unselectable="on"><a href="../../software_recommendations">Software recommendations</a></li><li class="unselectable" unselectable="on"><a href="../../blog">Blog</a></li></ul></div>\n<div class="content">|' -e 's|</body>|</div></body>|' /home/adam/Projects/personal_site/blog/"$2"/index.html

This is the longest line of code I think I've ever written.

It adds the navigation bar to the top of the page.

After that it's just adding it to the website and RSS feed, then uploading it to the server.

sed -i 's|<!-- Posts -->|<!-- Posts -->\n <li><a href="./'"$2"'">'"$post_title"'</a></li>|' /home/adam/Projects/personal_site/blog/index.html sed -i "s|<\!-- Items -->|<\!-- Items -->\n <item>\n <title>$post_title</title>\n <guid>https://fossworld.hu/blog/$2</guid>\n <link>https://fossworld.hu/blog/$2</link>\n <pubDate>$(date)</pubDate>\n </item>|" /home/adam/Projects/personal_site/blog/rss.xml

rsync -rtvzP /home/adam/Projects/personal_site/blog/index.html /home/adam/Projects/personal_site/blog/rss.xml /home/adam/Projects/personal_site/blog/"$2" vo:/var/www/fossworld.hu/blog

And that's basically it!

Although it doesn't seem like much, it actually took me quite a bit of time to figure this all out.