Introduction
Introduction Statistics Contact Development Disclaimer Help
add -l option to set lazyload hint for images that have dimensions - smu - smu …
git clone git://git.codemadness.org/smu
Log
Files
Refs
README
LICENSE
---
commit bcfa37c77dc9519b54e05813b1f73dbbf0f0b4c9
parent fbc3d2b11f52754309998077a50a757278671759
Author: Hiltjo Posthuma <[email protected]>
Date: Tue, 11 May 2021 17:30:03 +0200
add -l option to set lazyload hint for images that have dimensions
Diffstat:
M smu.1 | 3 +++
M smu.c | 8 ++++++--
2 files changed, 9 insertions(+), 2 deletions(-)
---
diff --git a/smu.1 b/smu.1
@@ -7,6 +7,7 @@
.Sh SYNOPSIS
.Nm
.Op Fl h
+.Op Fl l
.Op Fl n
.Op Fl v
.Sh DESCRIPTION
@@ -16,6 +17,8 @@ The options are as follows:
.Bl -tag -width Ds
.It Fl h
prints usage information to stderr, then exits.
+.It Fl l
+set loading="lazy" hint attribute for images if it has a width and a height.
.It Fl n
escapes all HTML tags.
.It Fl v
diff --git a/smu.c b/smu.c
@@ -41,7 +41,7 @@ static void process(const char *begin, const char *end, int i…
static Parser parsers[] = { dounderline, docomment, dolineprefix,
dolist, doparagraph, dogtlt, dosurround, dolink,
doshortlink, dohtml, doamp, doreplace };
-static int nohtml = 0;
+static int lazyimg = 0, nohtml = 0;
static Tag lineprefix[] = {
{ " ", 0, "<pre><code>", "\n</code></pre>" },
@@ -337,6 +337,8 @@ dolink(const char *begin, const char *end, int newblock)
printf("width=\"%ld\" ", width);
if (height > 0)
printf("height=\"%ld\" ", height);
+ if (width > 0 && height > 0 && lazyimg)
+ fputs("loading=\"lazy\" ", stdout);
fputs("/>", stdout);
} else {
fputs("<a href=\"", stdout);
@@ -692,7 +694,7 @@ process(const char *begin, const char *end, int newblock)
void
usage(char **argv)
{
- eprint("usage: %s [-n]\n\t-n escape HTML strictly\n", argv[0]);
+ eprint("usage: %s [-l] [-n]\n", argv[0]);
}
int
@@ -710,6 +712,8 @@ main(int argc, char *argv[])
eprint("smu v%s\n", VERSION);
else if (!strcmp("-n", argv[i]))
nohtml = 1;
+ else if (!strcmp("-l", argv[i]))
+ lazyimg = 1;
else
usage(argv);
}
You are viewing proxied material from codemadness.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.