From 2b5d9a3416b4ee27d482bcd06f4102b6f89601ce Mon Sep 17 00:00:00 2001 From: Derek Stevens Date: Tue, 18 May 2021 13:10:28 -0600 Subject: [PATCH] mangle html for thumbnails in euereka instead of the shellscript -- wayyy faster --- build.sh | 2 +- main.c | 30 ++++++++++++++++++++++++++++-- thumbnailer.sh | 35 +++++++++++++---------------------- 3 files changed, 42 insertions(+), 25 deletions(-) diff --git a/build.sh b/build.sh index f2de11b..aee4218 100755 --- a/build.sh +++ b/build.sh @@ -27,7 +27,7 @@ cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wuninitializ # Run ./main -./thumbnailer.sh +./thumbnailer.sh build # Cleanup diff --git a/main.c b/main.c index 808492d..0fe1108 100644 --- a/main.c +++ b/main.c @@ -130,10 +130,32 @@ int fphref(FILE* f, char* s) { return 1; } +char* thumbtrans(char* s, char* thumb) { + int i, j; + char* ss; + char* fnss; + char fn[1024]; + + scpy(s, thumb, slen(s)); + + i = clin(thumb, '/'); + ss = thumb + i + 1; + + scpy(ss, fn, slen(thumb) - i + 1); + scpy(".thumb/", ss, 8); + + j = clin(fn, '.'); + fnss = fn + j; + scpy(".png", fnss, 5); + scat(thumb, fn); + return thumb; +} + int fpimg(FILE* f, char* s) { char id[1024] = {0}; char src[1024] = {0}; char alt[1024] = {0}; + char thumb[1024] = {0}; char* c = s; int i = 0; @@ -156,8 +178,9 @@ int fpimg(FILE* f, char* s) { } } + thumbtrans(src, thumb); fprintf(f, "\n", id, src); - fprintf(f, "%s\n", src, alt); + fprintf(f, "%s\n", thumb, alt); fputs("", f); return 1; } @@ -167,6 +190,7 @@ int fphimg(FILE* f, char* s) { char href[1024] = {0}; char src[1024] = {0}; char alt[1024] = {0}; + char thumb[1024] = {0}; char* c = s; int i = 0; @@ -192,8 +216,10 @@ int fphimg(FILE* f, char* s) { } } + thumbtrans(src, thumb); + fprintf(f, "\n", id, href); - fprintf(f, "%s\n", src, alt); + fprintf(f, "%s\n", thumb, alt); fputs("", f); return 1; } diff --git a/thumbnailer.sh b/thumbnailer.sh index fcb93c7..2b42774 100755 --- a/thumbnailer.sh +++ b/thumbnailer.sh @@ -17,7 +17,6 @@ pathtrans() { } # generate thumbnails in /img/*/.thumb/ - resize() { output=$(pathtrans $1) if echo $1 | grep .gif > /dev/null; then @@ -27,28 +26,20 @@ resize() { echo "generating thumbnail for $1" convert $1 -strip -auto-orient -resize ${SIZE} -dither FloydSteinberg -colors 16 ${output} fi - replace $1 ${output} } -# crawl through html and replace src='/img/*/*' with src='/img/*/.thumb/*' -replace() { - src=$(echo $1 | sed s#\.\./www##) - dest=$(echo $2 | sed s#\.\./www##) - src=$(echo "src='${src}'") - dest=$(echo "src='${dest}'") - - echo -n "modifying html to use thumbnail for $1" - for f in $(find ${ROOT}/*.html); do - echo -n "." - if grep ${src} ${f} > /dev/null; then - sed -i s#${src}#${dest}# $f - fi - done - echo -} - -echo "creating new thumbnails" -for x in $(find ${SRC}/*/*); do resize $x exit; done -echo "done" +if [ -z $1 ]; then + echo "usage: $0 [build|clean]" +else + case $1 in + "build") + echo "creating new thumbnails" + for x in $(find ${SRC}/*/*); do resize $x; done;; + "clean") + echo "cleaning thumbnails cache" + rm -rf ${SRC}/*/.thumb + echo "cleaned";; + esac +fi