Skip to content
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 #1139

Closed
wants to merge 1 commit into from

Conversation

bep
Copy link
Member

@bep bep commented May 13, 2015

Add support for URLs relative to context root

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 #1104
Fixes #622

@bep
Copy link
Member Author

bep commented May 13, 2015

@spf13 - what's your thoughts on this one? It is an important use case. One could argue that this should be done at render time, but there is a wormhole of challenges (mainly due to the render once, use twice) with that approach. And the performance penalty from this one is the same as for canonifyUrls.

@bep bep force-pushed the relurls branch 4 times, most recently from c7ec4e6 to f25527c Compare May 14, 2015 21:19
@spf13
Copy link
Contributor

spf13 commented May 15, 2015

I think it's a nice addition and there's a solid use case for making the site portable. Since the performance impact isn't much I'd say this is solid. LGTM.

@bep
Copy link
Member Author

bep commented May 15, 2015

Good, I'll pull it in, i just have to test a site build on a windows box first.

@bep bep force-pushed the relurls branch 4 times, most recently from c3b3c95 to aba04f3 Compare May 15, 2015 21:48
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
@bep
Copy link
Member Author

bep commented May 15, 2015

Merged in beaa8b1

@bep bep closed this May 15, 2015
@bep bep deleted the relurls branch April 18, 2017 09:19
bep added a commit that referenced this pull request Nov 3, 2020
57c1d1a67 Add note about issue with Instagram shortcode
2a4355113 Add example for regional language tags (#1139)
5e9a60fc0 Format dates with "th", "nd", and "rd". (#1254)
43df9a7f6 Update index.md
f15f32590 Update index.md
5a15be93d Update configuration.md
e71c1c545 Update configuration.md
5fd0439ff Release Hugo 0.77.0
5b875477c releaser: Add release notes to /docs for release of 0.77.0
09a2a3199 docs: Regen docs helper
bebef9bbe Merge commit '9cabb46f68bae01aeb1859727dcb21e8a10f5ec7'
f5ed02685 tpl: Refactor time.AsTime location implementation
f3b8eccd2 tpl: Update Hugo time to support optional [LOCATION] parameter

git-subtree-dir: docs
git-subtree-split: 57c1d1a67b9da5ba8ad5151d464f3fd7a21a24d8
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 14, 2022
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for URLs relative to context root Static Local Website with Hugo (file:///)
2 participants