-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeedscan
executable file
·43 lines (38 loc) · 955 Bytes
/
feedscan
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash
# Feedscan checks common feed suffixes for a webpage.
#
# Usage:
# feedscan [url]
#
# Examples:
# feedscan lukasschwab.me/blog
# feedscan lukasschwab.me/blog/
# feedscan http://lukasschwab.me/blog/
# feedscan https://lukasschwab.me/blog/
base="$1"
if [ "${base: -1}" != "/" ]; then
base="$base/"
fi
# TODO: grep for application/rss+xml; sometimes feed links are lodged in HTML
# <head> elements.
check () {
local httpStatus=$(curl -Is --write-out %{http_code} --output /dev/null "$1");
local class=$(($httpStatus / 100))
case $class in
2)
blog info "$httpStatus: $1";;
1|3|5)
blog warn "$httpStatus: $1";;
4)
blog error "$httpStatus: $1";;
esac
}
slugs=("atom" "rss" "feed")
for slug in "${slugs[@]}"; do
check "${base}${slug}"
check "${base}${slug}.xml"
done
# Check common non-XML cases for good measure.
check "${base}feed.atom"
check "${base}feed.json"
check "${base}?format=rss"