2minNoods/2minNoods.sh

108 lines
2.9 KiB
Bash
Raw Normal View History

2023-08-27 00:30:39 +00:00
#!/bin/bash
siteroot="../2minNoods_siteroot"
noodspp=40
mkdir -p "$siteroot/img/thumbs"
pageno=1
noodcount=1
2023-08-27 00:30:39 +00:00
# html and css stolen from https://perfectmotherfuckingwebsite.com/
pageheader='''<!DOCTYPE html>
2023-08-27 00:30:39 +00:00
<html lang="en">
<head>
<meta charset="utf-8">
<title>2minNoods</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="A saucy photoblog 😉">
<!-- <link rel="stylesheet" href="style.css">-->
<style>
body{
max-width:800px;
margin:10px auto;
2023-08-27 00:30:39 +00:00
padding:0 10px;
font:18px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
color:#444
}
h1,h2,h3{
line-height:1
}
.page-links{
font-size: 2em;
}
a.button{
padding: 1px 6px;
border: 1px outset buttonborder;
border-radius: 3px;
color: buttontext;
background-color: buttonface;
text-decoration: none;
2023-08-27 00:30:39 +00:00
}
@media (prefers-color-scheme: dark){
body{
color:#c9d1d9;
background:#0d1117
}
a:link{
color:#58a6ff
}
a:visited{
color:#8e96f0
}
}
</style>
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>😉</text></svg>">
</head>
<body>
<h1>2minNoods</h1>
<hr>'''
2023-08-27 00:30:39 +00:00
rm -v "$siteroot"/index.*.html
echo '<meta http-equiv="refresh" content="0; url=index.1.html" />' > "$siteroot/index.html"
ls *.jpg | sort -k2 -t'_' -r > "$siteroot/photolist.txt"
2023-08-27 00:30:39 +00:00
while read i; do
if [ -f "$i" ]; then
if [ ! -f "$siteroot/img/$i" ]; then
2023-08-27 00:30:39 +00:00
echo "Resizing $i"
convert "$i" -quality 70 -strip -auto-orient -resize "960^>" "$siteroot/img/thumbs/$i"
convert "$i" -quality 90 -strip -auto-orient -resize "2160^>" "$siteroot/img/$i"
fi
if [[ $noodcount -eq 1 ]]; then
echo "$pageheader" > "$siteroot/index.$pageno.html"
fi
echo '<h3>'"$(basename $i .jpg)"'</h3><a href="'"img/$i"'"><img src="'"img/thumbs/$i"'" style="width:100%" loading="lazy"></a><hr>' >> "$siteroot/index.$pageno.html"
((noodcount++))
if [[ $noodcount -gt $noodspp ]]; then
((pageno++))
noodcount=1
2023-08-27 00:30:39 +00:00
fi
fi
done < "$siteroot/photolist.txt"
2023-08-27 00:30:39 +00:00
for ((page=1;page<=pageno;page++)); do
echo -n '<div class="page-links">' >> "$siteroot/index.$page.html"
for ((link=1;link<=pageno;link++)); do
if [ $link -eq $page ]; then
echo -n "$link "
else
echo -n "<a class=\"button\" href=\"index.$link.html\">$link</a> "
fi
done >> "$siteroot/index.$page.html"
echo '</div></body></html>' >> "$siteroot/index.$page.html"
done
2023-08-27 00:30:39 +00:00
echo "Searching for deleted images"
for i in $siteroot/img/*.jpg; do
pic="$(basename $i)"
if ! grep -Fxq "$pic" "$siteroot/photolist.txt"; then
rm -v "$siteroot/img/thumbs/$pic" "$siteroot/img/$pic"
fi
done
rm -v "$siteroot/photolist.txt"