2023-08-27 00:30:39 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2024-07-31 02:28:39 +00:00
|
|
|
# Dependencies: mktemp, sed, imagemagick, basename, grep, sort
|
|
|
|
|
|
|
|
# Config variables
|
2024-07-29 06:38:07 +00:00
|
|
|
siteroot="../2minNoods_siteroot"
|
|
|
|
noodspp=40
|
|
|
|
|
2024-07-31 02:28:39 +00:00
|
|
|
# Don't touch these
|
2024-07-29 06:38:07 +00:00
|
|
|
pageno=1
|
|
|
|
noodcount=1
|
2024-07-31 02:19:37 +00:00
|
|
|
photolist="$(mktemp --suffix='.txt')"
|
2024-07-31 02:28:39 +00:00
|
|
|
mkdir -p "$siteroot/img/thumbs"
|
2023-08-27 00:30:39 +00:00
|
|
|
|
2024-07-31 02:28:39 +00:00
|
|
|
# html and css stolen from: https://perfectmotherfuckingwebsite.com/
|
|
|
|
# a.button stolen from: https://stackoverflow.com/a/2906586
|
2024-07-29 06:38:07 +00:00
|
|
|
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{
|
2024-07-29 10:22:42 +00:00
|
|
|
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{
|
2024-07-29 06:38:07 +00:00
|
|
|
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>
|
2024-07-31 02:19:37 +00:00
|
|
|
<hr>
|
|
|
|
<!--pageno-->'''
|
2023-08-27 00:30:39 +00:00
|
|
|
|
2024-07-29 06:38:07 +00:00
|
|
|
rm -v "$siteroot"/index.*.html
|
|
|
|
|
|
|
|
echo '<meta http-equiv="refresh" content="0; url=index.1.html" />' > "$siteroot/index.html"
|
|
|
|
|
2024-07-31 02:19:37 +00:00
|
|
|
ls *.jpg | sort -k2 -t'_' -r > "$photolist"
|
2023-08-27 00:30:39 +00:00
|
|
|
|
|
|
|
while read i; do
|
|
|
|
if [ -f "$i" ]; then
|
2024-07-29 06:38:07 +00:00
|
|
|
if [ ! -f "$siteroot/img/$i" ]; then
|
2023-08-27 00:30:39 +00:00
|
|
|
echo "Resizing $i"
|
2024-07-29 06:38:07 +00:00
|
|
|
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
|
2024-07-31 02:19:37 +00:00
|
|
|
done < "$photolist"
|
2023-08-27 00:30:39 +00:00
|
|
|
|
2024-07-29 06:38:07 +00:00
|
|
|
for ((page=1;page<=pageno;page++)); do
|
2024-07-31 02:19:37 +00:00
|
|
|
htmlpagenumbers=$(
|
2024-07-31 02:28:39 +00:00
|
|
|
echo -n '<div class="page-links">'
|
|
|
|
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
|
|
|
|
echo '</div><hr>'
|
|
|
|
)
|
2024-07-31 02:19:37 +00:00
|
|
|
echo "$htmlpagenumbers" >> "$siteroot/index.$page.html"
|
|
|
|
sed -i "s%<!--pageno-->%$htmlpagenumbers%" "$siteroot/index.$page.html"
|
|
|
|
echo '</body></html>' >> "$siteroot/index.$page.html"
|
2024-07-29 06:38:07 +00:00
|
|
|
done
|
2023-08-27 00:30:39 +00:00
|
|
|
|
2024-07-29 10:22:42 +00:00
|
|
|
echo "Searching for deleted images"
|
|
|
|
for i in $siteroot/img/*.jpg; do
|
|
|
|
pic="$(basename $i)"
|
2024-07-31 02:19:37 +00:00
|
|
|
if ! grep -Fxq "$pic" "$photolist"; then
|
2024-07-29 10:22:42 +00:00
|
|
|
rm -v "$siteroot/img/thumbs/$pic" "$siteroot/img/$pic"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2024-07-31 02:19:37 +00:00
|
|
|
rm -v "$photolist"
|