commit 025b991d00090658af58bbe506a4be82b3ef1a9b
parent f5b0e3ae7e573c35b61d93a1e33a8a0f06a40e2c
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date: Sat, 12 Apr 2025 19:27:30 +0200
feat: do not display duplicates
Diffstat:
5 files changed, 52 insertions(+), 23 deletions(-)
diff --git a/assets/css/custom.css b/assets/css/custom.css
@@ -38,14 +38,19 @@ p {
{
display: none;
}
-/* inactive class */
-.inactive {
+/* inactive posts */
+*[data-inactive="true"] {
opacity: 0.5;
}
-.inactive:hover,
-.inactive:focus {
+*[data-inactive="true"]:hover,
+*[data-inactive="true"]:focus
+{
opacity: 1.0;
}
+/* duplicated posts */
+*[data-duplicate="true"] {
+ display: none;
+}
/* Span tables across thw whole width */
table {
width: 100%;
diff --git a/assets/css/mini.css b/assets/css/mini.css
@@ -0,0 +1,12 @@
+/* less padding and margins around sections */
+section {
+ margin-top: 0px;
+ margin-bottom: 1em;
+ padding-bottom: 1em;
+}
+
+/* inactive items should not be displayed */
+*[data-inactive="true"] {
+ display: none;
+}
+
diff --git a/scripts/run.sh b/scripts/run.sh
@@ -43,10 +43,10 @@ for i in $(seq 0 1 $((${#start_lines[@]} - 1))); do
done
done
# re-apply <!--start--> / <!--end--> comments
-sed -E \
- -e "${start_lines[0]}s/^/<\!--start\-\->/g" \
- -e "${stop_lines[0]}s/$/<\!--end-->/g" \
- -i "$page_file"
+# sed -E \
+# -e "${start_lines[0]}s/^/<\!--start\-\->/g" \
+# -e "${stop_lines[0]}s/$/<\!--end-->/g" \
+# -i "$page_file"
# insert link to rss/xml file
printf "Inserting RSS feed file...\n"
@@ -82,13 +82,30 @@ sed -E -e "s/<\!--UPDATED-->/${now}/" -i "$page_file"
# mark posts older than threshold as "inactive"
printf "Mark older posts as inactive...\n"
-dates=$(grep "<section data=" $page_file | sed -E -e 's/^.*?"([^"]+)".*$/\1/g')
+dates=$(grep -e "data-inactive=" $page_file | sed -E -e 's/^.*data-inactive="([^"]+)".*$/\1/g' | uniq)
now=$(date +%s)
for date in $dates; do
secs=$(date +%s --date "$date")
if [ $(($now - $secs)) -gt $entries_age ]; then
- sed -E -e "s/(<section data=\"$date\")/\1 class=\"inactive\"/g" \
- -i $page_file
+ sed -E -e "s/(data-inactive=\")$date(\".*)/\1true\2/" -i $page_file
+ fi
+done
+
+# mark doubled posts as non-visible
+printf "Remove duplicated posts...\n"
+post_ids=$(
+ grep "data-duplicate=" $page_file | \
+ sed -E -e 's/^.*(data-duplicate="[^"]+").*/\1/g' -e 's/(\/|\?)/\\\1/g' | \
+ uniq
+)
+for pid in $post_ids; do
+ # check whether post-id appears multiple times
+ if [ $(grep "$pid" -c $page_file) -gt 1 ]; then
+ # if it does, mark all, except for the last one as duplicate
+ lines=$(grep -n "$pid" $page_file | head -n -1 | sed -e 's/:.*//g')
+ for line in $lines; do
+ sed -E -e "${line}s/${pid}/data-duplicate=\"true\"/" -i $page_file
+ done
fi
done
diff --git a/templates/index.tt b/templates/index.tt
@@ -80,7 +80,10 @@
<!-- Content Entries -->
[% FOREACH entry IN feed.entries %]
- <section data="[% entry.issued | html %]">
+ <section
+ data-inactive="[% entry.issued | html %]"
+ data-duplicate="[% entry.link | url | html %]"
+ >
<!-- Headline -->
<h3 style="margin-bottom:5px;">
<a href="[% entry.link | url | html %]"
diff --git a/templates/mini.tt b/templates/mini.tt
@@ -28,18 +28,9 @@
<link rel="apple-touch-icon" href="assets/favicon.png">
<link rel="stylesheet" type="text/css" href="assets/css/simple.min.css">
<link rel="stylesheet" type="text/css" href="assets/css/custom.css">
+ <link rel="stylesheet" type="text/css" href="assets/css/mini.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="robots" content="noindex">
- <style>
- section {
- margin-top: 0px;
- margin-bottom: 1em;
- padding-bottom: 1em;
- }
- .inactive {
- display: none;
- }
- </style>
</head>
<body>
@@ -48,7 +39,8 @@
<!-- Content Entries -->
[% FOREACH entry IN feed.entries %]
- <section data="[% entry.issued | html %]">
+ <section data-inactive="[% entry.issued | html %]">
+
<a
target="_blank"
rel="nofollow ugc"