-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
Add support for URLs relative to context root #1104
Comments
I guess the term relative is ... relative. |
@jbenet What does your content source look like? I guess I'm confused as to how you're feeding the links into hugo. I set I'm able to get a relative link by rendering this markdown:
|
@insanity54 setting
@insanity54 when you built, how do the links to the first post look in
note the |
To clarify, my issue here is not with links i make inside posts, it's with links hugo generates to posts from lists and so on. They are generated absolute, which simply do not work at all with many kinds of static hosting where the final location is not known at compile time. (e.g. content addressing/content hashing). |
@jbenet what you want isn't currently supported in Hugo. The definition of relative in Hugo is "relative to the domain root", but includes the context-root. So for site hosted at "http://mydomain.com/site" a relative URL will look like "/site/css/somecss.css". "css/somecss.css" would be relative to the context-root, but that would only not work when used below "/mysection". |
@jbenet when I followed the quickstart guide and did
I just removed the line with the baseurl directive. (I was guessing that was what you did) Ah I see what you're saying. Not links insite the post, but the links on the index to the post. In that case, I'm getting the same as you.
|
Could you explain to me what would be involved in adding support for this? I can see if I can PR. (IMO, lack is brittle) |
But to get to where you want, I'm not sure. URL creation isn't as "in one place" as I would want, but even if it was, your problem is contextual (a page's URL should be different when rendered on the home page, At first thought, you would think that you could expand on the mechanism used for https://github.com/spf13/hugo/blob/master/transform/absurlreplacer.go#L270 But it will fail further down. I may come up with a better idea later. |
The way I've seen this worked around in Jekyll is to declare the per-page relative URL pointing to the root path (e.g. I think that's a sound approach, but it would be great if the static generator could automatically calculate the relative path from a given page to the site root. In Hugo's case, this will depend on the ugly URLs setting. That should be pretty easy with |
Sure, the In Hugo it's also possible to use a Page in other sections (mostly on the home page). |
On Thu, May 07, 2015 at 05:01:41AM -0700, Bjørn Erik Pedersen wrote:
So you'd have to re-render that Page using it's new context for |
Yeah, i think that would work |
Most things are doable, but it's not a one-liner change, either. |
Setting `RelativeURLs` to `true` will make all relative URLs in the site *really* relative. And will do so with speed. So: In `/post/myblogpost.html`: `/mycss.css` becomes `../mycss.css` The same in /index.html` will become: `./mycss.css` etc. Note that absolute URLs will not be touched (either external resources, or URLs constructed with `BaseURL`). THIS WORKS, BUT NEEDS SOME POLISH. WORK IN PROGRESS. Fixes gohugoio#1104 Fixes gohugoio#622
Setting `RelativeURLs` to `true` will make all relative URLs in the site *really* relative. And will do so with speed. So: In `/post/myblogpost.html`: `/mycss.css` becomes `../mycss.css` The same in `/index.html` will become: `./mycss.css` etc. Note that absolute URLs will not be touched (either external resources, or URLs constructed with `BaseURL`). THIS WORKS, BUT NEEDS SOME POLISH. WORK IN PROGRESS. Fixes gohugoio#1104 Fixes gohugoio#622
Setting `RelativeURLs` to `true` will make all relative URLs in the site *really* relative. And will do so with speed. So: In `/post/myblogpost.html`: `/mycss.css` becomes `../mycss.css` The same in `/index.html` will become: `./mycss.css` etc. Note that absolute URLs will not be touched (either external resources, or URLs constructed with `BaseURL`). THIS WORKS, BUT NEEDS SOME POLISH. WORK IN PROGRESS. The speediness is about the same as before: ``` benchmark old ns/op new ns/op delta BenchmarkAbsURL 24135 24777 +2.66% BenchmarkAbsURLSrcset 26345 26803 +1.74% BenchmarkXMLAbsURLSrcset 25956 27344 +5.35% BenchmarkXMLAbsURL 13089 13231 +1.08% benchmark old allocs new allocs delta BenchmarkAbsURL 24 24 +0.00% BenchmarkAbsURLSrcset 29 29 +0.00% BenchmarkXMLAbsURLSrcset 27 27 +0.00% BenchmarkXMLAbsURL 12 12 +0.00% benchmark old bytes new bytes delta BenchmarkAbsURL 3183 3218 +1.10% BenchmarkAbsURLSrcset 2373 2428 +2.32% BenchmarkXMLAbsURLSrcset 2559 2611 +2.03% BenchmarkXMLAbsURL 1878 1916 +2.02% ``` Fixes gohugoio#1104 Fixes gohugoio#622
Setting `RelativeURLs` to `true` will make all relative URLs in the site *really* relative. And will do so with speed. So: In `/post/myblogpost.html`: `/mycss.css` becomes `../mycss.css` The same in `/index.html` will become: `./mycss.css` etc. Note that absolute URLs will not be touched (either external resources, or URLs constructed with `BaseURL`). The speediness is about the same as before: ``` benchmark old ns/op new ns/op delta BenchmarkAbsURL 24135 24777 +2.66% BenchmarkAbsURLSrcset 26345 26803 +1.74% BenchmarkXMLAbsURLSrcset 25956 27344 +5.35% BenchmarkXMLAbsURL 13089 13231 +1.08% benchmark old allocs new allocs delta BenchmarkAbsURL 24 24 +0.00% BenchmarkAbsURLSrcset 29 29 +0.00% BenchmarkXMLAbsURLSrcset 27 27 +0.00% BenchmarkXMLAbsURL 12 12 +0.00% benchmark old bytes new bytes delta BenchmarkAbsURL 3183 3218 +1.10% BenchmarkAbsURLSrcset 2373 2428 +2.32% BenchmarkXMLAbsURLSrcset 2559 2611 +2.03% BenchmarkXMLAbsURL 1878 1916 +2.02% ``` Fixes gohugoio#1104 Fixes gohugoio#622
Setting `RelativeURLs` to `true` will make all relative URLs in the site *really* relative. And will do so with speed. So: In `/post/myblogpost.html`: `/mycss.css` becomes `../mycss.css` The same in `/index.html` will become: `./mycss.css` etc. Note that absolute URLs will not be touched (either external resources, or URLs constructed with `BaseURL`). The speediness is about the same as before: ``` benchmark old ns/op new ns/op delta BenchmarkAbsURL 24135 24777 +2.66% BenchmarkAbsURLSrcset 26345 26803 +1.74% BenchmarkXMLAbsURLSrcset 25956 27344 +5.35% BenchmarkXMLAbsURL 13089 13231 +1.08% benchmark old allocs new allocs delta BenchmarkAbsURL 24 24 +0.00% BenchmarkAbsURLSrcset 29 29 +0.00% BenchmarkXMLAbsURLSrcset 27 27 +0.00% BenchmarkXMLAbsURL 12 12 +0.00% benchmark old bytes new bytes delta BenchmarkAbsURL 3183 3218 +1.10% BenchmarkAbsURLSrcset 2373 2428 +2.32% BenchmarkXMLAbsURLSrcset 2559 2611 +2.03% BenchmarkXMLAbsURL 1878 1916 +2.02% ``` Fixes gohugoio#1104 Fixes gohugoio#622
Setting `RelativeURLs` to `true` will make all relative URLs in the site *really* relative. And will do so with speed. So: In `/post/myblogpost.html`: `/mycss.css` becomes `../mycss.css` The same in `/index.html` will become: `./mycss.css` etc. Note that absolute URLs will not be touched (either external resources, or URLs constructed with `BaseURL`). The speediness is about the same as before: ``` benchmark old ns/op new ns/op delta BenchmarkAbsURL 24135 24777 +2.66% BenchmarkAbsURLSrcset 26345 26803 +1.74% BenchmarkXMLAbsURLSrcset 25956 27344 +5.35% BenchmarkXMLAbsURL 13089 13231 +1.08% benchmark old allocs new allocs delta BenchmarkAbsURL 24 24 +0.00% BenchmarkAbsURLSrcset 29 29 +0.00% BenchmarkXMLAbsURLSrcset 27 27 +0.00% BenchmarkXMLAbsURL 12 12 +0.00% benchmark old bytes new bytes delta BenchmarkAbsURL 3183 3218 +1.10% BenchmarkAbsURLSrcset 2373 2428 +2.32% BenchmarkXMLAbsURLSrcset 2559 2611 +2.03% BenchmarkXMLAbsURL 1878 1916 +2.02% ``` Fixes gohugoio#1104 Fixes gohugoio#622
Setting `RelativeURLs` to `true` will make all relative URLs in the site *really* relative. And will do so with speed. So: In `/post/myblogpost.html`: `/mycss.css` becomes `../mycss.css` The same in `/index.html` will become: `./mycss.css` etc. Note that absolute URLs will not be touched (either external resources, or URLs constructed with `BaseURL`). The speediness is about the same as before: ``` benchmark old ns/op new ns/op delta BenchmarkAbsURL 24135 24777 +2.66% BenchmarkAbsURLSrcset 26345 26803 +1.74% BenchmarkXMLAbsURLSrcset 25956 27344 +5.35% BenchmarkXMLAbsURL 13089 13231 +1.08% benchmark old allocs new allocs delta BenchmarkAbsURL 24 24 +0.00% BenchmarkAbsURLSrcset 29 29 +0.00% BenchmarkXMLAbsURLSrcset 27 27 +0.00% BenchmarkXMLAbsURL 12 12 +0.00% benchmark old bytes new bytes delta BenchmarkAbsURL 3183 3218 +1.10% BenchmarkAbsURLSrcset 2373 2428 +2.32% BenchmarkXMLAbsURLSrcset 2559 2611 +2.03% BenchmarkXMLAbsURL 1878 1916 +2.02% ``` Fixes gohugoio#1104 Fixes gohugoio#622
Setting `RelativeURLs` to `true` will make all relative URLs in the site *really* relative. And will do so with speed. So: In `/post/myblogpost.html`: `/mycss.css` becomes `../mycss.css` The same in `/index.html` will become: `./mycss.css` etc. Note that absolute URLs will not be touched (either external resources, or URLs constructed with `BaseURL`). The speediness is about the same as before: ``` benchmark old ns/op new ns/op delta BenchmarkAbsURL 17462 18164 +4.02% BenchmarkAbsURLSrcset 18842 19632 +4.19% BenchmarkXMLAbsURLSrcset 18643 19313 +3.59% BenchmarkXMLAbsURL 9283 9656 +4.02% benchmark old allocs new allocs delta BenchmarkAbsURL 24 28 +16.67% BenchmarkAbsURLSrcset 29 32 +10.34% BenchmarkXMLAbsURLSrcset 27 30 +11.11% BenchmarkXMLAbsURL 12 14 +16.67% benchmark old bytes new bytes delta BenchmarkAbsURL 3154 3404 +7.93% BenchmarkAbsURLSrcset 2376 2573 +8.29% BenchmarkXMLAbsURLSrcset 2569 2763 +7.55% BenchmarkXMLAbsURL 1888 1998 +5.83% ``` Fixes gohugoio#1104 Fixes gohugoio#622
Setting `RelativeURLs` to `true` will make all relative URLs in the site *really* relative. And will do so with speed. So: In `/post/myblogpost.html`: `/mycss.css` becomes `../mycss.css` The same in `/index.html` will become: `./mycss.css` etc. Note that absolute URLs will not be touched (either external resources, or URLs constructed with `BaseURL`). The speediness is about the same as before: ``` benchmark old ns/op new ns/op delta BenchmarkAbsURL 17462 18164 +4.02% BenchmarkAbsURLSrcset 18842 19632 +4.19% BenchmarkXMLAbsURLSrcset 18643 19313 +3.59% BenchmarkXMLAbsURL 9283 9656 +4.02% benchmark old allocs new allocs delta BenchmarkAbsURL 24 28 +16.67% BenchmarkAbsURLSrcset 29 32 +10.34% BenchmarkXMLAbsURLSrcset 27 30 +11.11% BenchmarkXMLAbsURL 12 14 +16.67% benchmark old bytes new bytes delta BenchmarkAbsURL 3154 3404 +7.93% BenchmarkAbsURLSrcset 2376 2573 +8.29% BenchmarkXMLAbsURLSrcset 2569 2763 +7.55% BenchmarkXMLAbsURL 1888 1998 +5.83% ``` Fixes gohugoio#1104 Fixes gohugoio#622
Setting `RelativeURLs` to `true` will make all relative URLs in the site *really* relative. And will do so with speed. So: In `/post/myblogpost.html`: `/mycss.css` becomes `../mycss.css` The same in `/index.html` will become: `./mycss.css` etc. Note that absolute URLs will not be touched (either external resources, or URLs constructed with `BaseURL`). The speediness is about the same as before: ``` benchmark old ns/op new ns/op delta BenchmarkAbsURL 17462 18164 +4.02% BenchmarkAbsURLSrcset 18842 19632 +4.19% BenchmarkXMLAbsURLSrcset 18643 19313 +3.59% BenchmarkXMLAbsURL 9283 9656 +4.02% benchmark old allocs new allocs delta BenchmarkAbsURL 24 28 +16.67% BenchmarkAbsURLSrcset 29 32 +10.34% BenchmarkXMLAbsURLSrcset 27 30 +11.11% BenchmarkXMLAbsURL 12 14 +16.67% benchmark old bytes new bytes delta BenchmarkAbsURL 3154 3404 +7.93% BenchmarkAbsURLSrcset 2376 2573 +8.29% BenchmarkXMLAbsURLSrcset 2569 2763 +7.55% BenchmarkXMLAbsURL 1888 1998 +5.83% ``` Fixes gohugoio#1104 Fixes gohugoio#622
Setting `RelativeURLs` to `true` will make all relative URLs in the site *really* relative. And will do so with speed. So: In `/post/myblogpost.html`: `/mycss.css` becomes `../mycss.css` The same in `/index.html` will become: `./mycss.css` etc. Note that absolute URLs will not be touched (either external resources, or URLs constructed with `BaseURL`). The speediness is about the same as before: ``` benchmark old ns/op new ns/op delta BenchmarkAbsURL 17462 18164 +4.02% BenchmarkAbsURLSrcset 18842 19632 +4.19% BenchmarkXMLAbsURLSrcset 18643 19313 +3.59% BenchmarkXMLAbsURL 9283 9656 +4.02% benchmark old allocs new allocs delta BenchmarkAbsURL 24 28 +16.67% BenchmarkAbsURLSrcset 29 32 +10.34% BenchmarkXMLAbsURLSrcset 27 30 +11.11% BenchmarkXMLAbsURL 12 14 +16.67% benchmark old bytes new bytes delta BenchmarkAbsURL 3154 3404 +7.93% BenchmarkAbsURLSrcset 2376 2573 +8.29% BenchmarkXMLAbsURLSrcset 2569 2763 +7.55% BenchmarkXMLAbsURL 1888 1998 +5.83% ``` Fixes gohugoio#1104 Fixes gohugoio#622
Setting `RelativeURLs` to `true` will make all relative URLs in the site *really* relative. And will do so with speed. So: In `/post/myblogpost.html`: `/mycss.css` becomes `../mycss.css` The same in `/index.html` will become: `./mycss.css` etc. Note that absolute URLs will not be touched (either external resources, or URLs constructed with `BaseURL`). The speediness is about the same as before: ``` benchmark old ns/op new ns/op delta BenchmarkAbsURL 17462 18164 +4.02% BenchmarkAbsURLSrcset 18842 19632 +4.19% BenchmarkXMLAbsURLSrcset 18643 19313 +3.59% BenchmarkXMLAbsURL 9283 9656 +4.02% benchmark old allocs new allocs delta BenchmarkAbsURL 24 28 +16.67% BenchmarkAbsURLSrcset 29 32 +10.34% BenchmarkXMLAbsURLSrcset 27 30 +11.11% BenchmarkXMLAbsURL 12 14 +16.67% benchmark old bytes new bytes delta BenchmarkAbsURL 3154 3404 +7.93% BenchmarkAbsURLSrcset 2376 2573 +8.29% BenchmarkXMLAbsURLSrcset 2569 2763 +7.55% BenchmarkXMLAbsURL 1888 1998 +5.83% ``` Fixes gohugoio#1104 Fixes gohugoio#622 Fixes gohugoio#937 Fixes #157
Thank you @bep |
The relative URL-ifier doesn't seem to kick in on the action attribute on form tags. |
Setting `RelativeURLs` to `true` will make all relative URLs in the site *really* relative. And will do so with speed. So: In `/post/myblogpost.html`: `/mycss.css` becomes `../mycss.css` The same in `/index.html` will become: `./mycss.css` etc. Note that absolute URLs will not be touched (either external resources, or URLs constructed with `BaseURL`). The speediness is about the same as before: ``` benchmark old ns/op new ns/op delta BenchmarkAbsURL 17462 18164 +4.02% BenchmarkAbsURLSrcset 18842 19632 +4.19% BenchmarkXMLAbsURLSrcset 18643 19313 +3.59% BenchmarkXMLAbsURL 9283 9656 +4.02% benchmark old allocs new allocs delta BenchmarkAbsURL 24 28 +16.67% BenchmarkAbsURLSrcset 29 32 +10.34% BenchmarkXMLAbsURLSrcset 27 30 +11.11% BenchmarkXMLAbsURL 12 14 +16.67% benchmark old bytes new bytes delta BenchmarkAbsURL 3154 3404 +7.93% BenchmarkAbsURLSrcset 2376 2573 +8.29% BenchmarkXMLAbsURLSrcset 2569 2763 +7.55% BenchmarkXMLAbsURL 1888 1998 +5.83% ``` Fixes gohugoio#1104 Fixes gohugoio#622 Fixes gohugoio#937 Fixes gohugoio#157
ac2c4a487 Update documentation for Ugly URLs (#1082) 88bdec17a Change 072.0 to 0.72.0 in release post's description 2aa7d7818 Update rss.md (#1104) c80677aeb Update quick-start.md (#1076) d04196bbd Minor spelling and capitalization fixes 837d2feba Fixed spelling mistake 67dc78e12 Update installing.md ce280c5d6 Update relurl.md bb4d0e703 Capitalization and Redirecting URL fixes e1fecada0 Update partials.md 1d99bb182 Typos and whitespacing issues fixed b20dba125 actually fix index function link this time f47d6f1e3 Fixing typos, whitespace issues and links dc82309b9 fix link to the index function 1eab0cbea add missing word (#1130) 9c3ee62ae more fixes e9bc5880a whitespace, typos and HTTPS fixes 93b806493 Add missing word to Module section 80ced9062 Display image on page bundles page. 727029b0a Update index.md 51fc48e4d Release 0.72.0 1ff68ac3b releaser: Add release notes to /docs for release of 0.72.0 f74a25b92 common/maps: Add Scratch.Values 2fd83db96 Add redirect support to the server bdfccf9f4 Fix typo in install instructions e12737ea6 Create SUPPORT.md git-subtree-dir: docs git-subtree-split: ac2c4a4871e90ddfb180f23704ce7ec9023529ca
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. |
Try as I might, I cannot figure out how to get hugo to stop making urls absolute, and use only relative urls. I've set:
in
config.toml
and removed the default baseurl directive. (The generated html files do not get a<base>
html tag.) But hugo continues to make all urls absolute:instead of a relative
If you need motivation (in case you ask "why are you doing this?"): many static website use cases cannot predict what url they will be hosted at, and MUST work with only relative urls. For example, a content addressed static host (say, using hash-trees to make the resulting hierarchy content addressed) would place the generated site at
<domain>/<base hash>/
. Obviously, the hugo site could know its hash a priori :)The text was updated successfully, but these errors were encountered: