mangle html for thumbnails in euereka instead of the shellscript -- wayyy faster
This commit is contained in:
parent
76fc3e88ff
commit
2b5d9a3416
3 changed files with 42 additions and 25 deletions
2
build.sh
2
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
|
||||
|
|
30
main.c
30
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, "<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 @@ 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, "<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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue