From 4860306bb613a3df5090da2dfe206968a328892e Mon Sep 17 00:00:00 2001 From: Florian Knoch Date: Wed, 10 Jun 2020 17:12:49 +0200 Subject: [PATCH] Add option to lazyload images --- helper.py | 13 ++++++++++++- main.py | 22 ++++++++++++++++------ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/helper.py b/helper.py index f979184..ff944cd 100644 --- a/helper.py +++ b/helper.py @@ -1,6 +1,7 @@ import os import stat import yaml +import re # Calls a YAML parser for the given relative path inside the presentation root # directory. Returns a dictionary with the YAML content. @@ -29,4 +30,14 @@ def insert_metadata(content, root, lang): # Retrieve the modification time for a given file. def get_modification_time(path): - return os.stat(path)[stat.ST_MTIME] \ No newline at end of file + return os.stat(path)[stat.ST_MTIME] + +# Replace the "src" attribute on images by "data-src". +# Should be done after caching because fragments#defragmentize requires +# valid XHTML and data-src causes problems with that. +# Also: Toggling lazyload is easier this way. +def add_lazyload(source, lazyload_images): + if lazyload_images: + return re.sub(r'