Skip to content

Commit

Permalink
Now correctly reading content from HTML and offering CSS as content. F…
Browse files Browse the repository at this point in the history
…ixes #162
  • Loading branch information
remy committed Jul 13, 2012
1 parent 9803e31 commit 42fab8c
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/utils.js
Expand Up @@ -129,30 +129,37 @@ module.exports = {
title: /<title>(.*)<\/title>/
},
titleForBin: function (bin) {
// TODO: Use HTML parser or JSDOM
var html = (bin.html || '').replace(this.re.flatten, ' '), // flatten
javascript = (bin.javascript || '').replace(this.re.flatten, ' ').trim(),
css = (bin.css || '').replace(this.re.flatten, ' ').trim(),
matches = (html.match(this.re.meta) || []);

// try to return the meta[description] first
if (matches.length === 2 && matches[1].trim()) {
return matches[1];
}

matches = (html.match(this.re.body) || []);
// then some of the body content with tags stripped
matches = (html.match(this.re.body) || [,''])[1].replace(this.re.tags, '').trim();

if (matches.length === 2 && matches[1].trim()) {
return matches[1].replace(this.re.tags, '').trim();
if (matches) {
return matches;
}

// No title return JavaScript.
if (javascript) {
return javascript;
}

if (css) {
return css;
}

matches = (html.match(this.re.title) || []);
if (matches.length === 2 && matches[1].trim()) {
return matches[1];
}

return '';
},
since: function (date) {
Expand Down

0 comments on commit 42fab8c

Please sign in to comment.