option to specify favicon + default-enable it

This commit is contained in:
ed 2022-07-05 00:06:22 +02:00
parent 36365ffa6b
commit dded4fca76
8 changed files with 47 additions and 20 deletions

View file

@ -311,7 +311,7 @@ def disable_quickedit() -> None:
cmode(True, mode | 4) cmode(True, mode | 4)
def run_argparse(argv: list[str], formatter: Any) -> argparse.Namespace: def run_argparse(argv: list[str], formatter: Any, retry: bool) -> argparse.Namespace:
ap = argparse.ArgumentParser( ap = argparse.ArgumentParser(
formatter_class=formatter, formatter_class=formatter,
prog="copyparty", prog="copyparty",
@ -611,6 +611,7 @@ def run_argparse(argv: list[str], formatter: Any) -> argparse.Namespace:
ap2.add_argument("--lang", metavar="LANG", type=u, default="eng", help="language") ap2.add_argument("--lang", metavar="LANG", type=u, default="eng", help="language")
ap2.add_argument("--theme", metavar="NUM", type=int, default=0, help="default theme to use") ap2.add_argument("--theme", metavar="NUM", type=int, default=0, help="default theme to use")
ap2.add_argument("--themes", metavar="NUM", type=int, default=8, help="number of themes installed") ap2.add_argument("--themes", metavar="NUM", type=int, default=8, help="number of themes installed")
ap2.add_argument("--favico", metavar="TXT", type=u, default="c 000 none" if retry else "🎉 000 none", help="favicon text [ foreground [ background ] ], set blank to disable")
ap2.add_argument("--js-browser", metavar="L", type=u, help="URL to additional JS to include") ap2.add_argument("--js-browser", metavar="L", type=u, help="URL to additional JS to include")
ap2.add_argument("--css-browser", metavar="L", type=u, help="URL to additional CSS to include") ap2.add_argument("--css-browser", metavar="L", type=u, help="URL to additional CSS to include")
ap2.add_argument("--html-head", metavar="TXT", type=u, default="", help="text to append to the <head> of all HTML pages") ap2.add_argument("--html-head", metavar="TXT", type=u, default="", help="text to append to the <head> of all HTML pages")
@ -682,12 +683,14 @@ def main(argv: Optional[list[str]] = None) -> None:
except: except:
pass pass
for fmtr in [RiceFormatter, Dodge11874, BasicDodge11874]: retry = False
for fmtr in [RiceFormatter, RiceFormatter, Dodge11874, BasicDodge11874]:
try: try:
al = run_argparse(argv, fmtr) al = run_argparse(argv, fmtr, retry)
except SystemExit: except SystemExit:
raise raise
except: except:
retry = True
lprint("\n[ {} ]:\n{}\n".format(fmtr, min_ex())) lprint("\n[ {} ]:\n{}\n".format(fmtr, min_ex()))
assert al assert al

View file

@ -184,6 +184,8 @@ class HttpCli(object):
def j2s(self, name: str, **ka: Any) -> str: def j2s(self, name: str, **ka: Any) -> str:
tpl = self.conn.hsrv.j2[name] tpl = self.conn.hsrv.j2[name]
ka["ts"] = self.conn.hsrv.cachebuster() ka["ts"] = self.conn.hsrv.cachebuster()
ka["lang"] = self.args.lang
ka["favico"] = self.args.favico
ka["svcname"] = self.args.doctitle ka["svcname"] = self.args.doctitle
ka["html_head"] = self.html_head ka["html_head"] = self.html_head
return tpl.render(**ka) # type: ignore return tpl.render(**ka) # type: ignore
@ -1862,6 +1864,8 @@ class HttpCli(object):
"edit": "edit" in self.uparam, "edit": "edit" in self.uparam,
"title": html_escape(self.vpath, crlf=True), "title": html_escape(self.vpath, crlf=True),
"lastmod": int(ts_md * 1000), "lastmod": int(ts_md * 1000),
"lang": self.args.lang,
"favico": self.args.favico,
"have_emp": self.args.emp, "have_emp": self.args.emp,
"md_chk_rate": self.args.mcr, "md_chk_rate": self.args.mcr,
"md": boundary, "md": boundary,
@ -2406,7 +2410,6 @@ class HttpCli(object):
"readme": readme, "readme": readme,
"title": html_escape(self.vpath, crlf=True), "title": html_escape(self.vpath, crlf=True),
"srv_info": srv_infot, "srv_info": srv_infot,
"lang": self.args.lang,
"dtheme": self.args.theme, "dtheme": self.args.theme,
"themes": self.args.themes, "themes": self.args.themes,
"turbolvl": self.args.turbo, "turbolvl": self.args.turbo,

View file

@ -3,7 +3,7 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>⇆🎉 {{ title }}</title> <title>{{ title }}</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=0.8"> <meta name="viewport" content="width=device-width, initial-scale=0.8">
{{ html_head }} {{ html_head }}
@ -139,6 +139,7 @@
dtheme = "{{ dtheme }}", dtheme = "{{ dtheme }}",
srvinf = "{{ srv_info }}", srvinf = "{{ srv_info }}",
lang = "{{ lang }}", lang = "{{ lang }}",
dfavico = "{{ favico }}",
def_hcols = {{ def_hcols|tojson }}, def_hcols = {{ def_hcols|tojson }},
have_up2k_idx = {{ have_up2k_idx|tojson }}, have_up2k_idx = {{ have_up2k_idx|tojson }},
have_tags_idx = {{ have_tags_idx|tojson }}, have_tags_idx = {{ have_tags_idx|tojson }},

View file

@ -1,6 +1,6 @@
<!DOCTYPE html><html><head> <!DOCTYPE html><html><head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>📝🎉 {{ title }}</title> <title>📝 {{ title }}</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=0.7"> <meta name="viewport" content="width=device-width, initial-scale=0.7">
{{ html_head }} {{ html_head }}
@ -128,7 +128,8 @@ write markdown (most html is 🙆 too)
<script> <script>
var last_modified = {{ lastmod }}, var last_modified = {{ lastmod }},
have_emp = {{ have_emp|tojson }}; have_emp = {{ have_emp|tojson }},
dfavico = "{{ favico }}";
var md_opt = { var md_opt = {
link_md_as_html: false, link_md_as_html: false,

View file

@ -1,6 +1,6 @@
<!DOCTYPE html><html><head> <!DOCTYPE html><html><head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>📝🎉 {{ title }}</title> <title>📝 {{ title }}</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=0.7"> <meta name="viewport" content="width=device-width, initial-scale=0.7">
{{ html_head }} {{ html_head }}
@ -26,7 +26,8 @@
<script> <script>
var last_modified = {{ lastmod }}, var last_modified = {{ lastmod }},
have_emp = {{ have_emp|tojson }}; have_emp = {{ have_emp|tojson }},
dfavico = "{{ favico }}";
var md_opt = { var md_opt = {
link_md_as_html: false, link_md_as_html: false,

View file

@ -97,7 +97,9 @@
<a href="#" id="repl">π</a> <a href="#" id="repl">π</a>
<script> <script>
var lang="{{ this.args.lang }}"; var lang="{{ lang }}",
dfavico="{{ favico }}";
document.documentElement.className=localStorage.theme||"{{ this.args.theme }}"; document.documentElement.className=localStorage.theme||"{{ this.args.theme }}";
</script> </script>

View file

@ -2139,8 +2139,8 @@ favico.init();
ebi('ico1').onclick = function () { ebi('ico1').onclick = function () {
var a = favico.txt == this.textContent; var a = favico.txt == this.textContent;
swrite('icot', a ? 'c' : this.textContent); swrite('icot', a ? 'c' : this.textContent);
swrite('icof', a ? null : '000'); swrite('icof', a ? 'fc5' : '000');
swrite('icob', a ? null : ''); swrite('icob', a ? '222' : '');
favico.init(); favico.init();
}; };

View file

@ -1427,12 +1427,24 @@ var favico = (function () {
var b64; var b64;
try { try {
b64 = btoa(svg ? svg_decl + svg : gx(r.txt)); b64 = btoa(svg ? svg_decl + svg : gx(r.txt));
//console.log('f1');
} }
catch (ex) { catch (e1) {
b64 = encodeURIComponent(r.txt).replace(/%([0-9A-F]{2})/g, try {
function x(m, v) { return String.fromCharCode('0x' + v); }); b64 = btoa(gx(encodeURIComponent(r.txt).replace(/%([0-9A-F]{2})/g,
function x(m, v) { return String.fromCharCode('0x' + v); })));
//console.log('f2');
}
catch (e2) {
try {
b64 = btoa(gx(unescape(encodeURIComponent(r.txt)))); b64 = btoa(gx(unescape(encodeURIComponent(r.txt))));
//console.log('f3');
}
catch (e3) {
//console.log('fe');
return;
}
}
} }
if (!r.tag) { if (!r.tag) {
@ -1445,9 +1457,13 @@ var favico = (function () {
r.init = function () { r.init = function () {
clearTimeout(r.to); clearTimeout(r.to);
scfg_bind(r, 'txt', 'icot', '', r.upd); var dv = (window.dfavico || '').trim().split(/ +/),
scfg_bind(r, 'fg', 'icof', 'fc5', r.upd); fg = dv.length < 2 ? 'fc5' : dv[1].toLowerCase() == 'none' ? '' : dv[1],
scfg_bind(r, 'bg', 'icob', '222', r.upd); bg = dv.length < 3 ? '222' : dv[2].toLowerCase() == 'none' ? '' : dv[2];
scfg_bind(r, 'txt', 'icot', dv[0], r.upd);
scfg_bind(r, 'fg', 'icof', fg, r.upd);
scfg_bind(r, 'bg', 'icob', bg, r.upd);
r.upd(); r.upd();
}; };