Here is an idea:
If the GOOS is windows or darwin, when you run hugo server, it should open up the browser page immediately: http://localhost:1313/ using package: github.com/pkg/browser.
It should not do so after a live reload obviously.
https://github.com/gohugoio/hugo/blob/master/commands/server.go#L443
Should I submit a PR?
No, I don't think that is a good idea, but I'll leave this issue open if others want to chime in.
the idea was to address something that always annoyed me (minor irritation). I only see positives and no negatives.
What about a new flag that opens the browser up?
I quite like this idea, but it should be an opt-in feature, and not happen by default. Assuming it's smart enough to just open a new tab in an existing browser rather than forcefully spawning a new one.
Side note: Is there a reason this can't be done on the other supported platforms too?
I agree with the orange colored one. If this was done at all, should be opt-in. I don't like the idea of a new tab opening automatically.
I would assume then a hugo serve flag.
Give me a flag name and I'll make a PR
Well I use GitHub's hub CLI a lot and their command is hub browse to open a repository in the browser.
So I vote for a --browse flag.
hugo serve --browse would generate the site and open it up (localhost:1313 by default) in the browser.
browse is a bit ambiguous. It could mean browse files or browse website.
I think browser is better.
hugo server -D --browser
it's 1 extra letter plus a bit more self-explanatory in what it does.
Sounds good to me.
Give me a flag name and I'll make a PR
As I said, I'm currently not merging such a feature. I'm not convinced that this is worth it; note that adding code to Hugo isn't just about ... adding it; I assume you need a dependency or two which adds work later in the build chain, and the code/tests needs to be maintained by someone.
No, I don't think that is a good idea, but I'll leave this issue open if others want to chime in.
@bep please close the issue. don't waste anyone's time keeping it open under the pretence that it is in theory possible to flip your opinion on the matter.
Having said that, thank you for your amazing product. It's the best static site generator out there in my honest opinion.
Gatsby and plenty of other generators do this. Its so simple that I have no idea why you wouldn't add it.
Hi.
Thats probably not going to change your opinion @bep but personally I would find this feature useful too. I come from a JavaScript / Node.js space, and majority of the server tools implement this feature under the optional --open flag. Would be cool to see that as part of a hugo one day.
Thanks for building an amazing product!
Most helpful comment
browseis a bit ambiguous. It could mean browse files or browse website.I think
browseris better.hugo server -D --browserit's 1 extra letter plus a bit more self-explanatory in what it does.