Skip to content

Commit

Permalink
Fix #3166 — make auto/serve URL clickable
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Sep 27, 2018
1 parent 1caf3a9 commit f58ba9a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Expand Up @@ -4,6 +4,9 @@ New in master
Features
--------

* Make URL displayed by ``nikola auto`` and ``nikola serve`` clickable
(Issue #3166)

Bugfixes
--------

Expand Down
12 changes: 6 additions & 6 deletions nikola/plugins/command/auto/__init__.py
Expand Up @@ -238,13 +238,13 @@ def _execute(self, options, args):

host, port = srv.sockets[0].getsockname()

self.logger.info("Serving HTTP on {0} port {1}...".format(host, port))
if browser:
if options['ipv6'] or '::' in host:
server_url = "http://[{0}]:{1}/".format(host, port)
else:
server_url = "http://{0}:{1}/".format(host, port)
if options['ipv6'] or '::' in host:
server_url = "http://[{0}]:{1}/".format(host, port)
else:
server_url = "http://{0}:{1}/".format(host, port)
self.logger.info("Serving on {0} ...".format(server_url))

if browser:
self.logger.info("Opening {0} in the default web browser...".format(server_url))
webbrowser.open('http://{0}:{1}'.format(host, port))

Expand Down
15 changes: 8 additions & 7 deletions nikola/plugins/command/serve.py
Expand Up @@ -139,14 +139,15 @@ def _execute(self, options, args):
httpd = OurHTTP((options['address'], options['port']),
OurHTTPRequestHandler)
sa = httpd.socket.getsockname()
self.logger.info("Serving HTTP on {0} port {1}...".format(*sa))
if ipv6:
server_url = "http://[{0}]:{1}/".format(*sa)
elif sa[0] == '0.0.0.0':
server_url = "http://127.0.0.1:{1}/".format(*sa)
else:
server_url = "http://{0}:{1}/".format(*sa)
self.logger.info("Serving on {0} ...".format(server_url))

if options['browser']:
if ipv6:
server_url = "http://[{0}]:{1}/".format(*sa)
elif sa[0] == '0.0.0.0':
server_url = "http://127.0.0.1:{1}/".format(*sa)
else:
server_url = "http://{0}:{1}/".format(*sa)
self.logger.info("Opening {0} in the default web browser...".format(server_url))
webbrowser.open(server_url)
if options['detach']:
Expand Down

0 comments on commit f58ba9a

Please sign in to comment.