Przeglądaj źródła

Add macro to show file size in links

Thomas Buck 5 lat temu
rodzic
commit
67c6c522bb
3 zmienionych plików z 30 dodań i 6 usunięć
  1. 3
    3
      input/blog/2013/2013_06_04_gfs.md
  2. 2
    2
      input/stuff/c250.md
  3. 25
    1
      macros.py

+ 3
- 3
input/blog/2013/2013_06_04_gfs.md Wyświetl plik

11
 print "*Posted at %s.*" % date
11
 print "*Posted at %s.*" % date
12
 %-->
12
 %-->
13
 
13
 
14
-Am Montag habe ich in der Schule eine [GFS][gfs] über meinen Quadrocopter gehalten. Hier die Präsentation als [ODP (2,8MB)][odp] und [PDF (3,3MB)][pdf].
14
+Am Montag habe ich in der Schule eine [GFS][gfs] über meinen Quadrocopter gehalten. Hier die Präsentation als [ODP][odp] und [PDF][pdf].
15
 
15
 
16
 Welche Note ich dafür bekomme weiß ich noch nicht, allerdings bin ich recht zuversichtlich :)
16
 Welche Note ich dafür bekomme weiß ich noch nicht, allerdings bin ich recht zuversichtlich :)
17
 
17
 
18
- [gfs]: http://de.wikipedia.org/wiki/Gleichwertige_Feststellung_von_Schülerleistungen
18
+ [gfs]: https://de.wikipedia.org/wiki/Gleichwertige_Feststellung_von_Sch%C3%BClerleistungen
19
  [odp]: files/quadgfs.odp
19
  [odp]: files/quadgfs.odp
20
- [pdf]: files/quadgfs.pdf
20
+ [pdf]: files/quadgfs.pdf

+ 2
- 2
input/stuff/c250.md Wyświetl plik

12
 
12
 
13
 In short:
13
 In short:
14
 
14
 
15
-*   Place [Mio C220 / C250 Pseudo Unlock (4.3MB)][1] on a SD Card.
15
+*   Place [Mio C220 / C250 Pseudo Unlock][1] on a SD Card.
16
 *   Insert the Card while the device is running. A file-manager will start.
16
 *   Insert the Card while the device is running. A file-manager will start.
17
 *   Backup your "MioMap" Folder which is inside "\My Flash Drive\".
17
 *   Backup your "MioMap" Folder which is inside "\My Flash Drive\".
18
 *   Delete the folder "MioMap" inside "\My Flash Drive\".
18
 *   Delete the folder "MioMap" inside "\My Flash Drive\".
48
 
48
 
49
 Der ganze Aufbau des Systems ist wirklich sehr einfach. Du kannst problemlos weitere Programme ins Menü hinzufügen.
49
 Der ganze Aufbau des Systems ist wirklich sehr einfach. Du kannst problemlos weitere Programme ins Menü hinzufügen.
50
 
50
 
51
-### [Download Mio C250 / C220 Pseudo Unlock (4.3MB)][1]
51
+### [Download Mio C250 / C220 Pseudo Unlock][1]
52
 
52
 
53
  [1]: files/c250_pseudo_unlock.zip
53
  [1]: files/c250_pseudo_unlock.zip

+ 25
- 1
macros.py Wyświetl plik

236
     fp.write("}\n");
236
     fp.write("}\n");
237
     fp.write("header('Location: '.$loc);\n")
237
     fp.write("header('Location: '.$loc);\n")
238
     fp.write("?>")
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>&nbsp;(%.1f MiB)" % (matchobj.group(1), matchobj.group(3), size / (1024.0 * 1024.0))
254
+            elif size >= 1024:
255
+                return  "<a href=\"%s\">%s</a>&nbsp;(%d KiB)" % (matchobj.group(1), matchobj.group(3), size // 1024)
256
+            else:
257
+                return  "<a href=\"%s\">%s</a>&nbsp;(%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)

Ładowanie…
Anuluj
Zapisz