[ doc, build_docs ] Optionally bind to global wan when previewing
This commit adds an additional --bind-wan argument to build_docs.py.
This forces the hugo server to bind the http server to a port on the
global interface (as opposed to just on localhost, which is the default).
This is important when using hugo on build farms with older (or no) browser
support, and no support for ssh tunnelling.
For testing other options, there is also a --hugo-opts flag for passing
arguments into hugo directly.
Signed-off-by: Martin Lueker-Boden <martin.lueker-boden@wdc.com>
diff --git a/util/build_docs.py b/util/build_docs.py
index 5ecadd2..090caf3 100755
--- a/util/build_docs.py
+++ b/util/build_docs.py
@@ -18,6 +18,7 @@
import subprocess
import sys
import textwrap
+import socket
from pathlib import Path
import check_tool_requirements
@@ -405,7 +406,7 @@
return hugo_bin_path
-def invoke_hugo(preview, hugo_bin_path):
+def invoke_hugo(preview, bind_wan, hugo_opts, hugo_bin_path):
site_docs = SRCTREE_TOP.joinpath('site', 'docs')
config_file = str(site_docs.joinpath('config.toml'))
layout_dir = str(site_docs.joinpath('layouts'))
@@ -422,6 +423,12 @@
]
if preview:
args += ["server"]
+ # --bind-wan only applies when previewing.
+ if bind_wan:
+ args += ["--bind", "0.0.0.0", "--baseURL", "http://"+socket.getfqdn()]
+ if hugo_opts != None:
+ args += hugo_opts
+
subprocess.run(args, check=True, cwd=str(SRCTREE_TOP))
@@ -441,10 +448,22 @@
changes in the documentation files). This feature is intended
to preview the documentation locally.""")
parser.add_argument(
+ '--bind-wan',
+ action='store_true',
+ help="""When previewing, bind to all interfaces (instead of just
+ localhost). This makes the documentation preview visible from
+ other hosts.""")
+ parser.add_argument(
'--force-global',
action='store_true',
help="""Use a global installation of Hugo. This skips the version
check and relies on Hugo to be available from the environment.""")
+ parser.add_argument(
+ '--hugo-opts',
+ nargs=argparse.REMAINDER,
+ help="""Indicates that all following arguments should be passed as
+ additional options to hugo. This may be useful for controlling
+ server bindings and so forth.""")
parser.add_argument('--hugo', help="""TODO""")
args = parser.parse_args()
@@ -469,7 +488,7 @@
pass
try:
- invoke_hugo(args.preview, hugo_bin_path)
+ invoke_hugo(args.preview, args.bind_wan, args.hugo_opts, hugo_bin_path)
except subprocess.CalledProcessError:
sys.exit("Error building site")
except PermissionError: