This works fine, using a collection permalink of :path, but I have one additional requirement… when linking to some-document's index, I want the index.html suffix to be omitted, so that the canonical paths to the pages above become:
Is this possible? I’ve tried various permuations of the permalink variables but the only thing I’ve found which preserves the directory structure of the source is /:path:output_ext (neither of which are documented in https://jekyllrb.com/docs/permalinks/, but which are recommended in examples).
(I’m quite happy to write Ruby code and set the permalink programmatically, if there’s a way to do that.)
so if you have just :path and you make a link to /some-document/ that does not work?
to be clear, some-document is a directory? or a document? seems like it is supposed to be some-directory.
And it looks like you want a pretty url for only the top index file but you want the other ones to have subpagex.html? to get both a pretty url for the one document but an ugly one for the other files I think you will need to specify the permalink in some of the front matter of the files. If you want to do them all the same - all pretty without extensions it should be fairly easy.
Linking to /some-document/ already works — the web server’s already configured to serve index.html in these situations. What I’m talking about is controlling the links that Jekyll generates to the documents; i.e. the contents of page.url.
All these pages are part of a single logical document, which is why they’re grouped into a single directory: there’s the index page, plus assorted subpages.
What I want is for Jekyll generates the page.url for the subpages, I want the document’s index page to be /some-document/, while the subpages are referred to in full.
so /:path:output_ext does what you want except for the index page that you want to be /some-document/ right?
Have you tried manually setting the permalink for the index file in its front matter? I think that may be the best way to do it, since you want two different schemes within one particular place.
I’ve got a lot of these; I’d really rather not have to edit all of them…
Anyway, sorted. Although it’s more complicated than it should be because while :path is an (undocumented) permalink variable, there isn’t one for just the directory part.
module Jekyll
class ShortifyGenerator < Jekyll::Generator
def generate(site)
site.collections["pages"].docs.each do |page|
if page.url.end_with?("index.html")
page.data["permalink"] = page.url[0..-11]
end
end
end
end
end