forked from itteco/iframely
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathted.com.js
70 lines (55 loc) · 2.18 KB
/
ted.com.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const cheerio = require('cheerio');
const URL = require("url");
module.exports = {
re: /^https?:\/\/(?:www\.)?ted\.com\/talks\//i,
provides: [
"oembedLinks"
],
mixins: [
"og-image",
"oembed-thumbnail",
"favicon",
"oembed-author",
"oembed-canonical",
"oembed-description",
"keywords",
"oembed-site",
"oembed-title"
],
getLink: function(oembed, url, options) {
var $container = cheerio('<div>');
try {
$container.html(oembed.html);
} catch (ex) {}
var $iframe = $container.find('iframe');
if ($iframe.length == 1) {
var query = URL.parse(url,true).query;
var lang = query.language || query.nolanguage;
return {
type: CONFIG.T.text_html,
rel:[CONFIG.R.oembed, CONFIG.R.player, CONFIG.R.html5, CONFIG.R.ssl],
href: lang ? $iframe.attr('src').replace(/\/lang\/\w+\//i, '/').replace(/\/talks\//i, '/talks/lang/' + lang.toLowerCase() + '\/') : $iframe.attr('src'),
"aspect-ratio": oembed.width / oembed.height
}
}
},
getData: function(url, meta, options, cb) {
var query = URL.parse(url,true).query;
var lang = (options.getProviderOptions('locale') && options.getProviderOptions('locale').replace(/(\_|\-)\w+$/i, '')) || query.language;
var is_valid_lang = lang && meta.alternate && meta.alternate instanceof Array && meta.alternate.some(function(link) {
return typeof link.indexOf === 'function' && link.indexOf('language='+lang) > -1;
});
cb (null, {oembedLinks: [{
href: 'http://www.ted.com/services/v1/oembed.json?url=' + encodeURIComponent(meta.canonical) + (is_valid_lang ? '&language=' + lang : ''),
rel: 'alternate',
type: 'application/json+oembed'
}]
});
},
tests: [{
page: "http://www.ted.com/talks",
selector: "#browse-results a"
}, {skipMethods: ['getData']},
"http://www.ted.com/talks/kent_larson_brilliant_designs_to_fit_more_people_in_every_city"
]
};