html.mk

static html creation framework using make(1) and cpp(1)
Log | Files | Refs | README | LICENSE

commit 818a835deceb519cf3571aba7c709456f04e92e0
parent 0015861934b4cbf09826405f900a5df1d472eab3
Author: Kyle Milz <krwmilz@gmail.com>
Date:   Sat, 14 Aug 2021 21:27:30 +0000

mk: change img_html handling

Before images and thumbnails would be placed in an _img directory to not
confuse make. Instead, go back to renaming images and putting them in
the same directory as index.html.

Both ways are have advantages and disadvantages but I think I like this way
better. Adjust test to match.

Diffstat:
Mbsd.html.mk | 13+++++++------
Mt/img_html.t | 7++++---
2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/bsd.html.mk b/bsd.html.mk @@ -63,22 +63,23 @@ depend: ${SRCS:.in=.d} _SUBDIRUSE .SUFFIXES: .jpg .SUFFIXES: .png .jpeg.img_html .jpg.img_html .png.img_html: - mkdir -p ${.OBJDIR}/_img - cp $? ${.OBJDIR}/_img/ + cp $? ${.OBJDIR}/${<F:R}.cp.${<F:E} - @# Generate thumbnail of image with `_thumb' appended to file name. - convert -resize 800x $? ${.OBJDIR}/_img/${<F:R}_thumb.${<F:E} + @# Generate thumbnail of image with `.thumb' appended to file name. + gm convert -resize 800x $? ${.OBJDIR}/${<F:R}.thumb.${<F:E} @# @# Create HTML fragment that uses the thumbnail as a base image @# that is a link to the full size (copied) image, like this: @# - @# <a href="pic_cp.jpg"><img loading='lazy' src="pic_thumb.jpg" + @# <a href="pic.cp.jpg"><img loading='lazy' src="pic.thumb.jpg" @# @# NOTE: The <img> tag is not closed! You must close it, maybe with: @# alt="description of image for blind people" /></a> @# - echo "\t<a href='_img/${<F}'><img loading='lazy' src='_img/${<F:R}_thumb.${<F:E}' " > $@ + echo "\t<a href='${<F:R}.cp.${<F:E}'>" > $@ + echo "\t\t<img loading='lazy' src='${<F:R}.thumb.${<F:E}' " >> $@ + # # Generate `*_html' html fragments that link to videos using <video> tag. diff --git a/t/img_html.t b/t/img_html.t @@ -54,14 +54,15 @@ is( $? >> 8, 0, 'make exit status' ); my $index_good; for my $sfx (@sfxs) { - my $cp_file = catfile( '_img', "pic_${sfx}.${sfx}" ); - my $thumb_file = catfile( '_img', "pic_${sfx}_thumb.${sfx}" ); + my $cp_file = "pic_${sfx}.cp.${sfx}"; + my $thumb_file = "pic_${sfx}.thumb.${sfx}"; file_exists_ok( catfile( $cmd->workdir, $cp_file ) ); file_exists_ok( catfile( $cmd->workdir, $thumb_file ) ); my $html_good = <<EOF; - <a href='$cp_file'><img loading='lazy' src='$thumb_file' + <a href='$cp_file'> + <img loading='lazy' src='$thumb_file' EOF my $html_file = catfile( $cmd->workdir, "pic_${sfx}.img_html" );