Skip to content
This repository has been archived by the owner on Jun 4, 2022. It is now read-only.

Commit

Permalink
Minor webfeed fixes.
Browse files Browse the repository at this point in the history
feed/link may refer to the feed's website, not necessarily it's canonical URL.
Needed to handle relative links.
logic for finding the title was a bit off.
(wasn't needed, but thought it was) double check if what Odysseus recieved is a webfeed.
  • Loading branch information
alcinnz committed Apr 13, 2019
1 parent 5c2bfd7 commit 4663088
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion data/pages/viewers/application/rss+xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<title>{{ feed.title }}</title>
<link rel="alternate" type="{{ mime }}" href="{{ feed.link|default:url }}" />
<link rel="alternate" type="{{ mime }}" href="{{ url }}" />
<base href="{{ url }}" />
<style>
@import url("odysseus:butterick.css");
Expand Down
4 changes: 2 additions & 2 deletions src/Models/Links.vala
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ namespace Odysseus.Model {
this.rel = rel; this.href = href;
}
}
public async Link[] parse_links(uint8[] src) {
public async Link[] parse_links(uint8[] src, string url) {
// Runs a W3C utility to extract additional information WebKit won't
// readily give me.
try {
int stdin;
int stdout;
Process.spawn_async_with_pipes("/",
{"hxwls", "-l"},
{"hxwls", "-lb", url},
null,
SpawnFlags.SEARCH_PATH,
null,
Expand Down
19 changes: 11 additions & 8 deletions src/Traits/status/webfeed.vala
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ namespace Odysseus.Traits {
}

private Gtk.Popover build_subscribe_popover(Gee.List<string> links) {
// FIXME download these so I can determine if they actually are webfeeds,
// If there's a better label, and the best apps to suggest subscribing via.
var grid = new Gtk.Grid();
grid.orientation = Gtk.Orientation.VERTICAL;
var session = FeedRow.build_session();
Expand Down Expand Up @@ -107,10 +105,11 @@ namespace Odysseus.Traits {
var response_text = yield read_stream(response);
var info = new WebFeedParser();
info.parse(response_text);
label.label = info.title;
// TODO do something with info

if (!info.is_webfeed) {destroy(); return;}
label.label = info.title;
populate_subscribe_buttons(link, info.types);

} catch (Error err) {
destroy();
}
Expand Down Expand Up @@ -184,17 +183,21 @@ namespace Odysseus.Traits {
int depth = 0;
public Gee.Set<string> types = new Gee.HashSet<string>();
public string title = "";
bool in_title = true;
bool in_title = false;
public bool is_webfeed = false;

private void visit_start(MarkupParseContext context, string name,
string[] attr_names, string[] attr_values) throws MarkupError {
depth++;
if (strip_ns(name) == "enclosure" || strip_ns(name) == "content") {
if (strip_ns(name) != "channel") depth++;

if (depth == 1 && (strip_ns(name) == "rss" || strip_ns(name) == "feed"))
is_webfeed = true;
else if (strip_ns(name) == "enclosure" || strip_ns(name) == "content") {
for (var i = 0; i < attr_names.length; i++) {
if (strip_ns(attr_names[i]) == "type")
types.add(attr_values[i].split(";", 2)[0]);
}
} else if (depth == 1 && strip_ns(name) == "title") {
} else if (depth == 2 && strip_ns(name) == "title") {
in_title = true;
title = "";
}
Expand Down
2 changes: 1 addition & 1 deletion src/Widgets/WebTab.vala
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public class Odysseus.WebTab : Granite.Widgets.Tab {
private async void parse_links(Cancellable? cancellable = null) {
try {
var source = yield web.get_main_resource().get_data(cancellable);
var links = yield Model.parse_links(source);
var links = yield Model.parse_links(source, url);

links_parsed(links, indicators);
indicators_loaded(indicators);
Expand Down

0 comments on commit 4663088

Please sign in to comment.