make prism optional

This commit is contained in:
ed 2021-11-04 03:10:13 +01:00
parent 3899c7ad56
commit cb7674b091
7 changed files with 29 additions and 9 deletions

View file

@ -2281,6 +2281,9 @@ class HttpCli(object):
j2a["doc"] = doc j2a["doc"] = doc
if not self.conn.hsrv.prism:
j2a["no_prism"] = True
for d in dirs: for d in dirs:
d["name"] += "/" d["name"] += "/"
@ -2289,7 +2292,7 @@ class HttpCli(object):
j2a["files"] = dirs + files j2a["files"] = dirs + files
j2a["logues"] = logues j2a["logues"] = logues
j2a["taglist"] = taglist j2a["taglist"] = taglist
j2a["txt_ext"] = self.args.textfiles.replace(',', ' ') j2a["txt_ext"] = self.args.textfiles.replace(",", " ")
if "mth" in vn.flags: if "mth" in vn.flags:
j2a["def_hcols"] = vn.flags["mth"].split(",") j2a["def_hcols"] = vn.flags["mth"].split(",")

View file

@ -76,6 +76,7 @@ class HttpSrv(object):
x: env.get_template(x + ".html") x: env.get_template(x + ".html")
for x in ["splash", "browser", "browser2", "msg", "md", "mde"] for x in ["splash", "browser", "browser2", "msg", "md", "mde"]
} }
self.prism = os.path.exists(os.path.join(E.mod, "web", "deps", "prism.js.gz"))
cert_path = os.path.join(E.cfg, "cert.pem") cert_path = os.path.join(E.cfg, "cert.pem")
if bos.path.exists(cert_path): if bos.path.exists(cert_path):

View file

@ -142,6 +142,7 @@
have_unpost = {{ have_unpost|tojson }}, have_unpost = {{ have_unpost|tojson }},
have_zip = {{ have_zip|tojson }}, have_zip = {{ have_zip|tojson }},
txt_ext = "{{ txt_ext }}", txt_ext = "{{ txt_ext }}",
{% if no_prism %}no_prism = 1,{% endif %}
readme = {{ readme|tojson }}; readme = {{ readme|tojson }};
document.documentElement.setAttribute("class", localStorage.lightmode == 1 ? "light" : "dark"); document.documentElement.setAttribute("class", localStorage.lightmode == 1 ? "light" : "dark");

View file

