Support for extensionless URLs (neither .html nor trailing slash)?
See original GitHub issueI would like to generate a static site in which I have files like blog/post-name.html
, but the generated URLs to them have neither .html
nor a trailing slash and look like, for example, example.com/blog/post-name
. (Although this requires support from the web server, it’s pretty common and easy to set up; for example, GitHub Pages supports it directly with no configuration. It doesn’t seem to be commonly supported in other static site generators, but Jekyll supports it — there used to be a clear section in the Jekyll documentation explaining this, but it seems to be sort of absorbed into the overall documentation now; see https://github.com/jekyll/jekyll/issues/156 for more discussion and motivation.)
Does Lektor support this? If not, is it possible to add support, or at least expose enough API to make this possible to implement in a plugin? I’ve poked around trying to write a plugin and am very unsure if the current plugin API supports this. For example, I can create an extra VirtualSourceObject
for every Record and make the URL resolver resolve extensionless URLs to it, and I imagine I could just change every place URLs are generated in my website templates to use these URLs instead, but I don’t think I can avoid building a separate artifact at a separate location, nor do I think I can make my new source just fallback to my old source’s generated file.
If this sounds like a feature you don’t have but would accept, I am extremely willing to write code for this 😃 (Lektor’s CMS looks amazing, plus my blog currently runs on a custom Hugo fork that I don’t want to maintain indefinitely…)
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (4 by maintainers)
Top GitHub Comments
I don’t really have an objection to this being in core, I guess file extensions are increasingly irrelevant to anyone but old dinosaurs.
The complicated stuff would be: a) finding a config name for it 🙄, and b) making sure the logic won’t blow up once #344 is fixed. There’s probably other places that will get tripped, relative urls will need fixing as well, and the devserver part will need to know if that’s an actual extensionless file or a
.html
. The current gist is naive in this respect, but hey, so is lektor core for now.For requests, isn’t apache (multiviews) also able to add
/index.html
to an extension-less slug if it finds a directory?So, wouldn’t lektors a-folder-per-page approach (on disk) be just fine. And the only thing missing would be a lektor option that allows it to drop
/index.html | .html
from internal links in the generated pages?webserver_supports_clean_URLs = true
?