From 607a0cbd5b7d2aeb3abba2466c51e5c5515c25d0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 17 Nov 2018 00:22:46 +0100 Subject: [PATCH] m.filesize, m.images: support Pelican 3.8 {static} placeholder. --- pelican-plugins/m/filesize.py | 8 ++++++-- pelican-plugins/m/images.py | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pelican-plugins/m/filesize.py b/pelican-plugins/m/filesize.py index ad85428d..f83ef381 100644 --- a/pelican-plugins/m/filesize.py +++ b/pelican-plugins/m/filesize.py @@ -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']: diff --git a/pelican-plugins/m/images.py b/pelican-plugins/m/images.py index 2231d5bd..b8eb6ac9 100644 --- a/pelican-plugins/m/images.py +++ b/pelican-plugins/m/images.py @@ -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 -- 2.30.2