Originally this HowTo was part of my last post – a lengthy piece about how I migrated my blog to Pelican. As this specific modification might be more interesting than reading the whole thing, I decided to fork and extend it.
What and why?¶
What I was trying to do is to be able to add, edit and delete content from Pelican from anywhere, so whenever inspiration strikes I can simply take out my phone or open up a web browser and create a rough draft. Basically a make-shift mobile and desktop blogging app.
I decided to that the easiest this to do this by accessing my content via WebDAV via ownCloud that runs on the same server.
Works also on Nextcloud
As an update a few years after I wrote this blog post, I have since migrated from ownCloud to Nextcloud and it all still works the same way.
Why not Git and hooks?¶
The answer is quite simple: because I do not need it and it adds another layer of complication.
I know many use Git and its hooks to keep track of changes as well as for backups and for pushing from remote machines onto the server. And that is a very fine way of running it, especially if there are several users committing to it.
But for the following reasons, I do not need it:
- I already include this page with its MarkDown sources, settings and the HTML output in my standard RSnapshot backup scheme of this server, so no need for that;
- I want to sometimes draft my posts on my mobile and Git and Vim on a touch-screen are just annoying to use;
- this is a personal blog, so the distributed VCS side of Git is just an overhead really;
- there is no added benefit to sharing the MarkDown sources on-line, if all the HTML sources are public anyway.
Setting up the server¶
Pairing up Pelican and ownCloud¶
In ownCloud it is very easy to mount external storage, and a folder local to the server is still considered “extrenal” as it is outside of ownCloud. Needless to say, there is a nice GUI for that.
Once you open up the Admin page in ownCloud, you will see the External Storage settings. For security reasons only admins can mount a local folder, so if you aren’t one, you will not see Local as an option and you will have to ask your friendly ownCloud sysAdmin to add the folder from his Admin page for you.
If that is not an option, on a GNU/Linux server there is an easy, yet hackish solution as well: just link Pelican’s content folder into your ownCloud user’s file system – e.g:
ln -s /var/www/matija.suklje.name/content/ /var/www/owncloud/htdocs/data/hook/files/Blog
In order to have the files writeable over WebDAV, they need to have write permission from the user that PHP and web-server are running under – e.g.:
chown -R nginx:nginx /var/www/owncloud/htdocs/data/hook/files/Blog/
Automating page generation and ownership¶
To have pages constantly automatically generated, there is a option to call
pelican --autoreload and I did consider turning it into an init script, but decided against it for two reasons:
- it consumes too much CPU power just to check for changes;
- as on my poor ARM server a full (re-)generation of this blog takes about 6 minutes2, I did not want to hammer my system for every time I save a minor change.
What I did instead was to create an fcronjob to (re-)generate the website every night at 3 in the morning (and send a mail to root’s default address), under the condition that there blog posts have either been changed in content or added since yesterday:
%nightly,mail * 3 cd /var/www/matija.suklje.name && posts=(content/**/*.markdown(Nm-1)); if (( $#posts )) LC_ALL="en_GB.utf8" make html
Update: the above command is changed to use Zsh; for the old
sh version, use:
%nightly,mail * 3 cd /var/www/matija.suklje.name && [[ `find content -iname "*.markdown" -mtime -1` != "" ]] && LC_ALL="en_GB.utf8" make html
In order to have the file permissions on the content directory always correct for ownCloud (see above), I changed the
Makefile a bit. The relevant changes can be seen below:
html: chown -R nginx:nginx $(INPUTDIR) $(PELICAN) $(INPUTDIR) -o $(OUTPUTDIR) -s $(CONFFILE) $(PELICANOPTS) clean: [ ! -d $(OUTPUTDIR) ] || rm -rf $(OUTPUTDIR) regenerate: chown -R nginx:nginx $(INPUTDIR) $(PELICAN) -r $(INPUTDIR) -o $(OUTPUTDIR) -s $(CONFFILE) $(PELICANOPTS)
E-mail draft reminder¶
Not directly relevant, but still useful.
In order not to forget any drafts unattended, I have also set up an FCron job to send me an e-mail with a list of all unfinished drafts to my private address.
It is a very easy hack really, but I find it quite useful to keep track of things – find the said fcronjob below:
%midweekly,mailto(firstname.lastname@example.org) * * cd /var/www/matija.suklje.name/content/ && ack "Status: draft"
All I needed to do in ownNotes is to provide it with my ownCloud log-in credentials and state
Blog as the "Remote Folder Name" in the preferences.
But before I can really make use of ownNotes, I have to wait for it to starts using properly managing file-name extensions.
ownCloud web interface¶
Since ownCloud includes a webGUI text editor with MarkDown highlighting out of the box, I sometimes use that as well.
An added bonus is that the Activity feed of ownCloud keeps a log of when which file changed or was added.
It does not seem possible yet to collaboratively edit files other than ODT in ownCloud’s webGUI, but I imagine that might be the case in the future.
Kate via WebDAV¶
In many other desktop environments it is child’s play to add a WebDAV remote folder — just adding a link to the file manager should be enough, e.g.:
KDE’s Dolphin makes it easier for you, because all you have to do is select
Add remote folder and if you already have a connection to your ownCloud with some other service (e.g. Zanshin and KOrganizer for WebCal), it will suggest all the details to you, if you choose
Once you have the remote folder added, you can use it transparently all over KDE. So when you open up Kate, you can simply navigate the remote WebDAV folders, open up the files, edit and save them as if they were local files. It really is as easy as that! ☺
I probably could have also used the more efficient KIO FISH, but I have not bothered with setting up a more complex permission set-up for such a small task. For security reasons it is not possible to log in via SSH using the same user the web server runs under.
SSH and Vim¶
Of course, it is also possible to
ssh to the web server,
su to the correct user, edit the files with Vim and let FCron and Make file make sure the ownership is done appropriately.
hook out → back to studying Arbitration law