Export a local portable site with all relative links

New to Hugo but have built a small site that is actually documentation for a Wordpress site. I was hoping that I could then export this into a local folder that I could send to the client as a local site they can use in their browser alongside the Wordpress site.

So, I need the Hugo site to be completely location agnostic and have all internal links relative to the root folder, wherever it ends up on the clients computer. I’ve tried removing/editing baseURL, but I’m pretty confused - could anyone give me a shove in the right direction? Thanks.

I wonder if baseURL would accept a file:// path.

The setting canonifyurls is also something to look into: http://gohugo.io/extras/urls/

You might also look into: <base href="{{ .Site.BaseUrl }}/"> in <head>. I’ve not tried this, but it might be a way to specify.

I’m a newbie to Hugo, but one thing I know is, right now there are a few URL-related discussions & tweaks going on, in the development version of Hugo. FYI.

This isn’t currently possible, me thinks – there are several related issues on GitHub, like this one:

Thanks for the replies - I’ll have a look into canonifyurls and what you’ve suggested RickCogley. I suspect that as I’m only running half a dozen pages I’ll end up just exporting the site and then editing the internal links for now. I know that is weak, but I haven’t really got my head round Hugo yet and I just need this to work.

bjornerik - its a shame if its not possible. Whilst I can understand that Hugo has a lot of power in building large static sites, for me it also seems like a perfect solution for quickly creating documentation. At the same time, I understand that creating a website full of relative links isn’t normally that useful - I should probably look at hosting it in a subdomain of the Wordpress site.

I wouldn’t call it “a shame”.

But it would cool if someone added that feature – it is an open source project, so all is welcome to chime in. I build the things I need, others build the things they need. In total it gets good.

I believe the fastest way to get fully relative links is to do something similar to what the canonifyUrls feature i doing today.

1 Like

I think the baseURL = baseurl = "file:////home/... approach could work out. But it demands some disipline:

  1. Set baseUrl using the file: syntax. I guess this will not solve the “relative problem” …

CanonifyUrls = "true"
uglyurls = "true"
And a permalink setting that creates *.html files:
post = “/:year/:month/:day/:slug.html”

  1. NEVER use {{ .BaseURL }}/somepath or {{ .Permalink }} to construct your URLs in the templates.

Cool, thanks for the input, I will give it a go :slight_smile:
Also, I don’t mean to come across as moaning/ungrateful - I’m really not! - I’d definitely chime in if I had any semblance of the skills required. Really appreciate the tools that are here and your help in understanding them a bit more, so thank you.

No problem. Your thoughts made me think a little about the problem; and I think I maybe have a doable solution to this in mind… When I get the time …

I think I have figured a “cheap” way to do this … cheap as in few code lines and fast execution.


It’s a little rough around the edges (missing test cases etc.), but I will wrap it up tomorrow.

If you know how to build from a branch, please take it for a spin and tell me how it works for you (Windows user esp. welcome).

Thanks for putting this together - I really appreciate your time. Unfortunately, I think I am too much of a luddite to take advantage of it - I’m not proficient with Git at all, but I think I’ve got that branch installed locally now. However, I’m not confident in what’s running or what results I’m looking for, so I can’t give you any decent feedback I’m afraid (and that’s having spent the past 2.5 hours tinkering with it all). Sorry :frowning:

No problem. It should be pretty straight-forward to use once it’s out.

It’s merged into Hugo master now and will be part of the upcoming release (my guesstimate a release in the next week or so).