My new plug-in for Nikola gives you the most recent posts as a JSON file. This file isn’t very useful on its own, but with client-side scripting you can use it to promote your newest articles and increase your readership.
Unlike all my earlier Nikola plug-ins, this one requires some work on the theme and some client-scripting to be useful.
Install the plug-in by running
nikola plugin -i recent_posts_json. No configuration in Nikola is required but some options are available. Please refer to the documentation. Requires Nikola version 7.4 or later.
I’ve gone for a headline list presentation with plenty of spacing between each headline. This is built from the JSON output of this plug-in and some client-side scripting. (Demo at the bottom of the page.) I’ve made an annotated version of the client-script that can kickstart your use of this plug-in.
You will need to tweak some CSS class names (top of the script file) to match your Nikola theme. Check it out as its chock-full of tips specific to the use of this plug-in. Save your script in your files/assets/ directory, and include
BODY_END = "<script async src="/assets/your-script.js"></script>" in Nikola’s conf.py.
You can customize the JSON file and your script to include meta descriptions/ingresses (set the option RECENT_POSTS_JSON_DESCRIPTION = True) and meta preview images/lead image (set the option RECENT_POSTS_JSON_PREVIEWIMAGE = True.) For example, you could do a typical headline-on-lead-image-carousel on your front page or sidebar.
If you want the same data in XML or for specific tags, categories, or archives, check out Nikola’s new Atom capabilities.
Alternatively, you can produce the same result without the need for client-side scripting by modifying your theme. You’ll have to rebuild every post every time you make a new post with this approach. That can be very time-consuming and will remove many of the advantages of using a static site builder such as Nikola. Yikes.
Performance tip: Set a decent caching time HTTP header for the script (months?) and a time reflecting how often you post on the JSON file (days? – at least a few hours.)
Bonus stat: Both the page-view count per visitor and advertisement click-through rates (CTR) increases after implementing this list at the bottom of each post here on this site.