run.sh (1536B)
1 #!/usr/bin/env sh
2
3 # fetch input config file, fall back to "general"
4 if [ -z $1 ]; then
5 CONFIG="general.yaml"
6 else
7 CONFIG="$1"
8 fi
9
10 # Generate site
11 printf "Fetching feeds and generating html...\n"
12 perlanet "$CONFIG"
13
14 # fetch name of resulting html file
15 HTML=`grep -E '^\s+file:.*?\.html\s*$' "$CONFIG" | awk '{ print $NF }'`
16
17 # fetch name of resulting xml file
18 XML=`grep -E '^\s+file:.*?\.xml\s*$' "$CONFIG" | awk '{ print $NF }'`
19
20 # insert link to rss/xml file
21 sed -E -e "s/<!--XML-->/\"$XML\"/" -i "$HTML"
22
23 # insert link to manifest JSON file
24 MANIFEST=`echo "$HTML" | sed -e 's/html/json/'`
25 sed -E -e "s/<!--MANIFEST-->/\"$MANIFEST\"/" -i "$HTML"
26
27 # remove images and iframes from article previews
28 printf "Removing images and iframes...\n"
29 sed -E -e 's/<img[^>]*>//g' -e 's/<iframe[^>]*>//g' \
30 -e 's/<figure[^>]*>//g' -e 's/<\/figure>//g' -i "$HTML"
31
32 # remove linebreaks and empty paragraphs
33 printf "Clean up HTML...\n"
34 sed -E -e 's/<br[^a-z]*[^>]*>//g' -e 's/<p[^a-z]*[^>]*><\/p>//g' -i "$HTML"
35
36 # insert favicon image buttons
37 printf "Insert favicons...\n"
38 sed -E -e 's/<!--IMG\ src=\"(https:\/\/[^\/]*)[^\"]*(\"[^>]*>)-->/<img src=\"\1\/favicon.ico\2/g' -i "$HTML"
39
40 # Insert feeds list
41 printf "Inserting feeds list...\n"
42 FEEDS=`
43 grep -E '^\s*web:' "$CONFIG" | \
44 awk '{ print "<a href=\""$NF"\">"$NF"</a><br>" }' | \
45 sed -e 's/\//\\\\\//g' -ze's/\n//g'
46 `
47 sed -E -e "s/<!--FEEDS-->/$FEEDS/" -i "$HTML"
48
49 # Insert Update time
50 printf "Inserting update time...\n"
51 DATE=`date +%c`
52 sed -E -e "s/<!--UPDATED-->/$DATE/" -i "$HTML"