Skip to content
This repository has been archived by the owner on Nov 3, 2018. It is now read-only.

Commit

Permalink
Preview link improvements. Closes #32. Closes #31
Browse files Browse the repository at this point in the history
  • Loading branch information
hueniverse committed Jun 8, 2016
1 parent eeb19eb commit dc66751
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 27 deletions.
30 changes: 17 additions & 13 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const Url = require('url');
const Content = require('content');
const Hoek = require('hoek');
const Items = require('items');
const Joi = require('joi');
const Wreck = require('wreck');
const Oembed = require('./oembed');
const Ogp = require('./ogp');
Expand All @@ -18,26 +19,28 @@ const Utils = require('./utils');

// Declare internals

const internals = {
defaults: {
// maxWidth: 100,
// maxHeight: 100,
maxSize: false,
providers: true,
whitelist: null,
preview: true,
css: false
}
};
const internals = {};


exports.oembed = { providers: Oembed.providers };


internals.schema = Joi.object({
maxWidth: Joi.number().integer().min(1),
maxHeight: Joi.number().integer().min(1),
maxSize: Joi.number().integer().min(1).allow(false).default(false),
providers: Joi.array().allow(true, false).default(true),
whitelist: Joi.array().items(Joi.string()).min(1),
preview: Joi.func().allow(true, false).default(true),
css: Joi.string().allow(false),
redirect: Joi.string()
});


exports.Engine = class {
constructor(options) {

this.settings = Hoek.applyToDefaults(internals.defaults, options || {});
this.settings = Joi.attempt(options || {}, internals.schema);
if (this.settings.providers === true) {
this.settings.providers = Providers;
}
Expand Down Expand Up @@ -265,6 +268,7 @@ internals.preview = function (description, options, callback) {

const icon = (description.icon ? description.icon.smallest : '');
const image = internals.image(description, options);
const url = (options.redirect ? `${options.redirect}${encodeURIComponent(description.url)}` : description.url);
const html = `
<!DOCTYPE html>
<html>
Expand All @@ -277,7 +281,7 @@ internals.preview = function (description, options, callback) {
<div class='metaphor-embed-header'>
${icon ? '<img class="metaphor-embed-header-icon" src="' + icon + '"/>' : '<div class="metaphor-embed-header-icon-missing"></div>'}
<div class="metaphor-embed-header-site">${description.site_name}</div>
<a class="metaphor-embed-header-link" href="${description.url}">
<a class="metaphor-embed-header-link" href="${url}" target="_blank">
<div class="metaphor-embed-header-title">${description.title || description.url}</div>
</a>
</div>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "metaphor",
"description": "Open Graph, Twitter Card, and oEmbed Metadata Collector",
"version": "3.3.3",
"version": "3.4.0",
"repository": "git://github.com/hueniverse/metaphor",
"main": "lib/index.js",
"keywords": [
Expand Down
Loading

0 comments on commit dc66751

Please sign in to comment.