Add page numbers to top of page, use mktemp(1) for temp files

This commit is contained in:
tim 2024-07-31 11:49:37 +09:30
parent a37c16ff4e
commit 8eea7fc1b5
1 changed files with 14 additions and 9 deletions

View File

@ -7,7 +7,7 @@ noodspp=40
mkdir -p "$siteroot/img/thumbs" mkdir -p "$siteroot/img/thumbs"
pageno=1 pageno=1
noodcount=1 noodcount=1
photolist="$(mktemp --suffix='.txt')"
# html and css stolen from https://perfectmotherfuckingwebsite.com/ # html and css stolen from https://perfectmotherfuckingwebsite.com/
pageheader='''<!DOCTYPE html> pageheader='''<!DOCTYPE html>
@ -57,13 +57,14 @@ a.button{
</head> </head>
<body> <body>
<h1>2minNoods</h1> <h1>2minNoods</h1>
<hr>''' <hr>
<!--pageno-->'''
rm -v "$siteroot"/index.*.html rm -v "$siteroot"/index.*.html
echo '<meta http-equiv="refresh" content="0; url=index.1.html" />' > "$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" ls *.jpg | sort -k2 -t'_' -r > "$photolist"
while read i; do while read i; do
if [ -f "$i" ]; then if [ -f "$i" ]; then
@ -82,26 +83,30 @@ while read i; do
noodcount=1 noodcount=1
fi fi
fi fi
done < "$siteroot/photolist.txt" done < "$photolist"
for ((page=1;page<=pageno;page++)); do for ((page=1;page<=pageno;page++)); do
echo -n '<div class="page-links">' >> "$siteroot/index.$page.html" htmlpagenumbers=$(
echo -n '<div class="page-links">'
for ((link=1;link<=pageno;link++)); do for ((link=1;link<=pageno;link++)); do
if [ $link -eq $page ]; then if [ $link -eq $page ]; then
echo -n "$link " echo -n "$link "
else else
echo -n "<a class=\"button\" href=\"index.$link.html\">$link</a> " echo -n "<a class=\"button\" href=\"index.$link.html\">$link</a> "
fi fi
done >> "$siteroot/index.$page.html" done
echo '</div></body></html>' >> "$siteroot/index.$page.html" 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 done
echo "Searching for deleted images" echo "Searching for deleted images"
for i in $siteroot/img/*.jpg; do for i in $siteroot/img/*.jpg; do
pic="$(basename $i)" pic="$(basename $i)"
if ! grep -Fxq "$pic" "$siteroot/photolist.txt"; then if ! grep -Fxq "$pic" "$photolist"; then
rm -v "$siteroot/img/thumbs/$pic" "$siteroot/img/$pic" rm -v "$siteroot/img/thumbs/$pic" "$siteroot/img/$pic"
fi fi
done done
rm -v "$siteroot/photolist.txt" rm -v "$photolist"