Today I Learn

Today I Learn

Snippets, Tips, Links

28 Aug 2020

Hugo |> Dev Server Open Browser

Why hugo dev server can’t open browser tab automatically?

Modify hugo source code will definitely solve this issue.

Or we can use two simpler ways:

  • use some programe to run command hugo server and open_browser in parallel

  • use simple command sleep

Here is the second way on macOS: (open command only works on macOS)

#!/bin/bash

LOCAL_URL=http://localhost:1313

run_after () {
  duration=${1:-3}
  sleep $duration
  echo 'After '$duration
  # change open command to proper one
  open --new -a "Google Chrome" --args $LOCAL_URL
}

run_after 1 &
hugo server

Reference: