Fixes #164 - Add support for title alt semantic metadata.

pull/167/head
Nicolas Perriault 9 years ago
parent eb7ec7231e
commit 6eeabf90c1

@ -906,10 +906,10 @@ Readability.prototype = {
// Match "description", or Twitter's "twitter:description" (Cards)
// in name attribute.
var namePattern = /^\s*((twitter)\s*:\s*)?description\s*$/gi;
var namePattern = /^\s*((twitter)\s*:\s*)?(description|title)\s*$/gi;
// Match Facebook's og:description (Open Graph) in property attribute.
var propertyPattern = /^\s*og\s*:\s*description\s*$/gi;
// Match Facebook's Open Graph title & description properties.
var propertyPattern = /^\s*og\s*:\s*(description|title)\s*$/gi;
// Find description tags.
this._forEachNode(metaElements, function(element) {
@ -949,6 +949,14 @@ Readability.prototype = {
metadata.excerpt = values["twitter:description"];
}
if ("og:title" in values) {
// Use facebook open graph title.
metadata.title = values["og:title"];
} else if ("twitter:title" in values) {
// Use twitter cards title.
metadata.title = values["twitter:title"];
}
return metadata;
},
@ -1708,8 +1716,8 @@ Readability.prototype = {
this._prepDocument();
var articleTitle = this._getArticleTitle();
var metadata = this._getArticleMetadata();
var articleTitle = metadata.title || this._getArticleTitle();
var articleContent = this._grabArticle();
if (!articleContent)

@ -1,5 +1,5 @@
{
"title": "This API is so Fetching! ✩ Mozilla Hacks the Web developer blog",
"title": "This API is so Fetching!",
"byline": "Nikhil Marathe",
"excerpt": "For more than a decade the Web has used XMLHttpRequest (XHR) to achieve asynchronous requests in JavaScript. While very useful, XHR is not a very ...",
"readerable": true

@ -575,4 +575,4 @@ on
</p>
</footer>
</article>
</div>
</div>

@ -1,5 +1,5 @@
{
"title": "Angry media wont buckle over new surveillance laws\n\t\t\t\t\t\t| Herald Sun",
"title": "Angry media wont buckle over new surveillance laws",
"byline": "JOE HILDEBRAND",
"excerpt": "A HIGH-powered federal government team has been doing the rounds of media organisations in the past few days in an attempt to allay concerns about the impact of new surveillance legislation on press freedom. It failed.",
"readerable": true

@ -93,4 +93,4 @@ Supplied</span>
</div>
</div>
</div>
</div>
</div>

@ -1,5 +1,5 @@
{
"title": "Inside the Deep Web Drug Lab — Backchannel — Medium",
"title": "Inside the Deep Web Drug Lab",
"byline": "Joseph Cox",
"excerpt": "Welcome to DoctorXs Barcelona lab, where the drugs you bought online are tested for safety and purity. No questions ask…",
"readerable": true

@ -477,4 +477,4 @@
</p>
</div>
</div>
</div>
</div>

@ -1,5 +1,5 @@
{
"title": "Better Student Journalism — Medium",
"title": "The Open Journalism Project: Better Student Journalism",
"byline": "Pippin Lee",
"excerpt": "We pushed out the first version of the Open Journalism site in January. Heres what weve learned about student journali…",
"readerable": true

@ -374,4 +374,4 @@
</p>
</div>
</div>
</div>

@ -1,5 +1,5 @@
{
"title": "On Behalf of “Literally” — Medium",
"title": "On Behalf of “Literally”",
"byline": "Courtney Kirchoff",
"excerpt": "In defense of the word “literally” and why you or someone you know should stop misusing the word, lest they drive us fig…",
"readerable": true

@ -94,4 +94,4 @@
stopped, or the world will be lost to meaninglessness forever. Figuratively
speaking.</p>
</div>
</div>
</div>

@ -1,5 +1,5 @@
{
"title": "The sharing economy is a lie: Uber, Ayn Rand and the truth about tech\n and libertarians",
"title": "The sharing economy is a lie: Uber, Ayn Rand and the truth about tech and libertarians",
"byline": "Joanna Rothkopf",
"excerpt": "Disruptive companies talk a good game about sharing. Uber's really just an under-regulated company making riches",
"readerable": true

Loading…
Cancel
Save