Pelican and static files in the root
Posted on
Pelican is a great tool to manage static websites, like this. You put your markdown content under content/
, run make publish
and that's it.
What's less obvious is how to leave some service file in the root of your website; just think about files such as the robots.txt. There seems to be no entirely automatic way of achieving this but after checking Pelican's Tips and Tricks page it's just a matter of adding a new entry in a Python dictionary.
Here's what I've added to my pelicanconf.py
:
STATIC_PATHS = ['images', 'extra/robots.txt', 'extra/favicon.ico', 'extra/htaccess']
EXTRA_PATH_METADATA = {
'extra/robots.txt': {'path': 'robots.txt'},
'extra/favicon.ico': {'path': 'favicon.ico'},
'extra/htaccess': {'path': '.htaccess'}
}
Not very handy but, hey, adding new files under the root of a website doesn't happen every day, so no biggie.
Another thing is that I I keep forgetting how to write mod_rewrite rules to redirect all non-HTTP requests to HTTPS. Here's the simplest possible .htaccess
to achieve just that:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://0xf0.eu/$1 [R,L]