Merge pull request #62 from touero/main

Implement thumbnail display
This commit is contained in:
AngelJumbo
2025-03-23 08:41:39 -05:00
committed by GitHub
2 changed files with 48 additions and 42 deletions
+1
View File
@@ -1 +1,2 @@
*.html *.html
thumbnails/
+21 -16
View File
@@ -20,16 +20,28 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE. # SOFTWARE.
generate_thumbnails() {
echo "generate thumbnails ..."
mkdir -p thumbnails
for img in ./wallpapers/*/*; do
local thumbnail="thumbnails/${img##*/}"
convert "$img" -resize 200x200 "$thumbnail"
done
}
write_section_header() { write_section_header() {
echo "write section header ..."
echo "<h2 class='s$1 clickable' onclick='activeSection(\"$2\")' >" >>$3 echo "<h2 class='s$1 clickable' onclick='activeSection(\"$2\")' >" >>$3
echo "$2" | tr a-z A-Z >>$3 echo "$2" | tr a-z A-Z >>$3
echo "</h2>" >>$3 echo "</h2>" >>$3
} }
write_img() { write_img() {
echo " <a target='_blank' href='$1'> echo "write image ..."
<img loading='lazy' src='$1' alt='$1' width='200'></a>" >> $2 local img_relative_path=${1#./}
local thumbnail="thumbnails/${1##*/}"
echo " <a target='_blank' href='$img_relative_path'>
<img loading='lazy' src='$thumbnail' alt='$1' width='200'></a>" >>$2
} }
rm *.html rm *.html
@@ -38,7 +50,6 @@ touch ./index.html
echo "<!DOCTYPE html> echo "<!DOCTYPE html>
<html lang='en'> <html lang='en'>
<head> <head>
<meta charset='utf-8'> <meta charset='utf-8'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'> <meta name='viewport' content='width=device-width, initial-scale=1.0'>
@@ -47,7 +58,6 @@ echo "<!DOCTYPE html>
<script src='app.js' defer></script> <script src='app.js' defer></script>
<script src='https://kit.fontawesome.com/13865d7982.js' crossorigin='anonymous' defer></script> <script src='https://kit.fontawesome.com/13865d7982.js' crossorigin='anonymous' defer></script>
</head> </head>
<body> <body>
<div class='float-btns'> <div class='float-btns'>
<a href='https://github.com/AngelJumbo/gruvbox-wallpapers' target='_blank' class='btn float-btn' title='Source code' > <a href='https://github.com/AngelJumbo/gruvbox-wallpapers' target='_blank' class='btn float-btn' title='Source code' >
@@ -71,13 +81,14 @@ maxPerPage=8
declare -a sections declare -a sections
for subdir in ./wallpapers/* # 生成缩略图
do generate_thumbnails
for subdir in ./wallpapers/*; do
section="${subdir##*/}" section="${subdir##*/}"
sections+=("$section") sections+=("$section")
write_section_header $color "$section" ./index.html write_section_header $color "$section" ./index.html
page=1 page=1
img_count=0 img_count=0
subhtml="${section}_page${page}.html" subhtml="${section}_page${page}.html"
@@ -94,21 +105,18 @@ do
echo "</div>" >>./index.html echo "</div>" >>./index.html
echo "<div id='$section-content'>" >>./index.html echo "<div id='$section-content'>" >>./index.html
echo "<div class='c'>" >>./$subhtml echo "<div class='c'>" >>./$subhtml
for wallpaper in ${subdir}/* for wallpaper in ${subdir}/*; do
do
if [ "$img_count" -ge $maxPerPage ]; then if [ "$img_count" -ge $maxPerPage ]; then
echo "</div>" >>./$subhtml echo "</div>" >>./$subhtml
page=$((page + 1)) page=$((page + 1))
subhtml="${section}_page${page}.html" subhtml="${section}_page${page}.html"
touch ./$subhtml touch ./$subhtml
echo "<div class='c'>" >>./$subhtml echo "<div class='c'>" >>./$subhtml
img_count=0 img_count=0
fi fi
write_img $wallpaper ./$subhtml write_img "$wallpaper" "./$subhtml"
img_count=$((img_count + 1)) img_count=$((img_count + 1))
done done
@@ -125,7 +133,6 @@ done
echo "</main>" >>./index.html echo "</main>" >>./index.html
echo "<script> echo "<script>
window.onload = () => {" >>./index.html window.onload = () => {" >>./index.html
#echo "hideAll();" >> ./index.html
for section in "${sections[@]}"; do for section in "${sections[@]}"; do
echo " loadPage('$section', 1);" >>./index.html echo " loadPage('$section', 1);" >>./index.html
done done
@@ -140,7 +147,5 @@ echo "
} }
</script>" >>./index.html </script>" >>./index.html
echo "</body>
echo "
</body>
</html>" >>./index.html </html>" >>./index.html