A simple Pelican article generation script

Posted on Thursday 10 March 2016 in pelican

As often, I have many ideas of useful tools that could ease software users’ life. I’m a new user of Pelican, and I already have some ideas for it too. But as usual, I don’t have much time to translate my ideas into proper software. So the simplest approach is to write something in the middle, trying to get most of the convenience for shorter time.

The idea

Here’s today’s idea: Pelican is a great and simple tool to write a blog. But as always, some details are painful, like in this case, the handling of an article’s metadata. Of course, a full dedicated GUI with powerful shortcuts and nice design would be great, but the time I decided to allocate to this is far too short to begin something like this. Plus, It would probably be a good idea to try a new tool like Electron, but I really don’t want to do more Javascript at the moment ;-)

The features

So here we go, hacking a (preferably) small Python script to do as much work for me as possible. The first contraint was to not introduce any dependency except Python 3. The tasks the script should do are:

  • initiating an article ;
  • asking the user for a title, a summary and a category ;
  • adding the current date automatically ;
  • initiating the article as draft.

The implementation

Small disclaimer: I’m probably not the best Python developer around, but I always try to do my best. You’ll be able to see what I did at the Pelistart Github’s page. So, in order, here what it does:

  • first, it detects the format you use (Markdown, reStructuredText or AsciiDoc) depending on existing files into content directory ; if no format is found, one is picked (almost) randomly, it is not completely satisfying I know, this is something I should probably do better…
  • next step is to build the header with every metatdata:
    • date is easy and straightforward to get ;
    • tags are not set, it is up to you ;
    • title is asked to the user ;
    • summary is asked to the user too ;
    • category is asked to the user, but to make it easy, existing categories are found through articles and proposed, but you can create a new one.
  • a file is written into the right directory and open into the user’s editor.

The use

To use (and love) it, just put the pelistart.py file into your Pelican’s directory and invoke it.

The conclusion

Nothing fancy after all, right? Hope you’ll like and use it!