URLs and relative paths

@fabianfalck

First of all, I have wrapped the URLs you posted in code blocks because the forum anti spam software flagged your posts for excessive external linking.

Please use the code block button when posting the contents of your config.

Second, your baseURL configuration is non standard. The Docs are quite explicit.

Also you need to post the full source code of your repository just a content file and the config are not enough because we need to see how you construct these links in your templates.

Hey everyone,
Thanks a lot for your help - I really appreciate it!

As you requested, I pushed all website source files to this repo: https://github.com/FabianFalck/upload . All I do is run “hugo” in this folder and then copy the thing via FTP to my website.

I followed your advices, but still could not find a solution. I think @funkydan2 's advice is good: relativeURLs should be set to true. But I don’t really know how the css file could then be correctly found. And still, the URLs don’t work properly.

I think it is really one or two parameters that have to be changed, but I can’t find them…

The variable is called baseURL and you need to match the case exactly.

So change line 9 of your config.toml to the following: baseURL = "http://fabianfalck.com/"

Eliminate everything else from line 9.

After doing this run hugo server or hugo and report back here if your problem persists.

3 Likes

Thanks a lot, I really thought this was the “error you can’t find” and it would solve it. Unfortunately, it didn’t.

I did exactly as you said and pushed the public folder to my website, but weird behavior of external links being prefixed by my website name persists…

PS.: Would it be possible to give me rights to post immediately? I always have to wait a day or an hour to post again…

Adminstrivia: I set you as a basic user in these forums; it would have switched over today, but no reason to wait. :slight_smile:

So I’ve cloned your site and noticed a few things.

  1. baseURL is case sensitive, and needs to be set to the URL your site is published to (e.g. baseURL = "http://fabianfalck.com/" (see @alexandros’s post above)
  2. In page frontmatter, URLs which refer to external sites need to start with either http(s):// or //. e.g. in content/publication/ipp2018.md set url_dataset = "//www.politicalcompass.de/data/preprocessedsentiments.csv".

The reason for 2. is because the theme uses this code to build the link buttons:

<a class="btn btn-outline-primary my-1 mr-1{{ if $is_list }} btn-sm{{end}}" href="{{ .RelPermalink }}">

And (I understand that) .RelPermalink is seeing a url which doesn’t include // and is interpretting the string as a reference to a local file, instead of to an external site.

Finally…if you’re using Netlify for hosting, you can take advantage of having your site built from a git repository


The main thing you’ll need to do is change your theme to be a submodule.

2 Likes

@funkydan2 Your support is superb! Thanks a lot for your help!

However, I am afraid it still does not work for me. I did 1. and 2. (I also updated my website), but it is still prefixed by the website domain before the www, both when adding // and http://. Did this work for you when you cloned the page on your machine?

UPDATE: When I test the website with “hugo server”, everything works perfectly fine! So only on my actual website server, there is a problem. Does anyone have an idea what this difference could result from, i.e. how is hugo server different from hosting it on my website?

I think this is now very close to be solved, but still don’t know how to do it…

If it hasn’t been resolved by then, tonight I’ll clone your repo locally and see if I can reproduce

@zwbetz Awesome, thank you so much! :slight_smile: I really can’t tell what is going wrong, it must be super trivial…

A difference between running hugo and hugo server is that when you’re running the testing environment, the baseURL setting is ignored (or, actually I think it’s set to localhost:1313).

When I run hugo on your repository - having changed baseURL and removed the relativeURLs setting, I get

<a class="btn btn-outline-primary my-1 mr-1 btn-sm" href="/www.politicalcompass.de/data/preprocessedsentiments.csv" target="_blank" rel="noopener">

Note the preceeding /—this is interpretted as a relative link, i.e. a link to file on your webserver.

When I change url_datatset in /content/publication/ipp2018.md to have preceding //the output is

<a class="btn btn-outline-primary my-1 mr-1 btn-sm" href="//www.politicalcompass.de/data/preprocessedsentiments.csv" target="_blank" rel="noopener">

Which is a link to an external site.

So have another look at your settings. And also, please keep your git repository up to date so we’re all looking at the same thing.

1 Like

I agree, the href parameter is correct. However, when I click on my website on this exact button, then the URL prefixed with my website is opened. That’s how I test it all the time and that’s what does not work. Maybe this helps to solve it…

Not at my laptop yet, but in addition to what @funkydan2 mentioned, you could also try making the link

http://www.politicalcompass.de

As it will become this anyway when clicked

www.politicalcompass.de

Thanks for updating your github repository.

The public folder hasn’t been updated to match the changes you’ve made (the public folder was updated 12 hours ago and the content and config.toml 2 hours ago…when I’m looking at it). After running hugo after making edits, and then uploading the new files in /public to your server? When I look at the code on your live server, and the public folder on github, it’s different from when I clone your repository, build the site using hugo and inspect the source.

I just tested this and got the following:

Chrome Browser served buy Hugo:
<a class="btn btn-outline-primary my-1 mr-1 btn-sm" href="http://www.politicalcompass.de" target="_blank" rel="noopener">
  Website
</a>

Hugo Server build in Public index.html:
<a class="btn btn-outline-primary my-1 mr-1 btn-sm" href="/http:/www.politicalcompass.de" target="_blank" rel="noopener">
  Website
</a>

@mojoa I just tested as well. I got the same result when viewing the page source after running hugo server.

But I get a different result than you when running hugo and viewing the index.html. For me the URL shows correctly:

<a class="btn btn-outline-primary my-1 mr-1 btn-sm" href="http://www.politicalcompass.de" target="_blank" rel="noopener">
  Website
</a>

@fabianfalck To be safe, make sure you delete the public/ folder before running hugo again. But on my end, things look good.

Which version of Hugo are you running? I used .49 Linux.

Am currently using 0.49.2 on my Windows box. But I wouldn’t think the version would be the culprit. Perhaps you don’t have the latest commits on Fabian’s repo?

Ok, I cloned again and I am now getting the correct result.

Everyone: Thanks a ton for your enormous support!

I could now narrow the problem down: I agree with you that the compilation with “hugo” on my local machine works. In the HTML files, the link is given as "//www.politicalcompass.de/data/preprocessedsentiments.csv" which will point to an external website.

However, when I transfer the public folder to my server and look at the source on www.fabianfalck.com on the Index page (searching for politicalcompass), the link is ./http:/www.politicalcompass.de/data/preprocessedsentiments.csv. When you actually click on it, the link changes to http://fabianfalck.com/http:/www.politicalcompass.de/data/preprocessedsentiments.csv which makes sense. But obviously, this link is wrong, as this is no internal document.

So the issue comes from the server somehow. Did anyone have had this issue before and an idea what this might come from?