So, here’s the script I put together to export my markdown blog post to this blog. It’s a crude solution, but I’d lie if I said I wasn’t proud anyway.
Here’s the code
And here’s what it does
The script takes as input the name of a markdown document, for example
This document is then converted to html in the second paragraph. Finally, it gets pushed to the server, to a folder called blog-posts, and the name of the new html is added to the index of posts.
Those global variables are configured for my special server setup. See more under “The server side”
Here’s what happens with the post when the page is loaded:
The PHP script runs through all the file-names stored in the index and creates posts out of them.
The server side
There’s some trickery and static code living on the server side, unfortunately. First, the /var/www/html that Apache uses to find a home folder has been rerouted.
As you can see, it now points to a certain folder in my home folder, with the following structure.
The bash script ha a global variable pointing to the same folder as the variable $rootpath in the bash script.
Suffice to say, a lot of important functionality is missing in blogit. Here’s are some things I want to fix in the future:
- Setting the global variables, so that it’s easy to change what destination and even server without manually changing the code.
- Removing published posts.
- Rearranging posts.
- Quickly undoing latest push.
- Editing markdown directly on the server, and then automatically update the posts accordingly.
If you looked at this and went “Yuck! This code is garbage!” – please let me know! Give me a shout on GitHub