From abc0b5bccb0029c2e14d3cf1d304945480bc27d3 Mon Sep 17 00:00:00 2001 From: Jokler Date: Thu, 22 Mar 2018 21:23:58 +0100 Subject: Let the Url plugin check for og:titles --- src/plugins/url.rs | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/plugins/url.rs b/src/plugins/url.rs index df3329a..ec98900 100644 --- a/src/plugins/url.rs +++ b/src/plugins/url.rs @@ -35,6 +35,28 @@ impl Url { Some(captures.get(2)?.as_str().to_owned()) } + + fn get_ogtitle<'a>(&self, body: &str) -> Result { + let title = body.find("property=\"og:title\"") + .map(|tag| { + body[tag..] + .find("content=\"") + .map(|offset| tag + offset + 9) + .map(|start| { + body[start..] + .find("\"") + .map(|offset| start + offset) + .map(|end| &body[start..end]) + }) + }) + .and_then(|s| s.and_then(|s| s)) + .ok_or(ErrorKind::MissingTitle)?; + + debug!("Title: {:?}", title); + + htmlescape::decode_html(title).map_err(|_| ErrorKind::HtmlDecoding.into()) + } + fn get_title<'a>(&self, body: &str) -> Result { let title = body.find(" t, + Err(e) => if e.kind() == ErrorKind::MissingTitle { + self.get_title(&body)? + } else { + Err(e)? + } + }; Ok(title.trim().replace('\n', "|").replace('\r', "|")) } -- cgit v1.2.3-70-g09d2