diff --git a/src/fsdocs-tool/BuildCommand.fs b/src/fsdocs-tool/BuildCommand.fs index e00d4837..a903caa4 100644 --- a/src/fsdocs-tool/BuildCommand.fs +++ b/src/fsdocs-tool/BuildCommand.fs @@ -792,11 +792,11 @@ module Serve = let refreshEvent = FSharp.Control.Event() /// generate the script to inject into html to enable hot reload during development - let generateWatchScript (port: int) = - let tag = - """ + let generateWatchScript = + """ """ - tag.Replace("{{PORT}}", string port) - let connectedClients = ConcurrentDictionary() let socketHandler (webSocket: WebSocket) (context: HttpContext) = @@ -1406,10 +1404,13 @@ type CoreBuildOptions(watch) = // Adjust the user substitutions for 'watch' mode root let userRoot, userParameters = if watch then - let userRoot = sprintf "http://localhost:%d/" this.port_option + let userRoot = + match this.static_content_host_option with + | Some s -> sprintf "%O" s + | _ -> sprintf "http://localhost:%d/" this.port_option if userParametersDict.ContainsKey(ParamKeys.root) then - printfn "ignoring user-specified root since in watch mode, root = %s" userRoot + printfn "ignoring user-specified root since in watch mode, root = '%s'" userRoot let userParameters = [ ParamKeys.root, userRoot ] @@ -1667,7 +1668,7 @@ type CoreBuildOptions(watch) = let getLatestWatchScript () = if watch then // if running in watch mode, inject hot reload script - [ ParamKeys.``fsdocs-watch-script``, Serve.generateWatchScript this.port_option ] + [ ParamKeys.``fsdocs-watch-script``, Serve.generateWatchScript ] else // otherwise, inject empty replacement string [ ParamKeys.``fsdocs-watch-script``, "" ] @@ -2088,6 +2089,9 @@ type CoreBuildOptions(watch) = abstract port_option: int default x.port_option = 0 + abstract static_content_host_option: Uri option + default x.static_content_host_option = None + [] type BuildCommand() = inherit CoreBuildOptions(false) @@ -2115,3 +2119,15 @@ type WatchCommand() = [] member val port = 8901 with get, set + + [[:]' to use in static content for browsers not running on localhost.")>] + member val contenturlroot = "" with get, set + + override x.static_content_host_option = + if not (String.IsNullOrEmpty x.contenturlroot) then + x.contenturlroot |> Uri |> Some + else + None