A minimalist static blog-style site generator. There is just one Python script (~300 lines), nine templates, one css file, and two favicon files. You write blog posts in text files, run the script, it generates the website. You can then ftp the files to the web server or use GitHub to sync it. That is all there is.
After years of hosting my website at WordPress, and a brief try of Octopress+GitHub Pages, I decided to go with a home-made program.
What you need
- A story you want to tell.
- Python 3.5 (Download, or Homebrew for Mac)
- titlecase module
- markdown module
- Web server to serve the files. I am using NearlyFreeSpeech
Files and Directories
Each post is a separate file located in /posts/ directory. Files ending with .md will go through Markdown -> Html translation. The file could be named anything but I name them like post-YYYY-MM-DD-unique-url-name.txt (post is in Html) or post-YYYY-MM-DD-unique-url-name.md (post is in Markdown).
The post file has four fields:
- title (Post title)
- name (unique name that will be used in the url, ie. example.com/YYYY/MM/DD/name)
- date (Post date, must be in YYYY-MM-DD HH:MM:SS format, e.g. 2016-09-19 01:37:00)
- text (Html/Markdown markup text of the post)
I have included two sample posts.
If you are migrating from WordPress, you can use wp-extract.py to import the posts from the WordPress exported xml file. I had to manually convert the text into Html so some manual effort is required. Pelican has a WordPress importer that might take away this pain but I could not get it working on Windows.
python process-posts.py. It will read the post files, sort it in date descending order, merge the post data into the templates from /templates/ and generate rss.xml and index.html files into /output/ directory. It will also copy over the favicon.* and styles.css files into /output/.
FTP or use GitHub to upload /output/ into the web server.
The URL scheme of /YYYY/MM/DD/post-name/ is backward compatable with my Wordpress blog. If I was starting from scratch and didn't have to worry about breaking links, I would have gone with /YYYY/MM/post-name.html to make it simpler and require lesser files and directories.
Make it your own
process-posts.pyand replace your url in line 42
- Replace favicon.ico and favicon.gif with your own images.
- Edit the following template files with your own details.
- main-top.txt (change title, description, Google Analytics js, etc.)
- W3C validated Html & RSS
- Future proof: 1000 posts with 5000 characters each generates in 3 seconds on my MacBook Air (Mid 2013 edition).
- I am using to generate my webiste at https://richardhsu.net and I have very high standards.
The free version of WordPress has ads and I don't like them. $50/year to remove ads is more than I want to pay.
Design changes are limited in the free WordPress. There are many nice themes available but changes to it requires $50/year or more upgrade. I like to tweak small details.
A static site appeals to my minimalist, long lasting, and geeky personality.
I wanted to write my own blogging engine for a long time. Before Chaipress, I tried to write typical dynamic web apps using C#+ASP.NET, Python+Google App Engine but didn't finish them. I bit off more than I could chew and the convenience of WordPress and other read-to-use applications was hard to resist.
It is called Chaipress because Chai(tea) is simple, easy-to-make, low cost, and refreshing. The press is a suffix borrowed from the names of other blogging systems (WordPress, Octopress)
Credits & Tools
Below are inspirations and tools that helped me in the design and implementation of Chaipress.
- Daring Fireball (Markdown, TitleCase, and inspiration)
- Charles Petzold (design)
- http://htmledit.squarefree.com/ (preview Html rendering)
- MarkdownPad2 (Markdown > Html)
- http://maxdesign.com.au/css-layouts/ (My css is based on the One-column fixed-width responsive layout)
- Pelican (This got me started on Chaipress)
- Notion and Notes (for telling me about NearlyFreeSpeech)
- Basecamp (for keeping things going)