From 1100562e29f6476448b656dbddd4cf22505523f6 Mon Sep 17 00:00:00 2001 From: Mitja Felicijan Date: Sun, 10 Mar 2024 14:59:14 +0100 Subject: Move back to JBMAFP --- .../2023-11-05-add-lazy-loading-to-jekyll-posts.md | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 content/notes/2023-11-05-add-lazy-loading-to-jekyll-posts.md (limited to 'content/notes/2023-11-05-add-lazy-loading-to-jekyll-posts.md') diff --git a/content/notes/2023-11-05-add-lazy-loading-to-jekyll-posts.md b/content/notes/2023-11-05-add-lazy-loading-to-jekyll-posts.md new file mode 100644 index 0000000..5d6dae4 --- /dev/null +++ b/content/notes/2023-11-05-add-lazy-loading-to-jekyll-posts.md @@ -0,0 +1,33 @@ +--- +title: "Add lazy loading of images in Jekyll posts" +url: /add-lazy-loading-to-jekyll-posts.html +date: 2023-11-05T09:04:28+02:00 +type: note +draft: false +--- + +Normally you define images with `![]()` in markdown files. But jekyll also +provides a way to adding custom attributes to tags with `{:attr="value"}`. + +If you have lots of posts this command will append `` to all +images in all your markdown files. + +```md +![image-title](/path/to/your/image.jpg) +``` + +will become + +```md +![image-title](/path/to/your/image.jpg) +``` + +Shell line bellow. Go into the folder where your posts are (probably `_posts`). + +```sh +find . -type f -name "*.md" -exec sed -i -E 's/(\!\[.*\]\((.*?)\))$/\1/' {} \; +``` + +Under the hood this adds `loading="lazy"` to HTML `img` nodes. + +That is about it. -- cgit v1.2.3