From 610a3ba8163a4d6fd6c40205244c02f8c3691348 Mon Sep 17 00:00:00 2001 From: touero Date: Fri, 21 Mar 2025 18:01:25 +0800 Subject: [PATCH] feat: implement thumbnail display --- .gitignore | 1 + build.sh | 89 ++++++++++++++++++++++++++++-------------------------- 2 files changed, 48 insertions(+), 42 deletions(-) diff --git a/.gitignore b/.gitignore index 2d19fc7..261a569 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *.html +thumbnails/ diff --git a/build.sh b/build.sh index 472f81d..45bd7a2 100755 --- a/build.sh +++ b/build.sh @@ -20,16 +20,28 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. - -write_section_header(){ - echo "

" >> $3 - echo "$2" | tr a-z A-Z >> $3 - echo "

" >> $3 +generate_thumbnails() { + echo "generate thumbnails ..." + mkdir -p thumbnails + for img in ./wallpapers/*/*; do + local thumbnail="thumbnails/${img##*/}" + convert "$img" -resize 200x200 "$thumbnail" + done } -write_img(){ - echo " -$1" >> $2 +write_section_header() { + echo "write section header ..." + echo "

" >>$3 + echo "$2" | tr a-z A-Z >>$3 + echo "

" >>$3 +} + +write_img() { + echo "write image ..." + local img_relative_path=${1#./} + local thumbnail="thumbnails/${1##*/}" + echo " +$1" >>$2 } rm *.html @@ -38,7 +50,6 @@ touch ./index.html echo " - @@ -47,7 +58,6 @@ echo " -
@@ -63,71 +73,68 @@ echo "
-

Gruvbox Wallpapers

" > ./index.html +

Gruvbox Wallpapers

" >./index.html color=1 -maxPerPage=8 +maxPerPage=8 declare -a sections -for subdir in ./wallpapers/* -do +# 生成缩略图 +generate_thumbnails + +for subdir in ./wallpapers/*; do section="${subdir##*/}" sections+=("$section") write_section_header $color "$section" ./index.html - page=1 img_count=0 subhtml="${section}_page${page}.html" touch ./$subhtml - echo "
" >> ./index.html + echo "
" >>./index.html - echo "
" >> ./index.html + echo "
" >>./index.html countImgs=$(find "$subdir" -type f | wc -l) countImgs=$((countImgs - 1)) - for i in $(seq 1 $((( $countImgs / $maxPerPage)+1))); do - echo "" >> ./index.html + for i in $(seq 1 $((($countImgs / $maxPerPage) + 1))); do + echo "" >>./index.html done - echo "
" >> ./index.html - echo "
" >> ./index.html - echo "
" >> ./$subhtml - for wallpaper in ${subdir}/* - do + echo "
" >>./index.html + echo "
" >>./index.html + echo "
" >>./$subhtml + for wallpaper in ${subdir}/*; do if [ "$img_count" -ge $maxPerPage ]; then - - echo "
" >> ./$subhtml + echo "
" >>./$subhtml page=$((page + 1)) subhtml="${section}_page${page}.html" touch ./$subhtml - - echo "
" >> ./$subhtml + echo "
" >>./$subhtml img_count=0 fi - write_img $wallpaper ./$subhtml + write_img "$wallpaper" "./$subhtml" img_count=$((img_count + 1)) done - echo "
" >> ./$subhtml + echo "
" >>./$subhtml - echo "
" >> ./index.html - echo "
" >> ./index.html + echo "
" >>./index.html + echo "
" >>./index.html color=$((color + 1)) - if [ "$color" -eq 8 ]; then + if [ "$color" -eq 8 ]; then color=1 fi done -echo "
" >> ./index.html +echo "" >>./index.html echo "" >> ./index.html +" >>./index.html - -echo " - -" >> ./index.html +echo " +" >>./index.html