From: Vladimír Vondruš Date: Fri, 16 Nov 2018 23:22:46 +0000 (+0100) Subject: m.filesize, m.images: support Pelican 3.8 {static} placeholder. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=607a0cbd5b7d2aeb3abba2466c51e5c5515c25d0;p=blog.git m.filesize, m.images: support Pelican 3.8 {static} placeholder. --- 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