[SOLVED] Pages from collection list are not render

Hello all,

I’m writing here about a problem I met, as I’m not sure it is a bug…

I try to render pages from a collection.

I’ve created a directory _collection/ in the root of a project. I put inside some files: authorA.*md, authorB.*md, etc.
I have a page: authors-list.*md to list all the authors from _collection directory with an include:

{% include list-collection collection='authors' %}
from an include page that define this:
 {% for page in site.[include.collection] %}
 {% unless page.published == false %}
 a href="{{ site.url }}{{ page.url }}">{{ page.title }}
 {% endunless %}
 {% endfor %} 

The page authors-list render quiet well the list of all titles of the .md pages from _collection/.
But when I click on one of the title of the list (for example authorA), the page is redirected to a 404 page… But the URL is showing the right path: www.mysite.tld/myjekyll-site/collections/authorA/

In the _config.yml, if I set a permalink for my collection like this:

     output: true
     permalink: '/:collection/:path/

the URL become wrong, as it redirects to: www.mysite.tld/collections/authorA/ (it miss the /myjekyll-site/);
but I’m able to access to the page if I manually enter www.mysite.tld/myjekyll-site/collections/ from which I can see the index and from here to go to my page…

If I do like this:

permalink: ‘/myjekyll-site/:collection/:name’
(or /:path/) the URL is right, but redirect anyway to a 404 page…
and I can’t even reach the index of the directory to find the page…

So, I don’t know so much what to do…

I’m using Jekyll 3.6.0, and I’m actually in localhost.

Hope to find a solution.


are you using baseurl? it sounds like you should be. If your files are not in the root directory and are instead in a sub folder then baseurl should be in your urls so that the links go to the sub folder rather than the root.

You say you are working locally but your examples are with a fake domain/tld, it may be easier for us if you show us the real links including localhost as it will be more accurate. But it sounds like a baseurl problem of some sort. That can be weird to diagnose though as jekyll will change the url for local dev under some circumstances.

Are you running jekyll build or jekyll serve when you preview the site?

Also, I would not recommend naming a collection collection - that seems like a bad idea though it sounds like it is working.

1 Like

thanks for answer.

Ok, I’m going to be more clear and give example as I used them.

Yes, I’m using baseurl.

I’ve set my _config.yml like this:

url: 'https://mydomain.ltd
baseurl: ‘/magazine’

The collection name is ‘authors’.

The full URL to the file, for example authorA.*md, is (on my computer) : localhost:4000/magazine/authors/authorA/

If I set the permalink like this: ‘/magazine/authors/:name’, the URL is right but the page is not rendered.

If I set the permalink like this: ‘/authors/:name’ or ‘/:collection/:name’, the URL is wrong, but I can access to the page by the index of the directory manually.

I’m running jekyll serve to preview my site. Jekyll changes automatically ‘https :// mydomain.ltd’ in ‘localhost:4000’.

Are you suggest/recommend to work directly on a live server and not on localhost?

local is good, just asking to know more.

a href="{{ site.url }}{{ page.url }}">{{ page.title }}

I think you need to have baseurl in here.

1 Like

Yes, it’s working!

I write it like this

a href="{{ site.url }}{{ site.baseurl }}{{ page.url }}">{{ page.title }}

Just that now the URL is quiet strange (but working!), as it add a baseurl name: it becomes:
localhost:4000/magazine/magazine/authors/authorA… (2x magazine)

But maybe, as you said (if I’m right), it’s because Jekyll change sometimes the url on a local dev?

Anyway, thank you very much rdyar!

magazine is your baseurl, and then maybe you have it in your permalink also, sounds like you could remove it there.

and yes, I find the localhost/baseurl/siteurl magic a little much - I generally do not use baseurl or siteurl, but I don’t host on GH usually and I am not making a theme to give others so I just use relative urls and if I need the full url I hard code it. I also only host at the root - not in a sub folder where you need baseurl.

Jekyll serve will swap out site url, jekyll build will not. I think that is what goes on. Although I think it also does something with baseurl - I thought it dropped it locally but not according to your links.

I’ve change the permalink in _config.yml, but still have 2 times the baseuri appear in the URL.

But I will investigate in other files. Maybe there is a permalink somewhere or else…

Thanks again!