Revert "Image optimization"

This commit is contained in:
AngelJumbo
2024-12-18 21:29:07 -05:00
committed by GitHub
parent 836b5c4d07
commit 6e0c1ebca9
2 changed files with 57 additions and 81 deletions
-1
View File
@@ -1,2 +1 @@
*.html *.html
.minified/
+57 -80
View File
@@ -20,44 +20,16 @@
# 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.
write_section_header() {
echo "<h2 class='s$1 clickable' onclick='activeSection(\"$2\")' >" >>$3 write_section_header(){
echo "$2" | tr a-z A-Z >>$3 echo "<h2 class='s$1 clickable' onclick='activeSection(\"$2\")' >" >> $3
echo "</h2>" >>$3 echo "$2" | tr a-z A-Z >> $3
echo "</h2>" >> $3
} }
MINIFIED_IMAGES_DIR='.minified' write_img(){
IMAGE_PREVIEW_WIDTH=200 echo " <a target='_blank' href='$1'>
<img loading='lazy' src='$1' alt='$1' width='200'></a>" >> $2
# Returns path to minified img or default img if no tools for minification
minify_image() {
local image=$1
if ! [ "$(command -v magick)" ]; then
echo "${image}"
return
fi
local preview_image
preview_image="${MINIFIED_IMAGES_DIR}/${image}.min.png"
mkdir -p "$(dirname "${preview_image}")"
magick convert "${image}" -resize "${IMAGE_PREVIEW_WIDTH}" -format png -write "${preview_image}"
echo "${preview_image}"
}
write_img() {
local image=$1
local output=$2
local preview_image
preview_image=$(minify_image "${image}")
echo "
<a target='_blank' href='${image}'>
<img loading='lazy' src='${preview_image}' alt='Preview of ${image} image' width='${IMAGE_PREVIEW_WIDTH}'>
</a>" >>"${output}"
} }
rm *.html rm *.html
@@ -91,67 +63,71 @@ echo "<!DOCTYPE html>
</button> </button>
</div> </div>
<main> <main>
<h1>Gruvbox Wallpapers</h1>" >./index.html <h1>Gruvbox Wallpapers</h1>" > ./index.html
color=1 color=1
maxPerPage=8 maxPerPage=8
declare -a sections declare -a sections
for subdir in ./wallpapers/*; do for subdir in ./wallpapers/*
section="${subdir##*/}" do
sections+=("$section") section="${subdir##*/}"
write_section_header $color "$section" ./index.html sections+=("$section")
write_section_header $color "$section" ./index.html
page=1
img_count=0
subhtml="${section}_page${page}.html"
touch ./$subhtml
echo "<div class='section' id='$section'>" >>./index.html page=1
img_count=0
subhtml="${section}_page${page}.html"
touch ./$subhtml
echo "<div class='pager'>" >>./index.html echo "<div class='section' id='$section'>" >> ./index.html
countImgs=$(find "$subdir" -type f | wc -l)
countImgs=$((countImgs - 1))
for i in $(seq 1 $(((countImgs / maxPerPage) + 1))); do
echo "<button class='btn pager-btn' onclick='loadPage(\"$section\", $i)'>$i</button>" >>./index.html
done
echo "</div>" >>./index.html
echo "<div id='$section-content'>" >>./index.html
echo "<div class='c'>" >>./$subhtml
for wallpaper in ${subdir}/*; do
if [ "$img_count" -ge $maxPerPage ]; then
echo "</div>" >>./$subhtml echo "<div class='pager'>" >> ./index.html
page=$((page + 1)) countImgs=$(find "$subdir" -type f | wc -l)
subhtml="${section}_page${page}.html" countImgs=$((countImgs - 1))
touch ./$subhtml for i in $(seq 1 $((( $countImgs / $maxPerPage)+1))); do
echo "<button class='btn pager-btn' onclick='loadPage(\"$section\", $i)'>$i</button>" >> ./index.html
done
echo "</div>" >> ./index.html
echo "<div id='$section-content'>" >> ./index.html
echo "<div class='c'>" >> ./$subhtml
for wallpaper in ${subdir}/*
do
if [ "$img_count" -ge $maxPerPage ]; then
echo "<div class='c'>" >>./$subhtml echo "</div>" >> ./$subhtml
img_count=0 page=$((page + 1))
fi subhtml="${section}_page${page}.html"
touch ./$subhtml
write_img $wallpaper ./$subhtml
img_count=$((img_count + 1))
done
echo "</div>" >>./$subhtml echo "<div class='c'>" >> ./$subhtml
img_count=0
fi
echo "</div>" >>./index.html write_img $wallpaper ./$subhtml
echo "</div>" >>./index.html img_count=$((img_count + 1))
done
color=$((color + 1)) echo "</div>" >> ./$subhtml
if [ "$color" -eq 8 ]; then
color=1 echo "</div>" >> ./index.html
fi echo "</div>" >> ./index.html
color=$((color + 1))
if [ "$color" -eq 8 ]; then
color=1
fi
done 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 #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
echo " echo "
@@ -162,8 +138,9 @@ echo "
setTheme('light'); setTheme('light');
} }
} }
</script>" >>./index.html </script>" >> ./index.html
echo " echo "
</body> </body>
</html>" >>./index.html </html>" >> ./index.html