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 · 6 comments

Comments

Projects
None yet
3 participants
@RickCogley
Contributor

RickCogley commented Apr 2, 2017

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

This comment has been minimized.

Show comment
Hide comment
@bep

bep Apr 2, 2017

Member

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.

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 from baseURL behavior different between config.toml and hugo arg in v0.20-DEV to baseURL trailing slash should be consistent between site setting and flag Apr 2, 2017

@RickCogley

This comment has been minimized.

Show comment
Hide comment
@RickCogley

RickCogley Apr 2, 2017

Contributor

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

Contributor

RickCogley commented Apr 2, 2017

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

This comment has been minimized.

Show comment
Hide comment
@RickCogley

RickCogley Apr 2, 2017

Contributor

@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!

Contributor

RickCogley commented Apr 2, 2017

@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

hubolib: Do not add missing trailing slash to command line baseURL
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

@bep bep closed this in #3299 Apr 7, 2017

bep added a commit that referenced this issue Apr 7, 2017

hubolib: Do not add missing trailing slash to command line baseURL
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

This comment has been minimized.

Show comment
Hide comment
@vielmetti

vielmetti Apr 10, 2017

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

Contributor

vielmetti commented Apr 10, 2017

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

This comment has been minimized.

Show comment
Hide comment
@vielmetti

vielmetti Apr 11, 2017

Contributor

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

Contributor

vielmetti commented Apr 11, 2017

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

@vielmetti

This comment has been minimized.

Show comment
Hide comment
@vielmetti

vielmetti Apr 12, 2017

Contributor

Casper theme has been updated with changes.

Contributor

vielmetti commented Apr 12, 2017

Casper theme has been updated with changes.

olehermanse added a commit to olehermanse/kiss that referenced this issue Apr 10, 2018

Use relURL to construct CSS path (recommended by Hugo authors)
See: gohugoio/hugo#3262

Signed-off-by: Ole Herman Schumacher Elgesem <oleherman93@gmail.com>

austinjp added a commit to number3wengen/number3wengen-hugo-theme that referenced this issue Apr 23, 2018

Remove BaseURL, use relURL instead.
Take bep,s advice for edits to his own theme! See gohugoio/hugo#3262

austinjp added a commit to austinjp/blank-hugo-theme that referenced this issue Apr 23, 2018

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