118 lines
3.2 KiB
Bash
Executable File
118 lines
3.2 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Dependencies: mktemp, sed, imagemagick, basename, grep, sort
|
|
|
|
# Config variables
|
|
siteroot="../2minNoods_siteroot"
|
|
noodspp=40
|
|
|
|
# Don't touch these
|
|
pageno=1
|
|
noodcount=1
|
|
photolist="$(mktemp --suffix='.txt')"
|
|
mkdir -p "$siteroot/img/thumbs"
|
|
|
|
# html and css stolen from: https://perfectmotherfuckingwebsite.com/
|
|
# a.button stolen from: https://stackoverflow.com/a/2906586
|
|
pageheader='''<!DOCTYPE html>
|
|
<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;
|
|
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;
|
|
}
|
|
@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>
|
|
<!--pageno-->'''
|
|
|
|
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 > "$photolist"
|
|
|
|
while read i; do
|
|
if [ -f "$i" ]; then
|
|
if [ ! -f "$siteroot/img/$i" ]; then
|
|
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
|
|
fi
|
|
fi
|
|
done < "$photolist"
|
|
|
|
for ((page=1;page<=pageno;page++)); do
|
|
htmlpagenumbers=$(
|
|
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>'
|
|
)
|
|
echo "$htmlpagenumbers" >> "$siteroot/index.$page.html"
|
|
sed -i "s%<!--pageno-->%$htmlpagenumbers%" "$siteroot/index.$page.html"
|
|
echo '</body></html>' >> "$siteroot/index.$page.html"
|
|
done
|
|
|
|
echo "Searching for deleted images"
|
|
for i in $siteroot/img/*.jpg; do
|
|
pic="$(basename $i)"
|
|
if ! grep -Fxq "$pic" "$photolist"; then
|
|
rm -v "$siteroot/img/thumbs/$pic" "$siteroot/img/$pic"
|
|
fi
|
|
done
|
|
|
|
rm -v "$photolist"
|