run.sh (2920B)
1 #!/usr/bin/env bash
2 # SPDX-License-Identifier: AGPL-3.0-or-later
3 # SPDX-FileCopyrightText: 2024-2025 JayVii <jayvii[AT]posteo[DOT]de>
4
5 # fetch input config file, fall back to "centre"
6 if [ -z $1 ]; then
7 for conf in $(find ./perlanetrc/ -type f | sort -r); do ${0} "$conf"; done
8 exit 0;
9 else
10 config="$1"
11 fi
12
13 # Gather various information from config file
14 printf "Gather information from ${config}...\n"
15 source "./scripts/yaml.sh" > /dev/null
16 eval "$(parse_yaml ${config})"
17
18 # Generate site
19 printf "Fetching feeds and generating html...\n"
20 perlanet "$config"
21
22 # remove images and iframes from article previews
23 printf "Removing images and iframes...\n"
24 sed -E -e 's/<img[^>]*>//g' -e 's/<iframe[^>]*>//g' \
25 -e 's/<figure[^>]*>//g' -e 's/<\/figure>//g' -i "$page_file"
26
27 # remove linebreaks and empty paragraphs as well as inline-links ("more...")
28 printf "Clean up HTML...\n"
29 sed -E \
30 -e 's/<br[^a-z]*[^>]*>//g' \
31 -e 's/<p[^a-z]*[^>]*><\/p>//g' \
32 -e 's/<a\ [^<]+<\/a><\!--end-->/<\!--end-->/g' \
33 -i "$page_file"
34
35 # insert link to rss/xml file
36 printf "Inserting RSS feed file...\n"
37 sed -E -e "s/<\!--XML-->/$feed_file/g" -i "$page_file"
38
39 # insert link to opml/xml file
40 printf "Inserting OPML feed file...\n"
41 sed -E -e "s/<\!--OPML-->/$opml_file/g" -i "$page_file"
42
43 # insert link to manifest JSON file
44 printf "Inserting manifest file...\n"
45 manifest_file=$(echo "$manifest_file" | sed -e 's/\//\\\//g')
46 sed -E -e "s/<\!--MANIFEST-->/$manifest_file/" -i "$page_file"
47
48 # insert feed domains
49 sed -E \
50 -e 's/<\!--DOMAIN\ src=\"https:\/\/([^\/]+)[^\"]*(\"[^>]*>)-->/\1/g' \
51 -i "$page_file"
52
53 # Insert feeds list
54 # printf "Inserting feeds list...\n"
55 # feeds="<ul>"
56 # for i in $(seq 0 1 $((${#feeds__title[@]} - 1))); do
57 # feeds="${feeds}<li><a rel=\"nofollow\" target=\"_blank\" href=\"${feeds__web[$i]}\">${feeds__title[$i]}</a></li>"
58 # done
59 # feeds=`echo "${feeds}</ul>" | sed -e 's/\//\\\\\//g' -ze 's/\n//g'`
60 # sed -E -e "s/<\!--FEEDS-->/$feeds/" -i "$page_file"
61
62 # Insert Update time
63 printf "Inserting update time...\n"
64 now=`date +%c`
65 sed -E -e "s/<\!--UPDATED-->/${now}/" -i "$page_file"
66
67 # mark posts older than threshold as "inactive"
68 printf "Mark older posts as inactive...\n"
69 dates=$(grep "<section data=" $page_file | sed -E -e 's/^.*?"([^"]+)".*$/\1/g')
70 now=$(date +%s)
71 for date in $dates; do
72 secs=$(date +%s --date "$date")
73 if [ $(($now - $secs)) -gt $entries_age ]; then
74 sed -E -e "s/(<section data=\"$date\")/\1 class=\"inactive\"/g" \
75 -i $page_file
76 fi
77 done
78
79 # insert important feed at the top
80 if [ ! -z $sub_feed_file ]; then
81 printf "Insert sub-feed if there are active entries...\n"
82 if [ $(grep "<section" $sub_feed_file | grep -cv "inactive") -gt 0 ]; then
83 sub_feed_injection="<blockquote><strong>$sub_feed_title<\/strong><iframe class=\"subfeed\" src=\"$sub_feed_file\"><\/iframe><\/blockquote>"
84 sed -e "s/<\!--SUBFEED-->/$sub_feed_injection/g" -i $page_file
85 fi
86 fi