Skip to content
Advertisement

Pelican – How to remove .html extension on local host

I have a pelican blog and I want to remove the .html extension from the URL. I added the following to pelicanconf.py

ARTICLE_URL ='{slug}'
PAGE_URL = '{slug}'

The problem is that invoke livereload doesn’t serve the urls without html extension. pelican --autoreload --listen does, but it doesn’t automatically refresh my browser on changes.

Any solution to enjoy the best of both worlds?

Advertisement

Answer

Make use of the *_URL and *_SAVE_AS configuration options.

E.g.:

ARTICLE_URL = '{slug}/'
ARTICLE_SAVE_AS = '{slug}/index.html'
PAGE_URL = '{slug}/'
PAGE_SAVE_AS = '{slug}/index.html'

The above does rely on the fact that webservers will provide the “index.html” file when you attempt to browse a directory directly, but this is near-universal behaviour.

You can do the above for any *_URL setting. Further example:

CATEGORY_URL = "category/{slug}/"
CATEGORY_SAVE_AS = "category/{slug}/index.html"
CATEGORIES_URL = "category/"
CATEGORIES_SAVE_AS = "category/index.html"
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement