Add --name-url option (#884)

Turns the server name into a hyperlink to a spefified URL

Can link back to homepage with `--name-url=/`, controlpanel with
`name-url="/?h"`, or external sites with `name-url="https://foo.bar/"`
This commit is contained in:
Lulu 2025-10-04 11:10:48 +01:00 committed by GitHub
parent e9b6e645d3
commit 38cc809822
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 9 additions and 1 deletions

View file

@ -1155,6 +1155,7 @@ def add_general(ap, nc, srvname):
ap2.add_argument("--urlform", metavar="MODE", type=u, default="print,xm", help="how to handle url-form POSTs; see \033[33m--help-urlform\033[0m")
ap2.add_argument("--wintitle", metavar="TXT", type=u, default="cpp @ $pub", help="server terminal title, for example [\033[32m$ip-10.1.2.\033[0m] or [\033[32m$ip-]")
ap2.add_argument("--name", metavar="TXT", type=u, default=srvname, help="server name (displayed topleft in browser and in mDNS)")
ap2.add_argument("--name-url", metavar="TXT", type=u, help="URL for server name hyperlink (displayed topleft in browser)")
ap2.add_argument("--mime", metavar="EXT=MIME", type=u, action="append", help="\033[34mREPEATABLE:\033[0m map file \033[33mEXT\033[0mension to \033[33mMIME\033[0mtype, for example [\033[32mjpg=image/jpeg\033[0m]")
ap2.add_argument("--mimes", action="store_true", help="list default mimetype mapping and exit")
ap2.add_argument("--rmagic", action="store_true", help="do expensive analysis to improve accuracy of returned mimetypes; will make file-downloads, rss, and webdav slower (volflag=rmagic)")

View file

@ -6493,7 +6493,11 @@ class HttpCli(object):
try:
if not self.args.nih:
srv_info.append(self.args.name)
if self.args.name_url:
url = html_escape(self.args.name_url, True, True)
srv_info.append(f"<a href='{url}'>{self.args.name}</a>")
else:
srv_info.append(self.args.name)
except:
self.log("#wow #whoa")

View file

@ -887,6 +887,9 @@ html.y #path a:hover {
#srv_info2 span {
color: var(--srv-1);
}
#srv_info2 a {
padding: 0;
}
#srv_info2 {
display: none;
}