diff options
author | SoniEx2 <endermoneymod@gmail.com> | 2022-02-04 12:08:59 -0300 |
---|---|---|
committer | SoniEx2 <endermoneymod@gmail.com> | 2022-02-04 12:08:59 -0300 |
commit | c9c1f68908324099aea5359b1c0575cde0653d37 (patch) | |
tree | 9b509a3d2032d0cd64d4fbcf73a869a15f2c23f3 | |
parent | 014544bd0b29f69d088f28ff748ee9192f02d0ef (diff) |
Better handling of large files
-rwxr-xr-x | git-hooks/post-receive | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/git-hooks/post-receive b/git-hooks/post-receive index f8337ad..4871122 100755 --- a/git-hooks/post-receive +++ b/git-hooks/post-receive @@ -288,7 +288,10 @@ while todotrees: linktarget = get_relative(path, tree) link.symlink_to(linktarget, target_is_directory=True) # FIXME html-escape - f.write("<li><a href=\"./{}\">{}</a></li>".format(quoted, quoted)) + f.write("<li>") + f.write("<a href=\"./{}\">{}</a>".format(quoted, quoted)) + f.write(" <span class=\"bytes\">{}</span>".format(obj.size)) + f.write("</li>") elif isinstance(obj, pygit2.Tree): todotrees.add(obj) tree = gen_dir / "trees" / str(obj.id) @@ -319,12 +322,18 @@ while todoblobs: continue with f: f.write("<!DOCTYPE html><html><head><meta charset=\"utf-8\"><title>blob</title><body>") - f.write("<a href=\"./raw.bin\">view raw</a>") + f.write("<a href=\"./raw.bin\">view raw</a> <span class=\"bytes\">") + f.write(str(b.size)) + f.write("</span>") try: text = b.data.decode("utf-8", errors="strict") lex = find_lexer(text, meta) if lex is not None: - f.write(highlight(text, lex, HtmlFormatter())) + # limit highlighting to files within 256KiB + if b.size <= (256 * 1024): + f.write(highlight(text, lex, HtmlFormatter())) + else: + f.write("<div>files larger than 256KiB may not be rendered</div>") else: # TODO maybe just write `text` (html escaped)? pass |