|
@@ -236,4 +236,28 @@ def hook_postconvert_mobilecompat():
|
236
|
236
|
fp.write("}\n");
|
237
|
237
|
fp.write("header('Location: '.$loc);\n")
|
238
|
238
|
fp.write("?>")
|
239
|
|
- fp.close()
|
|
239
|
+ fp.close()
|
|
240
|
+
|
|
241
|
+def hook_postconvert_size():
|
|
242
|
+ file_ext = '|'.join(['pdf', 'zip', 'rar', 'odp', 'exe', 'brd', 'mp3', 'mp4', 'plist']).encode("utf-8")
|
|
243
|
+ def matched_link(matchobj):
|
|
244
|
+ try:
|
|
245
|
+ path = matchobj.group(1)
|
|
246
|
+ if path.startswith("http") or path.startswith("//"):
|
|
247
|
+ return '<a href=\"%s\">%s</a>' % (matchobj.group(1), matchobj.group(3))
|
|
248
|
+ elif path.startswith("/"):
|
|
249
|
+ path = path.strip("/")
|
|
250
|
+ path = os.path.join("static/", path)
|
|
251
|
+ size = os.path.getsize(path)
|
|
252
|
+ if size >= (1024 * 1024):
|
|
253
|
+ return "<a href=\"%s\">%s</a> (%.1f MiB)" % (matchobj.group(1), matchobj.group(3), size / (1024.0 * 1024.0))
|
|
254
|
+ elif size >= 1024:
|
|
255
|
+ return "<a href=\"%s\">%s</a> (%d KiB)" % (matchobj.group(1), matchobj.group(3), size // 1024)
|
|
256
|
+ else:
|
|
257
|
+ return "<a href=\"%s\">%s</a> (%d Byte)" % (matchobj.group(1), matchobj.group(3), size)
|
|
258
|
+ except:
|
|
259
|
+ print "Unable to estimate file size for %s" % matchobj.group(1)
|
|
260
|
+ return '<a href=\"%s\">%s</a>' % (matchobj.group(1), matchobj.group(3))
|
|
261
|
+ _re_url = '<a href=\"([^\"]*?\.(%s))\">(.*?)<\/a>' % file_ext
|
|
262
|
+ for p in pages:
|
|
263
|
+ p.html = re.sub(_re_url, matched_link, p.html)
|