diff options
| author | Akshay Nair <phenax5@gmail.com> | 2026-07-05 23:11:26 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2026-07-05 23:11:29 +0530 |
| commit | 17d0f321faeecf5ea46faccb4157347673690def (patch) | |
| tree | f6adc23e79fe67ac82b9196359a706507cc60fec /cgit/filters/html-transform.py | |
| parent | 4d5182ad994c3bee390f3c21af4c43fc24428eef (diff) | |
| download | bacchus-remote-17d0f321faeecf5ea46faccb4157347673690def.tar.gz bacchus-remote-17d0f321faeecf5ea46faccb4157347673690def.zip | |
Add img tag lazy loading
Diffstat (limited to 'cgit/filters/html-transform.py')
| -rwxr-xr-x | cgit/filters/html-transform.py | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/cgit/filters/html-transform.py b/cgit/filters/html-transform.py index e12ffda..51b3538 100755 --- a/cgit/filters/html-transform.py +++ b/cgit/filters/html-transform.py @@ -41,12 +41,18 @@ class LinkRewriter(HTMLParser): else: value = "../" + urljoin("plain/", value) attr_map[name] = value - # Open in new tab - if tag == "a" and name == "href" and is_absolute_url(value): - if not 'target' in attr_map: attr_map['target'] = '_blank _parent' - if not 'rel' in attr_map: attr_map['rel'] = 'noopener' - attr_str = "".join( + # Open in new tab + if tag == 'a' and 'href' in attr_map and is_absolute_url(attr_map['href']): + if not 'target' in attr_map: attr_map['target'] = '_blank _parent' + if not 'rel' in attr_map: attr_map['rel'] = 'noopener' + + # Image tag lazy loading + if tag == 'img': + attr_map['loading'] = 'lazy' + attr_map['decoding'] = 'async' + + attr_str = ''.join( f' {name}="{html.escape(value, quote=True)}"' if value is not None else f" {name}" for name, value in attr_map.items() ) |
