New blog with pelican


this is just my new blog. It is generated using pelican, executing it in the post-recieve-hook of git. So I could just push a git repository to update the static blog pages.

I am using gitolite for managing the git repositories server side. The following few snippets could be used, to update a pelican blog after pushing new content to a git repository.

I wanted to make it possible to have multiple blogs managed with a single gitolite instance. Therefor I needed a possibility to supply some configuration options per git repositories. Gitolite has the possibility to set git-config options from the configuration file. To enable it, you need to add the following snippet to the .gitoite.rc in the home of the gitolite user on the server

$GL_GITCONFIG_KEYS = "pelican\..*";

To generate the blog using pelican, you obviously need pelican. Because gentoo did not include an package for system-wide installation, I decided to install pelican using virtualenvwrapper for the gitolite user.

After all this preparations, the final step is to create the post-recieve hook for gitolite. The simplest way is to create ~/.gitolite/hooks/common/post-recieve with the following content, make it executable and execute gl-setup to add symbolic links to all the git repositories:

umask 0022

TARGET_DIR="$(git config --get pelican.targetdir)"
THEME_DIR="$(git config --get pelican.themedir)"
SETTINGS="$(git config --get pelican.settingsfile)"
ARTICLES="$(git config --get pelican.articles)"
BRANCH="$(git config --get pelican.branch)"
[ -n "${TARGET_DIR}" -o -n "${THEME_DIR}" -o -n "${SETTINGS}" -o -n "${ARTICLES}" ] || exit 0

TMP_DIR="$(mktemp -d)"

test -n "${BRANCH}" || BRANCH="master"
git archive ${BRANCH} | tar -C "${TMP_DIR}" -xf -

source ~/.virtualenvs/pelican/bin/activate
echo "Generating blog: pelican -d -t \"${THEME_DIR}\" -o \"${TARGET_DIR}\" -s \"${SETTINGS}\" \"${ARTICLES}\""
pelican -d -t "${TMP_DIR}/${THEME_DIR}" -o "${TARGET_DIR}" -s "${TMP_DIR}/${SETTINGS}" "${TMP_DIR}/${ARTICLES}"

rm -rf "${TMP_DIR}"

Do not try to use something like GIT_WORK_TREE=$TMP_DIR git checkout -f to get the files into the temporary directory. It will change the index and the HEAD of your git repository and this could lead to a few problems. So instead use git archive like presented in the script.

The blogs could be simple configured within the gitolite configuration file. Here is an example repository with the custom settings needed for publishing with pelican:

repo blog
    RW+ = owner
    R   = gitweb daemon
    config pelican.targetdir = /var/www/
    config pelican.themedir = theme/
    config pelican.settingsfile =
    config pelican.articles = src/

Finally you have to create the destination folder and you should ensure that it has the correct file system rights. It should be writable for the user gitolite runs as and readable for the web server.

After adding an appropriate virtual host declaration and pushing a repository with content the blog should be ready.


Comments !