github / pages-gem

A simple Ruby Gem to bootstrap dependencies for setting up and maintaining a local Jekyll environment in sync with GitHub Pages
http://pages.github.com
MIT License
1.82k stars 349 forks source link

baseurl is rendered as an empty string #875

Closed zeakey closed 1 year ago

zeakey commented 1 year ago

This issue affects

What did you do (e.g., steps to reproduce)

I just setup a jekyll website with Jekyll and everything works well locally.

When deploying this site to github pages, I found that the baseurl variable was not properly rendered. What I have in my _config.yaml is: https://github.com/batchfy/batchfy.github.io/blob/ab6dddf4ddf6241a520027c9b9883842648b079d/docs/_config.yml#L1-L2

baseurl: '/'

However, it was rendered as an empty string (""), which broke many url links in my website.

For example, line57 of <batchfy.github.io/team/index.html>:

<a href=""><img width="120px" height="32px" alt="Batchfy" src="[/images/logo/logo.svg](view-source:https://batchfy.github.io/images/logo/logo.svg)" /></a>

The href to the logo should be /, but is actually an empty string.

This href is set to baseurl in the theme: https://github.com/batchfy/batchfy.github.io/blob/ab6dddf4ddf6241a520027c9b9883842648b079d/docs/_includes/header.html#L4

<a href="{{ site.baseurl }}"><img width="{{ site.logo.desktop_width }}" height="{{ site.logo.desktop_height }}" alt="{{ site.title }}" src="{{ site.logo.desktop | relative_url }}" /></a>

What did you expect to happen?

baseurl should be rendered to /, rather than an empty string.

What happened instead?

baseurl was renderred as an empty string.

Additional information

I have manually checked the generated html codes and found that the remotely and locally generated are different. Local codes are correct while github page generated html codes are incorrect.

parkr commented 1 year ago

Definitely recommend using relative_url or absolute_url filters (either with or without a piped-in argument):

{{ "my_url" | relative_url }}
{{ relative_url }}
{{ "my_url" | absolute_url }}
{{ absolute_url }}