summaryrefslogtreecommitdiff
path: root/sfeed_opml_export
blob: 212b3c6e7d028b85b91a7851c1642b9f21ddb6c0 (plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/sh

# load config (evaluate shellscript).
# loadconfig(configfile)
loadconfig() {
	# allow to specify config via argv[1].
	if [ ! x"$1" = x"" ]; then
		# get absolute path of config file.
		config=$(readlink -f "$1")
	else
		# default config location.
		config="$HOME/.sfeed/sfeedrc"
	fi

	# load config: config is loaded here to be able to override above variables
	# (sfeedpath, sfeedfile, etc).
	if [ -r "$config" ]; then
		. "$config"
	else
		echo "Configuration file \"$config\" does not exist or is not readable." >&2
		exit 1
	fi
}

# escape(s)
escape() {
	printf '%s' "$1" | sed 's@"@\"@g'
}

# override feeds function to ouput opml XML.
# feed(name, feedurl, [basesiteurl], [encoding])
feed() {
	name=$(escape "$1")
	xmlurl=$(escape "$2")
	htmlurl=$(escape "$3")

	printf '\t<outline title="%s" text="%s" xmlUrl="%s" htmlUrl="%s"/>\n' \
		"${name}" "${name}" "${xmlurl}" "${htmlurl}"
}

# load config file.
loadconfig "$1"

cat <<!
<?xml version="1.0" encoding="UTF-8"?>
<opml version="1.0">
<head>
	<title>opml export from sfeed</title>
</head>
<body>
!

feeds
# wait till all items are processed (concurrently).
wait

cat <<!
</body>
</opml>
!