@ -2336,6 +2336,9 @@ var showfile = (function () {
em = [r.sname(window.location.search), window.location.hash, em.textContent]; em = [r.sname(window.location.search), window.location.hash, em.textContent];
r.setstyle = function () { r.setstyle = function () {
if (window['no_prism'])
return;
qsr('#prism_css'); qsr('#prism_css');
var el = mknod('link'); var el = mknod('link');
el.rel = 'stylesheet'; el.rel = 'stylesheet';
@ -2438,12 +2441,14 @@ var showfile = (function () {
else { else {
el.textContent = txt; el.textContent = txt;
el.innerHTML = '<code>' + el.innerHTML + '</code>'; el.innerHTML = '<code>' + el.innerHTML + '</code>';
if (!window['no_prism']) {
el.setAttribute('class', 'prism linkable-line-numbers line-numbers language-' + lang); el.setAttribute('class', 'prism linkable-line-numbers line-numbers language-' + lang);
if (!defer) if (!defer)
fun(el.firstChild); fun(el.firstChild);
else else
import_js('/.cpr/deps/prism.js', function () { fun(); }); import_js('/.cpr/deps/prism.js', function () { fun(); });
} }
}
wr.appendChild(el); wr.appendChild(el);
wr.style.display = ''; wr.style.display = '';

View file

@ -29,7 +29,8 @@ set -e
# 259288 copyparty-extras/sfx-lite/copyparty-sfx.sh # 259288 copyparty-extras/sfx-lite/copyparty-sfx.sh
# 270004 copyparty-extras/sfx-lite/copyparty-sfx.py # 270004 copyparty-extras/sfx-lite/copyparty-sfx.py
# 293159 copyparty-extras/sfx-lite/copyparty-sfx-gz.py # 293159 copyparty-extras/sfx-lite/copyparty-sfx-gz.py
# `- also removed the codemirror markdown editor, # `- also removed the codemirror markdown editor
# and the text-viewer syntax hilighting,
# only essential features remaining # only essential features remaining
# #
# 646297 copyparty-extras/copyparty-1.0.14.tar.gz # 646297 copyparty-extras/copyparty-1.0.14.tar.gz
@ -141,8 +142,8 @@ repack() {
repack sfx-full "re gz no-sh" repack sfx-full "re gz no-sh"
repack sfx-ent "re no-dd no-ogv" repack sfx-ent "re no-dd no-ogv"
repack sfx-ent "re no-dd no-ogv gz no-sh" repack sfx-ent "re no-dd no-ogv gz no-sh"
repack sfx-lite "re no-dd no-ogv no-cm" repack sfx-lite "re no-dd no-ogv no-cm no-hl"
repack sfx-lite "re no-dd no-ogv no-cm gz no-sh" repack sfx-lite "re no-dd no-ogv no-cm no-hl gz no-sh"
# move fuse and up2k clients into copyparty-extras/, # move fuse and up2k clients into copyparty-extras/,

View file

@ -22,6 +22,8 @@ help() { exec cat <<'EOF'
# `no-cm` saves ~92k by removing easymde/codemirror # `no-cm` saves ~92k by removing easymde/codemirror
# (the fancy markdown editor) # (the fancy markdown editor)
# #
# `no-hl` saves ~41k by removing syntax hilighting in the text viewer
#
# `no-fnt` saves ~9k by removing the source-code-pro font # `no-fnt` saves ~9k by removing the source-code-pro font
# (browsers will try to use 'Consolas' instead) # (browsers will try to use 'Consolas' instead)
# #
@ -75,6 +77,7 @@ while [ ! -z "$1" ]; do
gz) use_gz=1 ; ;; gz) use_gz=1 ; ;;
no-ogv) no_ogv=1 ; ;; no-ogv) no_ogv=1 ; ;;
no-fnt) no_fnt=1 ; ;; no-fnt) no_fnt=1 ; ;;
no-hl) no_hl=1 ; ;;
no-dd) no_dd=1 ; ;; no-dd) no_dd=1 ; ;;
no-cm) no_cm=1 ; ;; no-cm) no_cm=1 ; ;;
no-sh) do_sh= ; ;; no-sh) do_sh= ; ;;
@ -226,6 +229,9 @@ rm have
tmv "$f" tmv "$f"
} }
[ $no_hl ] &&
rm -rf copyparty/web/deps/prism*
[ $no_fnt ] && { [ $no_fnt ] && {
rm -f copyparty/web/deps/scp.woff2 rm -f copyparty/web/deps/scp.woff2
f=copyparty/web/ui.css f=copyparty/web/ui.css

View file

@ -57,6 +57,9 @@ copyparty/web/deps/ogv-demuxer-ogg-wasm.js,
copyparty/web/deps/ogv-demuxer-ogg-wasm.wasm, copyparty/web/deps/ogv-demuxer-ogg-wasm.wasm,
copyparty/web/deps/ogv-worker-audio.js, copyparty/web/deps/ogv-worker-audio.js,
copyparty/web/deps/ogv.js, copyparty/web/deps/ogv.js,
copyparty/web/deps/prism.js,
copyparty/web/deps/prism.css,
copyparty/web/deps/prismd.css,
copyparty/web/deps/scp.woff2, copyparty/web/deps/scp.woff2,
copyparty/web/deps/sha512.ac.js, copyparty/web/deps/sha512.ac.js,
copyparty/web/deps/sha512.hw.js, copyparty/web/deps/sha512.hw.js,