chiark / gitweb /
m.filesize, m.images: support Pelican 3.8 {static} placeholder.
authorVladimír Vondruš <mosra@centrum.cz>
Fri, 16 Nov 2018 23:22:46 +0000 (00:22 +0100)
committerVladimír Vondruš <mosra@centrum.cz>
Fri, 16 Nov 2018 23:29:39 +0000 (00:29 +0100)
pelican-plugins/m/filesize.py
pelican-plugins/m/images.py

index ad85428d9947e7d3a7019466bb2e0bd2023699a2..f83ef381e3ee3ddd76fd43448619798a37587059 100644 (file)
@@ -36,7 +36,9 @@ def init(pelicanobj):
     pass
 
 def filesize(name, rawtext, text, lineno, inliner, options={}, content=[]):
-    size = os.path.getsize(text.format(filename=os.path.join(os.getcwd(), settings['path'])))
+    # Support both {filename} (3.7.1) and {static} (3.8) placeholders
+    file = os.path.join(os.getcwd(), settings['path'])
+    size = os.path.getsize(text.format(filename=file, static=file))
 
     for unit in ['','k','M','G','T']:
         if abs(size) < 1024.0:
@@ -49,7 +51,9 @@ def filesize(name, rawtext, text, lineno, inliner, options={}, content=[]):
     return [nodes.inline(size_string, size_string, **options)], []
 
 def filesize_gz(name, rawtext, text, lineno, inliner, options={}, content=[]):
-    with open(text.format(filename=os.path.join(os.getcwd(), settings['path'])), mode='rb') as f:
+    # Support both {filename} (3.7.1) and {static} (3.8) placeholders
+    file = os.path.join(os.getcwd(), settings['path'])
+    with open(text.format(filename=file, static=file), mode='rb') as f:
         size = len(gzip.compress(f.read()))
 
     for unit in ['','k','M','G','T']:
index 2231d5bd13cc158d64d313b55a1bf08f2f60cc07..b8eb6ac9bb542dae80d224a1bd3c07ea76ab7fd3 100644 (file)
@@ -181,7 +181,9 @@ class ImageGrid(rst.Directive):
                 continue
 
             # Open the files and calculate the overall width
-            absuri = uri.format(filename=os.path.join(os.getcwd(), settings['PATH']))
+            # Support both {filename} (3.7.1) and {static} (3.8) placeholders
+            file = os.path.join(os.getcwd(), settings['PATH'])
+            absuri = uri.format(filename=file, static=file)
             im = PIL.Image.open(absuri)
 
             # Get EXIF info, if it's there