all repos — eureka @ 2b5d9a3416b4ee27d482bcd06f4102b6f89601ce

static site generator based on the 100r.co engine

mangle html for thumbnails in euereka instead of the shellscript -- wayyy faster
Iris Lightshard nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEkFh6dA+k/6CXFXU4O3+8IhROY5gFAmCkESQACgkQO3+8IhRO
Y5jmnQ//dz6AV9Zaz+wj8SPxuDJoGN6zF6W7r4OpdmcE4J69UfpPwsJUN7ZI6hmH
XwSHfDGDzQfrvoLDi+yRrAa8eIZo1GiXy8z4qBv4S1i7oZ/btmnyPBHRYJRwrbTL
3CdyAtmZgva872ZOHIr6dP8uWpOBgbA2XMyAQpTGMU/lS80+PHVesV/oFVJ7IrnF
uRjT/CRyxqJTG3x3Hdecx6TJoDqZmx+c2N8Yz9Gyu4T5ISSEIvWbDld/n1SUs4AU
eqnAjQC1KfphibdkTyNKP0Xd5EridTm2fu/WicoigSilt+PXqDeV4HUUBbI+XVo5
A4pQ2L/8RncS0ejMPo5H2Lh9B4f72Zzqf6rKOM2qJYQoz6KCmiPYy5zpSqHDvMpN
1GxzSuYoUbHsrI6MHsoP+3xbwGkgKoU3sB0JM365pvSGPfqRkPlbTOs11fdD/hnj
VeKeSC9rcRiUfvfjQsJCk4DGnM/Wu34H7D7XkjMnxHHhXIXo2niaBCkDuQxMKzLi
f7yZjarV9kAZI3ge1aequo3GVeDQzqBh5JI0auGG3B6LHoML2LLUgDUbvIWGRGEY
gCuM7EZ/uvJhD/zeIdEc+LH1MCS6qeIBOmoLTyZCBCWRKKql/sTOFgLcyQ9QnINR
CaYfvkfil83LFFx+hLZ16pknhI31xxcDPz0Xsq8exwqyZyZ9peo=
=jsf2
-----END PGP SIGNATURE-----
commit

2b5d9a3416b4ee27d482bcd06f4102b6f89601ce

parent

76fc3e88ff43a81fd61ddebf5e0243087aa2e8a9

3 files changed, 42 insertions(+), 25 deletions(-)

jump to
M build.shbuild.sh

@@ -27,7 +27,7 @@ # echo "$(du -b ./main | cut -f1) bytes written"

# Run ./main -./thumbnailer.sh +./thumbnailer.sh build # Cleanup
M main.cmain.c

@@ -130,10 +130,32 @@ fprintf(f, "<a href='%s'>%s</a>", href, txt);

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 @@ break;

} } + thumbtrans(src, thumb); fprintf(f, "<a id='%s' href='%s'>\n", id, src); - fprintf(f, "<img class='image' src='%s' alt='%s'/>\n", src, alt); + fprintf(f, "<img class='image' src='%s' alt='%s'/>\n", thumb, alt); fputs("</a>", f); return 1; }

@@ -167,6 +190,7 @@ char id[1024] = {0};

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 @@ break;

} } + thumbtrans(src, thumb); + fprintf(f, "<a id='%s' href='%s'>\n", id, href); - fprintf(f, "<img class='image' src='%s' alt='%s'/>\n", src, alt); + fprintf(f, "<img class='image' src='%s' alt='%s'/>\n", thumb, alt); fputs("</a>", f); return 1; }
M thumbnailer.shthumbnailer.sh

@@ -17,7 +17,6 @@ echo ${transform}

} # generate thumbnails in /img/*/.thumb/ - resize() { output=$(pathtrans $1) if echo $1 | grep .gif > /dev/null; then

@@ -27,28 +26,20 @@ if [ ! -f ${output} ]; then

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