yvele
March 1, 2019, 8:52pm
1
I’m trying
<link rel="canonical" href="{{ .Permalink | absURL }}">
But it’s returning me the relative URL… I don’t get it
PS: I’m actually upgrading hugo from an old version… I don’t want to canonicalize all URLs but sometimes I want an absolute URL (with the host name in it)
zwbetz
March 1, 2019, 8:57pm
2
So .Permalink
is already the absolute URL. You probably have a setting in your config file for relative URLs. Show us your config file.
1 Like
yvele
March 1, 2019, 9:03pm
3
I have a super simple configuration file
baseURL = "http://domain.com/"
languageCode = "en-us"
title = "Domain"
pluralizeListTitles = false
preserveTaxonomyNames = true
ignoreFiles = [ "\\.original.jpg$" ]
[author]
name = "Me"
[taxonomies]
tag = "tags"
All I want is the absolute URL with the host name in it.
zwbetz
March 1, 2019, 9:19pm
4
Hmm. What Hugo version are you using?
yvele
March 1, 2019, 9:25pm
5
The last one
Hugo Static Site Generator v0.54.0/extended darwin/amd64 BuildDate: unknown
This is driving me crazy…
Even with a param in the configuration the host name is… removed?!
[params]
hostName = "http://domain.com"
<link rel="canonical" href="{{ .Site.Params.hostName }}{{ .Permalink | absURL }}">
The only way is to actually write the host name MANUALLY like that
<link rel="canonical" href="http://domain.com{{ .Permalink | absURL }}">
But I can’t do that… I have multiple host names by environments (production, test, dev, etc.)
zwbetz
March 1, 2019, 9:26pm
6
There is something else going on here. Could you share your full site code?
1 Like
yvele
March 1, 2019, 9:32pm
8
I can’t share my full site code… it’s big and private
I have a warning in my code… is it possible that it may cause some troubles?
Building sites … WARNING: calling IsSet with unsupported type "invalid" (<nil>) will always return false.
bep
March 1, 2019, 9:35pm
9
Did you solve the problem described in the title?
yvele
March 1, 2019, 9:39pm
10
No I style have the problem as described in the title.
I’m trying workaround using site params {{ $.Site.Params.hostName }}
and I don’t understand how is hugo even not outputting the param at all. I’m getting esoterical and I’m checking any potential clue (the warning maybe?)
bep
March 1, 2019, 9:47pm
11
yvele:
(the warning maybe?)
The warning isn’t relevant to this issue. I suggest you look at my post above and compare that to the documentation and the many example sites on the web.
yvele
March 1, 2019, 9:50pm
12
That’s what I’ve done
This is my config file
baseURL = "http://domain.com/"
languageCode = "en-us"
title = "Domain"
pluralizeListTitles = false
preserveTaxonomyNames = true
ignoreFiles = [ "\\.original.jpg$" ]
[author]
name = "Me"
[taxonomies]
tag = "tags"
[params]
hostName = "http://domain.com"
And in a layout/partials/header.html I’m doing thoses
<link rel="canonical" href="{{ .Permalink }}">
<link rel="canonical" href="{{ .Permalink | absURL }}">
<link rel="canonical" href="{{ .Site.Params.hostName }}{{ .Permalink | absURL }}">
And none of them are getting me absolute URLs with the host name in it
That’s exactly what you’ve suggested (and what the docs says)
You are using:
yvele:
baseurl
But that is not exactly what was posted above:
bep:
baseURL
Hint: use the exact case for baseURL
Configure Hugo | Hugo
Also if your problem remains unresolved after doing the above then you really need to share your project with dummy content for us to see the full context.
yvele
March 1, 2019, 10:00pm
14
alexandros:
baseURL
I’m already using the exact case baseURL
, I also was thinking that was the problem, but unfortunately it’s not
PS: I was using baseurl
with hugo 0.17 without any problem… anyway I’ve already switched to baseURL
and I still have the problem
Try removing the cache i.e. hugo server --ignoreCache
Beyond that I cannot reproduce your problem locally with the config and the template code you posted above.
yvele
March 1, 2019, 10:15pm
16
Thank you all… I will take some rest and later try to make a minimal reproduction case.
I’ll keep you all updated
I don´t know what you are trying to do, if you are trying to do imports like in the example you could use relative urls instead absolute ones, this way is the most common since is possible to change the location of the files all together.
If you are trying to do somethin more advanced another option is to get the url from js: https://css-tricks.com/snippets/javascript/get-url-and-url-parts-in-javascript/