Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

baseURL trailing slash should be consistent between site setting and flag #3262

Closed
RickCogley opened this issue Apr 2, 2017 · 7 comments · Fixed by #3299
Closed

baseURL trailing slash should be consistent between site setting and flag #3262

RickCogley opened this issue Apr 2, 2017 · 7 comments · Fixed by #3299
Assignees
Milestone

Comments

@RickCogley
Copy link
Contributor

Hello - it's been a while.

If I set a baseURL in my config.toml, such as http://www.mysite.com, when I use {{ .Site.BaseURL }}, no trailing slash is appended, so I'd compensate by adding one in the template.

Then, say if I want to publish the same content to http://anothersite.com/~myuser, I can override the baseURL in the hugo command when I generate like:

 hugo --config="/path/to/my/config.toml" --baseURL="http://anothersite.com/~myuser" -s /path/to/my/site/ -d /tmp/anothersite.com.myuser

...but, when doing this, it appends a trailing slash, so I don't need to compensate.

Should this not be consistent?

Using:
Hugo Static Site Generator v0.20-DEV-73C1C7B6 darwin/amd64 BuildDate: 2017-04-02T16:28:29+09:00

@bep
Copy link
Member

bep commented Apr 2, 2017

It should be consistent. But manually creating URLs using {{ .Site.BaseURL }} is fragile, esp. for themes, and not recommended.

Use absURL and friends, and you should not have to worry about slashes.

@bep bep changed the title baseURL behavior different between config.toml and hugo arg in v0.20-DEV baseURL trailing slash should be consistent between site setting and flag Apr 2, 2017
@RickCogley
Copy link
Contributor Author

thanks @bep, I'll give it a try!

@bep bep self-assigned this Apr 2, 2017
@bep bep added the Bug label Apr 2, 2017
@bep bep added this to the v0.20 milestone Apr 2, 2017
@RickCogley
Copy link
Contributor Author

@bep as you say, that works perfectly.

For future reference for searchers, doing:

 <img src="{{ "img/mylogo.jpg" | relURL }}" class="this that" alt="Logo">

... for the http://anothersite.com/~myuser site, gives:

 <img src="/~myuser/img/mylogo.jpg" class="this that" alt="Logo">

... and for the http://www.mysite.com site, gives:

 <img src="/img/mylogo.jpg" class="this that" alt="Logo">

Thanks again!

bep added a commit to bep/hugo that referenced this issue Apr 7, 2017
This makes it consistent with how it behaves when it's set in config.toml.

This commit also unifies BaseURL in Site.Info so we now have one source for this value.

Fixes gohugoio#3262
@bep bep closed this as completed in #3299 Apr 7, 2017
bep added a commit that referenced this issue Apr 7, 2017
This makes it consistent with how it behaves when it's set in config.toml.

This commit also unifies BaseURL in Site.Info so we now have one source for this value.

Fixes #3262
@vielmetti
Copy link
Contributor

This change is a bug fix and it also will break configurations that relied inadvertently on the old buggy code. It's a one-byte fix if you need the trailing slash. If you need it and don't use it, you'll get this behavior:

https://discuss.gohugo.io/t/hugo-0-20-upgrade-page-template-breaks/6097

@vielmetti
Copy link
Contributor

vjeantet/hugo-theme-casper#84 notes changes suggested to the Casper theme for 0.20.

@vielmetti
Copy link
Contributor

Casper theme has been updated with changes.

olehermanse added a commit to olehermanse/kiss that referenced this issue Apr 10, 2018
See: gohugoio/hugo#3262

Signed-off-by: Ole Herman Schumacher Elgesem <oleherman93@gmail.com>
lidel added a commit to lidel/website-1 that referenced this issue Sep 11, 2018
- lacked favicon when loaded from /ipns/ path
- social media embeds had broken images

This also fixes trailing slash issues mentioned in:
gohugoio/hugo#3262

License: MIT
Signed-off-by: Marcin Rataj <lidel@lidel.org>
vmx pushed a commit to ipld/website that referenced this issue Sep 13, 2018
- lacked favicon when loaded from /ipns/ path
- social media embeds had broken images

This also fixes trailing slash issues mentioned in:
gohugoio/hugo#3262

License: MIT
Signed-off-by: Marcin Rataj <lidel@lidel.org>
justinharringa added a commit to justinharringa/bota-hugo-theme that referenced this issue May 28, 2019
chrisreddington added a commit to chrisreddington/hugo-community that referenced this issue Dec 13, 2020
Signed-off-by: Chris Reddington <791642+chrisreddington@users.noreply.github.com>
jantari pushed a commit to jantari/LSUClient-docs that referenced this issue Mar 12, 2022
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants