RSS feed generator

Posted by pulkomandy on Sat Jul 28 18:43:54 2012  •  Comments (0)  • 

Any modern website needs an RSS feed. I added the feature to PulkoCMS.

The script is rather simple: it looks for all articles in the main category and create matching RSS feed entries. Since the main category has links to the most recent articles, this works rather well.

The code is not too clean (yet). I should start cleaning up and extract common stuff with index in an helper file, before it becomes a copypaste mess!

Get sourcecode

Publishing the recent articles on the homepage

Posted by pulkomandy on Sat Jul 28 18:37:35 2012  •  Comments (0)  • 

I decided to show the recent articles from all the categories on the hormapge. To do that, a small script in the /etc/cron.daily folder is enough.

This will delete all the symlinks in the main category, then recreate links to most recent articles in all categories.

The script will also create links to the comment files, so the comments will also be forwarded to the homepage.

Since there is no database, the website is static. So there is no real way to do queries. This is not really important, because :

  • You usually know when you publish a new article, so you can run the script by hand at that time,
  • You can also put the script in a cron job so that it works automagically. The only drawback is it will take up to 24 hours for your articles to go on the homepage (I do run the script daily).

I split the script in two files, because my sh skills are limited. It should be possible to do it in one file. If you do it, tell me so.

Part one, script to actually run (as a cron job for me, put it in /etc/cron.dayly)

#!/bin/sh
cd /path/to/pulkocms/cat/
find -maxdepth 1 -type l -delete -name "*.{article,comment}"
find . -wholename "*/*.article" -type f | xargs -d\\n ls -t1 | head | xargs -d\\n -L1 /var/www/pulkocms/dolink ;

And here is the dolink script that creates links.

#!/bin/sh
ln -s "$1" .
ln -s "`echo $1 | sed -e 's@\(.*\)article@\1comment@' | sed -e 's@ @%20@g'`" .

Some explanations. The first script will first delete all the symlinked articles on your home page/main category. It goes to depth one so you can have symlinks in other categories if you want (for multi-categories articles). It also delete the linked comment files.

Then, it looks in all categories for all article files. It pipes them to ls -t which sorts them by date. Head takes the 10 newest files and and send them (one at a time) to the dolink script.

dolink then just create a link to the found article in the main folder. It also link the comment file (which may not even exist yet). There's a subtle trick, the comment-file has its name url-escaped, so we have to fake that with sed. I chose to only replace spaces, but you can do more if needed.

Anyway, tell me if you improve it in anyway, or if you otherwise use and enjoy PulkoCMS!

About PulkoCMS

Posted by pulkomandy on Wed Feb 17 00:03:56 2010  •  Comments (1)  • 

Introduction

PulkoCMS is a small content management system. It was created to manage this website.

The idea is to get a simple and versatile system to easily manage the website. PulkoCMS relies on simple flat files and UNIX features to get the job done. There is no need for an heavy SQL database, just a perl interpreter and some files.

Features

  • UNIX integration : use files, folders, and UNIX users.
  • Easy installation: just a variable to set up in the main script.
  • Direct ftp/ssh access to article and comments content. No need for a complex online interface to edit them.
  • Fast page generation, no SQL request execution time.
  • Secure script: filters out html tags from comments.
  • Shoutbox!
  • Comments on articles, with a "recent comments" box.
  • Gravatar icon support in comments.
  • Short, readable and easily modifiable sourcecode: less than 400 lines of mixed html and perl.
  • Generates valid XHTML code (if you don't mess it up with your articles text).

Directory structure

PulkoCMS will build the page from a directory tree. You can adjust the PULKOCMS_ROOT variable to tell it where it is installed. There, you should have a folder called "cat". In this folder, you can put other folders that will be your categories. In each category folder, you must have a file called "cat.desc" that contains a short description of the category. This will be displayed in the sidebar. You can also add articles, they are file called "Article title.article". The content of the file is raw html, without header. UNIX file owner full name and modification date are used to identify the article.

You can have ".article" files in the cat/ folder. These will be displayed when there is no category selected. It's a good place for news.

If a category name starts with a dot, it won't show up in the category list, but you still can link to it. This is used for the "users" and "liks" categories on this site.

If you want an article to show up in different categories, just use symlinks.

Comments are stored in a file whith the same name of the article, but the extension is .comment. The format is name\0date\0content\0email address. This was chosen because people rarely use \0 in their name...

Feel free to use this and report bugs to me ! I made it for my own use but I would be happy to improve it.

Setting it up

Well, there is almost nothing to do...

  • Unpack it somewhere. You need index.pl to be an exectutable cgi script, depending on the config of your webserver this means putting it in /usr/lib/cgi-bin/, chmod +x it, or some oher magic. The pulkocms folder can be anywhere, and you can rename it.
  • Edit index.pl to make the $PULKOCMS_ROOT variable point to the pulkocms folder. This is where you will put all your articles, so the folder will have to be readable and writable by www-data (we also store comments and shoutbox contents inside it). It seems a good idea to make your user the owner, and www-data the group. Or www-data the user, and some group of users you want to contribute to the site the group. Well, both should have read&write access. Do as you want.
  • Also set the $WEB_ROOT variable to tell PulkoCMS where it is located. This is used as a prefix for all the generated URLs
  • You need URI::Escape. In Debian this is the apt package liburi-perl.
  • The current version requires some mod_rewrite functionality. Enable it on your server if it's not done. Here is the regexp I use to redirect my URIs (I put it in /etc/lighttpd/lighttpd.conf). If you use Apache, you may have to somewhat alter it:
url.rewrite-once = (
    "^(.*)/articles/([^/]*)/([^/]*)/([^/]*)" => "$1/index.pl?node=$2&cat=$3&art=$4" 
)

TODO list

  • Multilanguage support: article are named "name.EN.article", show an icon on article page when other language is available, allow user to select favorite language, still display other languages when favorite is not available.
  • Online editor for articles : get content if article exists, else create file. Allow delete, hide article/category
  • Helper scripts for setup and creating of base directories with some sample articles.

Changelog

  • 0.1 (24/06/09) : first public release
  • 0.3 (25/06/09) : shoutbox, comments, spaces in categories names, link to users category on author name.
  • 0.4 (26/06/09) : some bugfixes, "recent comments" box, made the css layout fluid (whole width).
  • 0.5 (27/06/09) : Bugfixed comment form hacking protection, added a cheatmode to the shoutbox.
  • 0.5 (28/06/09) : Gravatar support in comments, short dates in "recent comments" box.
  • 0.6 (??/06/09) : Photo gallery (well actually just a little helper script to generate an article for every .jpg in a given folder), nodes (ie hyper-categories).
  • 0.7 (06/07/09) : Use mod_rewrite for somewhat nicer URL that should allow google referencing to work better (not only on the front page).
  • 0.8 (08/08/09) : Allow PulkoCMs to be installed somewhere else than the root of the website.

Licence

This work is distributed under the BSD licence. I'd like to get feedback and ideas (and patcheshacks) if you use it, but I won't force you.

Download

Get it here !