@@ -22,7 +22,8 @@ type t = {
2222 feed : Feed .t ;
2323 author : string ;
2424 email : string ;
25- description : Nethtml .document list ;
25+ content : Nethtml .document list ;
26+ mutable link_response : (string , string ) result option ;
2627}
2728
2829let rec len_prefix_of_html html len =
@@ -167,7 +168,7 @@ let post_of_atom ~(feed : Feed.t) (e : Syndic.Atom.entry) =
167168 let date =
168169 match e.published with Some _ -> e.published | None -> Some e.updated
169170 in
170- let description =
171+ let content =
171172 match e.content with
172173 | Some (Text s ) -> html_of_text s
173174 | Some (Html (xmlbase , s )) -> html_of_text ?xmlbase s
@@ -187,18 +188,21 @@ let post_of_atom ~(feed : Feed.t) (e : Syndic.Atom.entry) =
187188 feed;
188189 author = author.name;
189190 email = " " ;
190- description;
191+ content;
192+ link_response = None ;
191193 }
192194
193195let post_of_rss2 ~(feed : Feed.t ) it =
194- let title, description =
196+ let title, content =
195197 match it.Syndic.Rss2. story with
196198 | All (t , xmlbase , d ) -> (
197199 ( t,
198200 match it.content with
199201 | _ , "" -> html_of_text ?xmlbase d
200202 | xmlbase , c -> html_of_text ?xmlbase c ))
201- | Title t -> (t, [] )
203+ | Title t ->
204+ let xmlbase, c = it.content in
205+ (t, html_of_text ?xmlbase c)
202206 | Description (xmlbase , d ) -> (
203207 ( " " ,
204208 match it.content with
@@ -221,8 +225,9 @@ let post_of_rss2 ~(feed : Feed.t) it =
221225 feed;
222226 author = feed.name;
223227 email = string_of_option it.author;
224- description ;
228+ content ;
225229 date = it.pubDate;
230+ link_response = None ;
226231 }
227232
228233let posts_of_feed c =
@@ -237,7 +242,7 @@ let string_of_html html =
237242 Buffer. contents buffer
238243
239244let mk_entry post =
240- let content = Syndic.Atom. Html (None , string_of_html post.description ) in
245+ let content = Syndic.Atom. Html (None , string_of_html post.content ) in
241246 let contributors =
242247 [ Syndic.Atom. author ~uri: (Uri. of_string post.feed.url) post.feed.name ]
243248 in
@@ -271,3 +276,18 @@ let get_posts ?n ?(ofs = 0) planet_feeds =
271276 let posts = List. sort post_compare posts in
272277 let posts = remove ofs posts in
273278 match n with None -> posts | Some n -> take n posts
279+
280+ (* Fetch the link response and cache it. *)
281+ let fetch_link t =
282+ match (t.link, t.link_response) with
283+ | None , _ -> None
284+ | Some _ , Some (Ok x ) -> Some x
285+ | Some _ , Some (Error _ ) -> None
286+ | Some link , None -> (
287+ try
288+ let response = Http. get (Uri. to_string link) in
289+ t.link_response < - Some (Ok response);
290+ Some response
291+ with _exn ->
292+ t.link_response < - Some (Error " " );
293+ None )
0 commit comments