My goal was to be able to edit my Pelican blog in local, commit the modifications I made and then by pushing it to a git repository, the blog would be regenerated on the remote webserver.
I found pelicangit, but the fact that it forces to add a configuration file in /etc/ didn't please me. I am sure there is a way to this without needing administration right.
My setup is inspired from Micheal Crosby. The main difference between my setup and his, is that I do not want the HTML output to be in the git repository. I want pelican to generate it on the remote server, in order to get a git repository as light as possible.
Starting your blog and first post
This is best described in the pelican documentation.
Setting a .gitignore file
We will be editing our blog on our local computer, chances are we will also use the make devserver
to take a look at what we have produced. In that case, pelican will create file that we may not want to add to our git repository.
$ cat .gitignore
*.pid
__pycache__
output
Now we can commit all the content of our blog and start working on the remote server.
Setting up the remote server
The default folder for all my webcontent is /var/www and it belongs to the user www-data. Here lives all of my websites.
I also have a /var/git folder where I store all of my git repositories. This folder is also owned by www-data. So it will be possible for the user www-data to write both in /var/www and /var/git.
We must first create a bare git repository :
$ mkdir /var/git/myblog.git
$ cd /var/git/myblog.git
$ git init --bare
Now we must create the hook that will generate our HTML content after every push :
vim /var/git/myblog.git/hooks/post-receive
Here is the content of my file
#!/bin/bash
GIT_WORK_TREE=/var/www/myblog.git git checkout -f
cd /var/www/myblog
make html
Let's make sure the hook is executable :
chmod 755 /var/git/myblog.git/hooks/post-receive
Let finish by adding the remote to our local git repository, so we can push on the remote server.
$ git remote add blog www-data@myserver:/var/git/myblog.git
Now everytime you push content to your remote server, the content gets updated.
$ git push blog master