run.sh (2168B)
1 #!/usr/bin/env sh
2
3 # fetch input config file, fall back to "centre"
4 if [ -z $1 ]; then
5 CONFIG="centre.yaml"
6 else
7 CONFIG="$1"
8 fi
9
10 # Gather various information from config file
11 printf "Gather information from config file...\n"
12 HTML=`grep -E '^\s+file:.*?\.html\s*$' "$CONFIG" | awk '{ print $NF }'`
13 XML=`grep -E '^\s+file:.*?\.xml\s*$' "$CONFIG" | awk '{ print $NF }'`
14 TITLES=`grep -E "^\s*-*\ title:" "$CONFIG" | sed -e 's/^.*title:\ //g'`
15 # URLS=`grep -E "^\s*-*\ url:" "$CONFIG" | sed -e 's/^.*url:\ //g'`
16 WEBS=`grep -E "^\s*-*\ web:" "$CONFIG" | sed -e 's/^.*web:\ //g'`
17 NFEEDS=`echo "$TITLES" | wc -l`
18
19 # Generate site
20 printf "Fetching feeds and generating html...\n"
21 perlanet "$CONFIG"
22
23 # remove images and iframes from article previews
24 printf "Removing images and iframes...\n"
25 sed -E -e 's/<img[^>]*>//g' -e 's/<iframe[^>]*>//g' \
26 -e 's/<figure[^>]*>//g' -e 's/<\/figure>//g' -i "$HTML"
27
28 # remove linebreaks and empty paragraphs
29 printf "Clean up HTML...\n"
30 sed -E -e 's/<br[^a-z]*[^>]*>//g' -e 's/<p[^a-z]*[^>]*><\/p>//g' -i "$HTML"
31
32 # insert link to rss/xml file
33 printf "Inserting RSS feed file...\n"
34 sed -E -e "s/<\!--XML-->/\"$XML\"/" -i "$HTML"
35
36 # insert link to manifest JSON file
37 printf "Inserting manifest file...\n"
38 MANIFEST=`echo "$HTML" | sed -e 's/html/json/'`
39 sed -E -e "s/<\!--MANIFEST-->/\"$MANIFEST\"/" -i "$HTML"
40
41 # insert favicon image buttons
42 # printf "Inserting favicons...\n"
43 # sed -E -e 's/<\!--IMG\ src=\"https:\/\/([^\/]*)[^\"]*(\"[^>]*>)-->/<img src=\"assets\/site-icons\/\1\2 \1/g' -i "$HTML"
44
45 # insert feed domain
46 sed -E \
47 -e 's/<\!--IMG\ src=\"https:\/\/([^\/]+)[^\"]*(\"[^>]*>)-->/\1/g' \
48 -i "$HTML"
49
50 # Insert feeds list
51 printf "Inserting feeds list...\n"
52 FEEDS=""
53 for i in `seq 1 1 $NFEEDS`; do
54 TITLE=`echo "$TITLES" | sed -n "${i},${i}p"`
55 WEB=`echo "$WEBS" | sed -n "${i},${i}p"`
56 FEEDS="$FEEDS<a href=\"$WEB\">$TITLE</a><br>"
57 done
58 FEEDS=`echo "$FEEDS" | sed -e 's/\//\\\\\//g' -ze 's/\n//g'`
59 sed -E -e "s/<\!--FEEDS-->/$FEEDS/" -i "$HTML"
60
61 # Insert Update time
62 printf "Inserting update time...\n"
63 DATE=`date +%c`
64 sed -E -e "s/<\!--UPDATED-->/$DATE/" -i "$HTML"
65
66 # Re-download favicons
67 # ./fetch_favicon.sh "$CONFIG"