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

Static Local Website with Hugo (file:///) #622

Closed
JeremyBYU opened this issue Nov 8, 2014 · 12 comments
Closed

Static Local Website with Hugo (file:///) #622

JeremyBYU opened this issue Nov 8, 2014 · 12 comments
Assignees
Milestone

Comments

@JeremyBYU
Copy link

Hey everyone,
This question will probably seem a little strange to most people because most people dont deploy websites by distributing a folder of html files. However I sometimes do this at work (with a network file share) instead of having to deal with a server.

What I'm trying to do is create a website with hugo that will build all my html files for a simple website and be able to open the html files with a browser. To accomplish this I set baseurl = path_to_file_share. It correctly links all resources in the html files (css, images, javascripts). I open the index.html homepage file in the file share and it loads correctly. However all the link to other posts are broken and are replaced with <a href="#ZgotmplZ">

A little googling brought me to this page which basically says that Go is considering the html to be unsafe and is escaping it. I'm guessing it is the file protocol in the link that it is considering to be unsafe (e.g. file:///).

I know that there are some ways in the Go templating language to disable this functionality (see link). Is there any way we can put a flag in hugo (maybe the config.toml) that will inactivate this html escaping feature.

Thanks for your help

Jeremy

@rickb777
Copy link

This is an interesting question, but there is an alternative solution. If it were possible to generate all the content using only relative URLs, then it would not matter whether you had a file: scheme or a http: scheme, or even https:.

I tried setting baseurl to "", but this doesn't help you (not at the moment, at least). It sets all the intra-content URLs to start with /, which is OK on a webserver, but rubbish for your use-case. I had hoped that not a single intra-content URL would start with /; that is the acceptance criterion for a portable bundle of content.

I would wholeheartedly support a change to Hugo that generates content with nothing but relative URLs. It should be quite easy to achieve in principle - Hugo knows where everything is. This would be a more general solution to your use-case than merely making file: scheme play nicely.

Rick

@rickb777
Copy link

I've discovered that setting baseurl to "" creates a website with some broken menu links :-(

Hugo cannot deal with this use-case at present, as far as I can tell.

@JeremyBYU
Copy link
Author

Yeah I had noticed that as well. It would be great if we could get the relative references working with setting the basurl to "".

@JeremyBYU
Copy link
Author

I created a VBS script that will automatically make all links created by hugo relative. This works for anchor tags to other posts as well as links to static files (css, js, img). Place the file in the parent directory of the 'public' directory.
Plan to convert it to python on some later date.
Known issues:

  • configured website url cant be blank
  • the configured website url has to have a trailing backslash /
'relative-reference.vbs
'specifiy the website in config.toml as a command parameter when calling this vbs script.  Make sure there is ending / on website
Const ForReading = 1, ForWriting = 2, ForAppending = 8

pub_dir = "public"
levelPaths = Array("","../","../../","../../../") '4 level for relative reference'

'Command line argument for websitre url'
if WScript.Arguments.Count = 0 then
    badPath = "http://localhost:1318/"
else
    badPath = WScript.Arguments(0)
end if

'File system object for file manipulation'
Set objFSO = CreateObject("Scripting.FileSystemObject")
objStartFolder =  objFSO.GetAbsolutePathName(".") & "/" & pub_dir

ShowSubfolders objFSO.GetFolder(objStartFolder), 0 'Start off in the public directory, level 0'

Sub ShowSubFolders(Folder, level)
    Set colFiles = Folder.Files
    For Each objFile in colFiles
        if isHTML(objFile.Path) then 'check if file is HTML'
            localize objFile,level 'make local references in file'
        end if
    Next
    For Each Subfolder in Folder.SubFolders
        'Wscript.Echo Subfolder.Path
        Set objFolder = objFSO.GetFolder(Subfolder.Path)
        ShowSubFolders Subfolder, level +1 'Recursive call, increment the level'
    Next
End Sub

Sub localize(file, level)
    'Wscript.echo "test"
    'create object file for reading, this is the HTML file hugo created'
    set myFile = objFSO.OpenTextFile(file.Path,ForReading,True) 

    newFile = myFile.ReadAll 'read the html file and store as stirng'
    myFile.Close 'close the file'

    'THe following uses regular expressions to find a match for links to other posts (<a href)'
    Dim regEx 'Regular Expression object'
    Dim colMatches 'will contain matches for links'

    ' Create regular expression.
    Set regEx = New RegExp
    regEx.Pattern = badPath & "(.*?"")" 'regular expression that captures website url and internal link inside
    regEx.IgnoreCase = True
    regEx.global = true

    Set colMatches = regEx.Execute(newFile)   ' Execute search.
    For Each objMatch In colMatches   ' Iterate Matches collection.
    fullMatch = objMatch.Value 'This is the full match, includes the full  tag'
    subMatch = objMatch.SubMatches(0) 'This is the link inside of the tag'
    replaceMatch = replace(fullMatch,badPath,levelPaths(level)) 'puts relative reference inside the tag'

    if(isFile(subMatch)) then 'Checks if this rerference is to a css/js/html file'
      newFile = replace(newFile,fullMatch,replaceMatch)
    elseif right(subMatch,2) = "/""" then 'check if there is an ending /, if not then add it with index.html'     
         newFile = Replace(newFile,fullMatch, left(replaceMatch,len(replaceMatch)-1) & "index.html""")
      else 'There is no ending / so you must add it here'  
         newFile = Replace(newFile,fullMatch, left(replaceMatch,len(replaceMatch)-1) & "/index.html""")
    end if
    Next
    'Take care of home page references'
    bad_index = "href=""" & badPath
    good_index = "href=""" & levelPaths(level) & "index.html"
    newFile = replace(newFile,left(bad_index,len(bad_index)-1),good_index)  

    set myFile = objFSO.OpenTextFile(file.Path,ForWriting,True) 
    myFile.Write newFile 'write the html file
    myFile.Close
end Sub
Function isHTML (file)
    if right(file,4) = "html" then
        isHTML = True
    else 
        isHTML = false
    end if
End Function
Function isFile(myString)
  Dim regEx, retVal

  ' Create regular expression.
  Set regEx = New RegExp
  regEx.Pattern = ".*\.[a-zA-Z]{2,4}"
  regEx.IgnoreCase = False

  isFile = regEx.Test(myString)


end Function

@rickb777
Copy link

This is a noble effort, but...

It would be good to fix the Hugo source code and submit a patch, instead of trying to fix links after they've been created.

@anthonyfok
Copy link
Member

Hi @JeremyBYU and @rickb777,

It turns out this issue is very similar to #347 where the user wanted to use irc:// links that got turned into #ZgotmplZ. This was fixed by the addition of the safeUrl template function in commit 724cc0d on 19 Jan 2015, now in v0.13-DEV. This new feature is documented around http://gohugo.io/templates/functions/#toc_12 (scroll down a bit to see it).

So, @JeremyBYU, with Hugo v0.13-DEV, you may now use a baseurl = "file:///path/to/your/website/" with uglyurls = true and have the links work by modifying your templates to use, for example, <a href="{{ .Permalink | safeUrl }}> rather than <a href="{{ .Permalink }}">.

Please let us know how it works out for you!

anthonyfok referenced this issue in anthonyfok/hugo Feb 16, 2015
Temporary workaround for the bug fix and resulting
behavioral change in purell.NormalizeURLString():
a leading '/' was inadvertently to relative links,
but no longer, see gohugoio#878.

I think the real solution is to allow Hugo to
make relative URL with relative path,
e.g. "../../post/hello-again/", as wished by users
in issues #157, #622, etc., without forcing
relative URLs to begin with '/'.
Once the fixes are in, let's remove this kludge
and restore SanitizeUrl() to the way it was.

Fixes gohugoio#878
anthonyfok added a commit that referenced this issue Feb 18, 2015
Temporary workaround for the bug fix and resulting
behavioral change in purell.NormalizeURLString():
a leading '/' was inadvertently to relative links,
but no longer, see #878.

I think the real solution is to allow Hugo to
make relative URL with relative path,
e.g. "../../post/hello-again/", as wished by users
in issues #157, #622, etc., without forcing
relative URLs to begin with '/'.
Once the fixes are in, let's remove this kludge
and restore SanitizeUrl() to the way it was.

Fixes #878
@rickb777
Copy link

This safeUrl solution seems like an ugly hack.

Why is it not possible to construct path-relative URLs so that safeUrl is not necessary?

@anthonyfok
Copy link
Member

Hi @rickb777,

I think having a way to construct path-relative URLs is a worthy goal for v0.14 or v0.15.
I took a brief look at it some weeks ago, and thought we could implement something very similar to http://golang.org/pkg/path/filepath/#Rel, but for URL rather than file names. But I was soon busy and haven't had time to follow up yet. (I am still a Go learner.)

I agree that using safeUrl was an ugly hack; I was merely responding to the <a href="#ZgotmplZ"> problem that @JeremyBYU reported in the original post. Though an ugly hack, it works™ for those who need it until proper relative URLs support is available in Hugo.

But yes, not only do we welcome comments and suggestions, we welcome Pull Requests even more! So, if you have time, we would love to receive a PR from you! 😉

@bep bep added this to the v0.14 milestone May 13, 2015
@bep bep self-assigned this May 13, 2015
bep added a commit to bep/hugo that referenced this issue May 13, 2015
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
bep added a commit to bep/hugo that referenced this issue May 13, 2015
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
bep added a commit to bep/hugo that referenced this issue May 14, 2015
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
bep added a commit to bep/hugo that referenced this issue May 14, 2015
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
bep added a commit to bep/hugo that referenced this issue May 14, 2015
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
bep added a commit to bep/hugo that referenced this issue May 14, 2015
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
bep added a commit to bep/hugo that referenced this issue May 15, 2015
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
bep added a commit to bep/hugo that referenced this issue May 15, 2015
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
bep added a commit to bep/hugo that referenced this issue May 15, 2015
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
bep added a commit to bep/hugo that referenced this issue May 15, 2015
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
bep added a commit to bep/hugo that referenced this issue May 15, 2015
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
bep added a commit to bep/hugo that referenced this issue May 15, 2015
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 bep closed this as completed in beaa8b1 May 15, 2015
tychoish pushed a commit to tychoish/hugo that referenced this issue Aug 13, 2017
Temporary workaround for the bug fix and resulting
behavioral change in purell.NormalizeURLString():
a leading '/' was inadvertently to relative links,
but no longer, see gohugoio#878.

I think the real solution is to allow Hugo to
make relative URL with relative path,
e.g. "../../post/hello-again/", as wished by users
in issues gohugoio#157, gohugoio#622, etc., without forcing
relative URLs to begin with '/'.
Once the fixes are in, let's remove this kludge
and restore SanitizeUrl() to the way it was.

Fixes gohugoio#878
tychoish pushed a commit to tychoish/hugo that referenced this issue Aug 13, 2017
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
@rgommers
Copy link

rgommers commented Apr 18, 2018

This question will probably seem a little strange to most people because most people dont deploy websites by distributing a folder of html files. However I sometimes do this at work (with a network file share) instead of having to deal with a server.

This is not that uncommon actually. Another use case is letting users download a html site (e.g. docs for a software project) as a bundle to use offline.

This issue was closed, but the behavior is still not supported (nor documented as far as I can tell). Using something like:

baseURL = "file:///path/to/networkfolder/doc/public/"

will not result in a working site whether RelativeURLs is set to true or false. If true, themes go missing completely, hugo server doesn't work (it changes localhost:1313 to localhost:1313/path/...), etc.

Can this issue be reopened, or closed as wontfix?

@rgommers
Copy link

Update: after a couple of hours of digging I found the answer: relativeURLs = "true" only works in combination with uglyURLs = "true". See #4642 (comment) for more details.

So no need to reopen this. I will see if I can find time for a PR to improve the Hugo docs - searching for terms like "portable", "offline", "deploying to a shared drive", etc. should lead users to a description of this behavior.

@inwardmovement
Copy link

inwardmovement commented Jul 4, 2019

I tried:

  1. Do not set baseURL
  2. Set relativeURLs = "true"
  3. Set uglyURLs = "true"

But it doesn't work for me.

Couldn't we simply create a hugo parameter to build "for local" while taking care of all these "not for local" problems, while not depending on baseURL, relativeURLs, uglyURLs, canonifyURLs (and so on)? hugo --local for example.

@github-actions
Copy link

github-actions bot commented Feb 2, 2022

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.

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

Successfully merging a pull request may close this issue.

7 participants
@rgommers @bep @anthonyfok @rickb777 @JeremyBYU @inwardmovement and others