docs/server: open browser using xdg-open

This commit is contained in:
Matt Sturgeon 2025-05-21 17:40:17 +01:00
parent 601d4309ed
commit 1ff5e1a33b
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299
2 changed files with 5 additions and 1 deletions

View file

@ -3,6 +3,7 @@
runCommand,
makeBinaryWrapper,
python3,
xdg-utils,
docs,
}:
runCommand "serve-docs"
@ -15,5 +16,6 @@ runCommand "serve-docs"
makeWrapper ${lib.getExe python3} \
$out/bin/server \
--add-flags ${./server.py} \
--chdir ${docs}
--chdir ${docs} \
--prefix PATH : ${lib.makeBinPath [ xdg-utils ]}
''

View file

@ -1,4 +1,5 @@
from http.server import HTTPServer, SimpleHTTPRequestHandler
from subprocess import call
PORT = 8000
URL = f"http://localhost:{PORT}"
@ -8,6 +9,7 @@ class AutoBrowseHTTPServer(HTTPServer):
def server_activate(self):
HTTPServer.server_activate(self)
print(f"Serving documentation at {URL}")
call(["xdg-open", URL])
class UncachedHTTPHandler(SimpleHTTPRequestHandler):