commit 6df391bcd6dc4cd03349907400d98e6445211f66
parent db5ffcaa8c133d249aafa4a64f3d827dd513d995
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Fri, 3 Aug 2012 14:57:22 +0200
Add base url of a site parameter for sfeedrc
This allows to have a feed on a different domain but specify the base
url of links if links in the feed are relative.
Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
Diffstat:
6 files changed, 21 insertions(+), 12 deletions(-)
diff --git a/common.c b/common.c
@@ -6,7 +6,7 @@
enum { FieldUnixTimestamp = 0, FieldTimeFormatted, FieldTitle, FieldLink,
FieldContent, FieldContentType, FieldId, FieldAuthor, FieldFeedType,
- FieldFeedName, FieldFeedUrl, FieldLast };
+ FieldFeedName, FieldFeedUrl, FieldBaseSiteUrl, FieldLast };
const int FieldSeparator = '\t';
diff --git a/sfeed_html.c b/sfeed_html.c
@@ -183,7 +183,10 @@ main(void) {
fputs("<b><u>", stdout);
if(islink) {
fputs("<a href=\"", stdout);
- printlink(fields[FieldLink], fields[FieldFeedUrl]);
+ if(fields[FieldBaseSiteUrl][0] != '\0')
+ printlink(fields[FieldLink], fields[FieldBaseSiteUrl]);
+ else
+ printlink(fields[FieldLink], fields[FieldFeedUrl]);
fputs("\">", stdout);
}
printhtmlencoded(fields[FieldTitle]);
diff --git a/sfeed_plain.c b/sfeed_plain.c
@@ -34,7 +34,10 @@ main(void) {
fputs(" ", stdout);
printutf8padded(fields[FieldTitle], 70);
fputs(" ", stdout);
- printlink(fields[FieldLink], fields[FieldFeedUrl]);
+ if(fields[FieldBaseSiteUrl][0] != '\0')
+ printlink(fields[FieldLink], fields[FieldBaseSiteUrl]);
+ else
+ printlink(fields[FieldLink], fields[FieldFeedUrl]);
putchar('\n');
}
free(line);
diff --git a/sfeed_update b/sfeed_update
@@ -65,15 +65,15 @@ addfield() {
}
# fetch and parse feed.
-# feed(name, url, encoding)
+# feed(name, feedurl, basesiteurl, [encoding])
feed() {
tmpfile=$(mktemp -p "$TMPDIR")
- (if [ "$3" = "" ]; then
+ (if [ "$4" = "" ]; then
# don't use iconv if encoding not set in config.
- fetchfeed "$2" "$1" | sfeed | addfield "$1 $2"
+ fetchfeed "$2" "$1" | sfeed | addfield "$1 $2 $3"
else
# use iconv to convert encoding to UTF-8.
- fetchfeed "$2" "$1" | iconv -cs -f "$3" -t "utf-8" | sfeed | addfield "$1 $2"
+ fetchfeed "$2" "$1" | iconv -cs -f "$4" -t "utf-8" | sfeed | addfield "$1 $2 $3"
fi) > "$tmpfile"
}
diff --git a/sfeed_update.1 b/sfeed_update.1
@@ -48,6 +48,9 @@ string (extra field added by sfeed_update)
.TP
.B feed url
string (extra field added by sfeed_update)
+.TP
+.B item baseurl site
+string (extra field added by sfeed_update)
.SH FILES READ
.TP
.B sfeedrc
diff --git a/sfeedrc.example b/sfeedrc.example
@@ -6,12 +6,12 @@
# list of feeds to fetch:
feeds() {
- # feed <name> <url> [encoding]
+ # feed <name> <feedurl> <basesiteurl> [encoding]
feed "codemadness" "http://www.codemadness.nl/blog/rss.xml"
feed "explosm" "http://feeds.feedburner.com/Explosm"
- feed "linux kernel" "http://kernel.org/kdist/rss.xml" "iso-8859-1"
+ feed "linux kernel" "http://kernel.org/kdist/rss.xml" "http://kernel.org" "iso-8859-1"
feed "phoronix" "http://feeds.feedburner.com/Phoronix"
- feed "slashdot" "http://rss.slashdot.org/Slashdot/slashdot"
- feed "tweakers" "http://feeds.feedburner.com/tweakers/mixed" "iso-8859-1"
- feed "xkcd" "http://xkcd.com/atom.xml"
+ feed "slashdot" "http://rss.slashdot.org/Slashdot/slashdot" "http://slashdot.org"
+ feed "tweakers" "http://feeds.feedburner.com/tweakers/mixed" "http://tweakers.net" "iso-8859-1"
+ feed "xkcd" "http://xkcd.com/atom.xml" "http://xkcd.com"
}