Fetch page titles

This commit is contained in:
Mattias Erming 2014-09-27 13:39:14 -07:00
parent 2a00fb1bb6
commit 3a28afe408
4 changed files with 41 additions and 21 deletions

View File

@ -574,7 +574,7 @@ button {
content: '* ';
}
#chat .toggle-button {
background: #eee;
background: #f5f5f5;
border-radius: 2px;
display: inline-block;
color: #666;
@ -588,16 +588,27 @@ button {
display: none;
color: #222;
font: 12px Lato;
max-width: 220px;
max-width: 480px;
padding: 6px 8px;
margin-top: 2px;
}
#chat .toggle-content.show {
display: inline-block !important;
#chat .toggle-content a {
color: inherit;
}
#chat .toggle-content img {
max-width: 100%;
max-height: 100%;
display: block;
margin: 2px 0;
}
#chat .toggle-content .head {
font-weight: bold;
}
#chat .toggle-content .body {
color: #999;
}
#chat .toggle-content.show {
display: inline-block !important;
}
#chat .count {
background: #fafafa;

View File

@ -130,17 +130,19 @@ templates['network'] = template({"1":function(depth0,helpers,partials,data) {
templates['toggle'] = template({"1":function(depth0,helpers,partials,data) {
var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;
return " <a href=\""
+ escapeExpression(((helper = (helper = helpers.body || (depth0 != null ? depth0.body : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"body","hash":{},"data":data}) : helper)))
+ escapeExpression(((helper = (helper = helpers.link || (depth0 != null ? depth0.link : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"link","hash":{},"data":data}) : helper)))
+ "\" target=\"_blank\">\n <img src=\""
+ escapeExpression(((helper = (helper = helpers.body || (depth0 != null ? depth0.body : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"body","hash":{},"data":data}) : helper)))
+ escapeExpression(((helper = (helper = helpers.link || (depth0 != null ? depth0.link : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"link","hash":{},"data":data}) : helper)))
+ "\">\n </a>\n";
},"3":function(depth0,helpers,partials,data) {
var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;
return " <div class=\"head\">"
+ escapeExpression(((helper = (helper = helpers.head || (depth0 != null ? depth0.head : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"head","hash":{},"data":data}) : helper)))
+ "</div>\n <div class=\"body\">\n "
var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, buffer = " <a href=\""
+ escapeExpression(((helper = (helper = helpers.link || (depth0 != null ? depth0.link : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"link","hash":{},"data":data}) : helper)))
+ "\" target=\"_blank\">\n <div class=\"head\">";
stack1 = ((helper = (helper = helpers.head || (depth0 != null ? depth0.head : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"head","hash":{},"data":data}) : helper));
if (stack1 != null) { buffer += stack1; }
return buffer + "</div>\n <div class=\"body\">\n "
+ escapeExpression(((helper = (helper = helpers.body || (depth0 != null ? depth0.body : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"body","hash":{},"data":data}) : helper)))
+ "\n </div>\n";
+ "\n </div>\n </a>\n";
},"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
var stack1, helperMissing=helpers.helperMissing, buffer = "<div class=\"toggle-content\">\n";
stack1 = ((helpers.equal || (depth0 && depth0.equal) || helperMissing).call(depth0, (depth0 != null ? depth0.type : depth0), "image", {"name":"equal","hash":{},"fn":this.program(1, data),"inverse":this.program(3, data),"data":data}));

View File

@ -1,13 +1,15 @@
<div class="toggle-content">
{{#equal type "image"}}
<a href="{{body}}" target="_blank">
<img src="{{body}}">
<a href="{{link}}" target="_blank">
<img src="{{link}}">
</a>
{{else}}
<div class="head">{{head}}</div>
<a href="{{link}}" target="_blank">
<div class="head">{{{head}}}</div>
<div class="body">
{{body}}
</div>
</a>
{{/equal}}
</div>
</div>

View File

@ -1,4 +1,5 @@
var _ = require("lodash");
var cheerio = require("cheerio");
var Msg = require("../../models/msg");
var request = require("superagent");
@ -43,12 +44,16 @@ module.exports = function(irc, network) {
};
function parse(id, url, res, client) {
var type = "";
var head = "";
var body = "";
var type = "";
var link = url;
switch (res.type) {
case "text/html":
var $ = cheerio.load(res.res.text);
type = "link";
head = $("title").text();
body = "No description found.";
break;
case "image/png":
@ -56,7 +61,6 @@ function parse(id, url, res, client) {
case "image/jpg":
case "image/jpeg":
type = "image";
body = url;
break;
default:
@ -65,8 +69,9 @@ function parse(id, url, res, client) {
client.emit("toggle", {
id: id,
type: type,
head: type,
body: body
head: head,
body: body,
link: link,
});
}