how to run a site locally & on server

626 views
Skip to first unread message

Kevin Burke

unread,
Jul 28, 2014, 4:19:30 PM7/28/14
to hugo-d...@googlegroups.com
I want to view my static site locally (on my own machine) and then deploy it to a server (where it's accessible by visiting somedomain.com/blog

Sadly the baseUrl parameter makes this difficult - for your CSS/JS, either you generate localhost URL's or you generate somedomain.com URL's, you can't have both. This leaves you with a few options

- leave config.json out of source code, and use different ones for local/prod

- don't check the public folder into source (requires a build step in each different environment)

- build into 2 separate directories, one for local and one for production (okay, files are cheap, but this doubles the build time)

- fix baseUrl to allow relative URL's, or I suppose write my own theme that loads JS relative to the root (eg <script src="/js/foobar.js")

Thoughts? Has anyone else run into this I checked "Using Hugo" and most of the other material on the site but didn't see anything about this problem.

Phil Pennock

unread,
Jul 28, 2014, 5:11:49 PM7/28/14
to Kevin Burke, hugo-d...@googlegroups.com
On 2014-07-28 at 13:19 -0700, Kevin Burke wrote:
> I want to view my static site locally (on my own machine) and then deploy
> it to a server (where it's accessible by visiting somedomain.com/blog)
>
> Sadly the baseUrl parameter makes this difficult - for your CSS/JS, either
> you generate localhost URL's or you generate somedomain.com URL's, you
> can't have both. This leaves you with a few options

> - fix baseUrl to allow relative URL's, or I suppose write my own theme that
> loads JS relative to the root (eg <script src="/js/foobar.js")
>
> Thoughts? Has anyone else run into this I checked "Using Hugo" and most of
> the other material on the site but didn't see anything about this problem.

You're after "canonifyurls: false". Included in Hugo releases since
v0.10 -- documented at <http://hugo.spf13.com/extras/urls>

Introduced in
<https://github.com/spf13/hugo/commit/438c2198923022a3e4d299b06a7df18268041dd8>

Regards,
--
My employer, Apcera Inc, is hiring sysadmin; primarily San Francisco:
http://www.apcera.com/jobs/#operations-engineer
(but all the mistakes in this email are made in my personal capacity)

David Kebler

unread,
Jul 30, 2014, 12:44:34 PM7/30/14
to hugo-d...@googlegroups.com
Phil's solution is fine but still I've been thinking that a "switch" on the hugo command line for development or production would be a nice feature.
It could for example trigger using an alternative config file which would allow absolute baseurls for either.   For example I recall(?) the output directory can be specified in the config file so one could send development to "public" and production to "site-pro".   Then it's easy enough to sync the production folder to wherever.   Could be other things hugo could do based on this switch than just choose alternative config files.

Kevin Burke

unread,
Jul 30, 2014, 4:08:22 PM7/30/14
to hugo-d...@googlegroups.com
Using 0.12 dev and the hyde theme, whether I set 

canonifyurls = true

or 

canonifyurls = false

The CSS URL's in themes/hyde/layout/_partials/head.html (the ones I care about) are still being rendered with the full base URL.


On Monday, July 28, 2014 1:19:30 PM UTC-7, Kevin Burke wrote:

Phil Pennock

unread,
Jul 30, 2014, 4:56:03 PM7/30/14
to Kevin Burke, hugo-d...@googlegroups.com
On 2014-07-30 at 13:08 -0700, Kevin Burke wrote:
> Using 0.12 dev and the hyde theme, whether I set
>
> canonifyurls = true
>
> or
>
> canonifyurls = false
>
> The CSS URL's in themes/hyde/layout/_partials/head.html (the ones I care
> about) are still being rendered with the full base URL.

The content there is explicitly inserting `{{ .Site.BaseUrl }}` as part
of the URL. So the data present isn't coming from canonification but by
being explicitly inserted.

Edit the theme, change the URL source to be something relative. In
combination with setting canonifyurls to false, that should work.

Steve Francia

unread,
Jul 30, 2014, 4:58:01 PM7/30/14
to David Kebler, hugo-d...@googlegroups.com
I've been thinking more about adding some workflows in this vein.

something like...
hugo dev -> hugo server --watch --config dev.yaml
hugo prod -> hugo --config prod.yaml

then eventually

hugo deploy

--
Hugo
 
A Fast and Flexible Static Site Generator built with love by spf13 and friends in Go
 
Download the latest at https://github.com/spf13/hugo/releases
---
You received this message because you are subscribed to the Google Groups "Hugo Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hugo-discuss...@googlegroups.com.
To post to this group, send email to hugo-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/hugo-discuss.
For more options, visit https://groups.google.com/d/optout.

Adrian Simmons

unread,
Sep 2, 2014, 7:59:46 AM9/2/14
to hugo-d...@googlegroups.com, d...@kebler.net
Hello,

just started my first hugo site build today having discovered Hugo yesterday – and one of my first thoughts is exactly around workflow.


On Wednesday, 30 July 2014 21:58:01 UTC+1, Steve Francia wrote:
hugo dev -> hugo server --watch --config dev.yaml
hugo prod -> hugo --config prod.yaml

I think personally I'd prefer to have a single config.toml and list alternative config options within it. Then a command line flag would prompt hugo to use the alternative option and 'hugo server --config dev' or 'hugo server --config stage' could simply output to a different directory.

For the moment I'm planning on using git, obviously keeping the src files in git (isn't everyone?) – a different branch for each destination with the config options set appropriately. Does that sound workable?

Nate Finch

unread,
Sep 11, 2014, 2:32:54 PM9/11/14
to hugo-d...@googlegroups.com, d...@kebler.net
So, what differences do you want in the config for local vs. production?  I've been thinking about similar things, and to that end I made a pull request that would let templates access the state of the BuildDrafts flag, for pretty much this purpose (do something different locally).

Adrian Simmons

unread,
Sep 15, 2014, 11:52:26 AM9/15/14
to hugo-d...@googlegroups.com, d...@kebler.net
On Thursday, 11 September 2014 19:32:54 UTC+1, Nate Finch wrote:
So, what differences do you want in the config for local vs. production?

At about 10% into my first site build with Hugo I'm probably not qualified to comment...
The most obvious things would be those that relate to the server environment. Output destination, base url etc. 

Nate Finch

unread,
Sep 15, 2014, 12:14:20 PM9/15/14
to Adrian Simmons, hugo-d...@googlegroups.com, d...@kebler.net
so, base url gets modified to localhost automatically when you run the local server, so like, if your normal base url is http://foo.com/bar/baz/  the local server will run with the baseurl as localhost:1313/bar/baz/  (but it'll still serve files from the public folder under your root site folder).  

The way I do it is that I have a symlink in my hugo folder called production, which links to the real folder where I want the output to go.  Then, when I want to output the real site for production use, I do hugo -d production (-d sets the output destination) which is nice and explicit, and only gets done once I'm satisfied with the way things look from the local server. Without using -d production, hugo outputs to the "public" folder, which I view as a disposable scratch pad just for the local server.

There is now support in the trunk code for your templates etc to check the value of BuildDrafts, which can be used as a way to turn on and off a sort of debugging mode... showing things that shouldn't normally be shown on the production site (that's the point of drafts, they don't normally get generated except while you're still working on things locally).  Not sure if that would suit your purpose.



--
Reply all
Reply to author
Forward
0 new messages