Set permalinks "pretty" for collections? #2293

Closed
budparr opened this Issue May 3, 2014 · 12 comments

Comments

Projects
None yet
5 participants
Contributor

budparr commented May 3, 2014

In Jekyll 2.0.0.rc1

For _config.yml I have
permalink: pretty

I would think that this setting would be respected throughout the site, including collections but my collections documents end with a ".html" extension while posts and pages render as expected.

I also tried:

collections:
  books:
    output: true
    permalink: pretty

But this didn't change anything. I don't know Ruby, but I was comparing the collection.rb file to the page.rb and didn't see the same references vis-à-vis permalinks.

Contributor

paulrobertlloyd commented May 3, 2014

+1

Owner

parkr commented May 3, 2014

There is no special permalink key in collections specification. The documents will be output by /:collection_name/:filename:output_ext: https://github.com/jekyll/jekyll/blob/master/lib/jekyll/document.rb#L95

Contributor

budparr commented May 4, 2014

Sorry, @parkr I don't understand from that how to make my collection URLs "pretty" or otherwise manipulate them. I can also over in jekyll-help if you prefer.

Owner

parkr commented May 5, 2014

You cannot change the URL of your collection – your collection has no URL itself, it is merely used to determine the URL of its constituent documents. Each document uses the format I linked to above, or the permalink specified in the header. If no permalink is specified for a document called chapter1 in a collection called books, the permalink will be books/chapter1.html.

parkr closed this May 5, 2014

Contributor

budparr commented May 5, 2014

So to exclude the extension from the permalink of the documents in a collection we need to manually set the permalink for every single document in the front-matter. I don't think that's optimal in many use-cases.

I would expect that we would be able to set "url_template" (or whatever) as a parameter in _config.yml to make permalinks pretty for the entire collection, which does not work.

Owner

parkr commented May 5, 2014

exclude the extension from the permalink

Just curious, why do you want to do this? Extensions are very useful things.

I think for 2.0, we don't need to add this in. For 2.1, perhaps.

Contributor

budparr commented May 5, 2014

Not using extensions makes your pages technology agnostic, so you can move from one underlying technology to another without relying on a mountain of re-directs.

This is a common development pattern that I'd think you would not want to dictate on your users. I'll wait for 2.1 to use them because to my mind collections don't exist without something so fundamental.

All due respect, though @parkr, great work and I never would have guessed you'd have built them so quickly.

Owner

parkr commented May 5, 2014

Not using extensions makes your pages technology agnostic, so you can move from one underlying technology to another without relying on a mountain of re-directs.

Can you give me an example? Are you thinking HTML ~> JSON, or Nginx ~> Apache? "Technology" is, of course, a very vague term. As it stands, the first guess I gave would be hugely inadvisable, and the second uses 2 technologies which do the same thing and have very similar capabilities.

The only reason I've heard other than the one you gave is vanity: they don't like the way .html looks.

Contributor

budparr commented May 5, 2014

You're just teasing me, right? example: PHP ~ HTML

Seriously, I'm not sure why you're even arguing the point. If it's not an issue, why does Jekyll have pretty permalinks in the first place? This is classic stuff dating back to Tim Berners-Lee's "Cool URIs don't change" where he recommends leaving the extension off. That's why I and everyone I know have been doing it this way over the past dozen years - it's good practice.

Contributor

paulrobertlloyd commented May 5, 2014

I’m in agreement with @budparr. I’m in the process of moving my site from one built with PHP to a static site powered by Jekyll. Although pages on my site are currently written using PHP, I do not use file extensions so that if I change the underlying stack (as I am doing now), the URLs will remain valid.

Ideally, there would be a global setting relating to the inclusion/exclusion of file extensions, with the permalink configuration option relating to the structure of (post) permalink URLs.

You can make your collection pretty like this (in _config.yml):

collections:
  article:
    output: true
    permalink: /:collection/:path/index.html

ctubbsii commented Mar 9, 2016

@steveortiz that doesn't seem to work for me in Jekyll 3. I'm trying to use /:collection/:title/index.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment