2
votes

I'm working through a guide for setting up Jekyll on GitHub Pages. My GitHub repo publishes to ~.github.io/hello-pages, so naturally I'm plugging {{ site.baseurl }} into anchor tags, etc. That's working great.

What isn't working is permalinks: I have to manually spell out permalink: /hello-pages/blog/:year/:month/:day/:title.html in _config.yml for any of the permalinks to work; otherwise they link to e.g. ~.github.io/blog/x/y/z instead of ~.github.io/hello-pages/blog/x/y/z like I expect.

Manually specifying baseurl: /hello-pages has no effect (I suppose GitHub's Jekyll config already does that).

Manually typing "/hello-pages" anywhere seems like quite a rigid design that I'd like to avoid. An older SO answer says that permalinks should "just work". What gives?


Edit

I am constructing the broken URLs like this:

<a href="{{ post.url }}">

1

1 Answers

5
votes

I just figured out what I was doing wrong. I need to do one of the below things. Here is documentation about this: https://jekyllrb.com/docs/templates/#filters

<a href="{{ post.url | relative_url }}">

This turns the URL into a relative URL, taking the base URL into account.

<a href="{{ post.url | absolute_url }}">

Same as the above, but makes absolute URLs.

<a href="{{ post.url | prepend:site.baseurl }}">

Prepends the base URL to the permalink.