How can I generate links without the ".html" extension?

20 views
Skip to first unread message

Dave Hollingworth

unread,
May 14, 2015, 1:51:22 AM5/14/15
to nikola-...@googlegroups.com

I'm new to Nikola (and loving it by the way!) and I'm creating a theme for my blog. I would like to have urls without the ".html" extension. So, instead of this:


I would like:


I have no problem with the actual file having the extension, because I'm using server-side rewrites to handle that. I just want the permalink to not have the extension.

I have discovered that I can do this to generate the link without the extension:

<a href="${post.permalink(extension='')}">

Which works nicely. However, it does mean that if I share the theme with someone else, they have to edit it if they don't want links like that. So is there some way I can achieve this without doing it the theme? I suppose ideally in the configuration file. Is this possible and if so how could I do it?

Many thanks!
Dave

Puneeth Chaganti

unread,
May 14, 2015, 2:47:52 AM5/14/15
to nikola-...@googlegroups.com

Dave Hollingworth writes:

> Which works nicely. However, it does mean that if I share the theme with
> someone else, they have to edit it if they don't want links like that. So
> is there some way I can achieve this *without* doing it the theme? I
> suppose ideally in the configuration file. Is this possible and if so how
> could I do it?

You could have a config variable that can be set in the config, and then
generate links with or without extension, based on the value of that variable.

Chris Warrick

unread,
May 14, 2015, 8:09:42 AM5/14/15
to Nikola—Discuss
> --
> You received this message because you are subscribed to the Google Groups
> "nikola-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to nikola-discus...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Nikola actually has two settings that do everything for you:
PRETTY_URLS and STRIP_INDEXES. It uses folders with index.html files,
and requires no special support in themes and your web server.

--
Chris Warrick <https://chriswarrick.com/>
PGP: 5EAAEA16

Dave Hollingworth

unread,
May 14, 2015, 12:35:28 PM5/14/15
to nikola-...@googlegroups.com
Thank you both for your replies - @Chris, just tried that and it works nicely, thanks!
Reply all
Reply to author
Forward
0 new messages