gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
74.93k stars 7.47k forks source link

Support schemaless BaseURL #2085

Closed kanata2 closed 7 years ago

kanata2 commented 8 years ago

Hello, There is a point which was worrisome when using the Hugo to GitHub pages. I want to ask you what I should do in the following cases.

For example

Now, GitHub pages support https. you can access http://example.github.io and https://example.github.io by default when user name of GitHub is example. At this time, if you set one (http or https) as baseurl in config.toml and describe like <script src="{{ .Site.BaseURL }}path/to/example.js"></script> in HTML , it will not load some files when user access GitHub pages in the other protocol. (Seemingly, many hugo's themes use BaseURL in src attribute of script (, link, img, etc) tag)

I believe that we should dispense with a protocol in the src attribute. recommend: src="//path/to/example.js" not recommend: src="http://path/to/example.js"

Solutions

I came up with two solutions.

Please tell me if there is already suggested solutions.

kanata2 commented 8 years ago

sorry, i have solved the problem... 😢

kanata2 commented 8 years ago

I thought going well if you set //example.github.io/ (remove protocol) as baseurl, but it was useless... (https://github.com/spf13/hugo/issues/2085#issuecomment-210615051) I want to ask you what I should do in the case.

bep commented 8 years ago

I think the solution is to add support for schema-less baseURLs, if not already working, as you hint at.

kanata2 commented 8 years ago

Thank you for your comment (and changing the title to a more appropriate one).

bep commented 8 years ago

It would be nice if you can be more clear about what doesn't work when using a schemaless baseURL?

heavywatal commented 8 years ago

Do you need a real baseURL in you content? Relative paths from the root will be enough for src attributes. For example, baseURL = "/" works fine for me on https://username.github.io/ as well as http://localhost/.

dschanoeh commented 8 years ago

I'm hosting a page with hugo on my own domain and I'm using a schema-less base URL. In general, this works just fine. However, when I try to preview the generated page through a $ hugo server, I end up with a 404. Having a baseURL='//domain.tld/'leads to the following local access URL: http://localhost:1313//domain.tld/. Removing the "extra" slash doesn't seem to help. I hope this is appropriate to add to this ticket but this is a bug that hugo itself seems to have with schema-less URLs.

kanata2 commented 8 years ago

when I try to preview the generated page through a $ hugo server, I end up with a 404. Having a baseURL='//domain.tld/' leads to the following local access URL: http://localhost:1313//domain.tld/.

I also didn't go well because of the above reason. However, in the case of GitHub Pages, I also feel one of the solutions is the way that @heavywatal wrote.

atomi commented 8 years ago

Another issue is if you have your blog hosted on multiple domains (mirrored). Using baseUrl, any mirror pulling from a central git repo will have the same baseUrl which would be a problem.

Is there any way to just have hugo not write the base href header?

pfft-meh commented 8 years ago

I too quite miss why baseUrl is needed at all... seems there are A LOT of issues based on this concept.

bep commented 7 years ago

This issue has been automatically marked as stale because it has not been commented on for at least four months.

The resources of the Hugo team are limited, and so we are asking for your help.

If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.

If this is a feature request, and you feel that it is still valuable, please open a proposal at https://discuss.gohugo.io/.

This issue will automatically be closed in four months if no further activity occurs. Thank you for all your contributions.

github-actions[bot] commented 2 years ago

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.