forked from itteco/iframely
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docs.google.com.js
123 lines (92 loc) · 4.09 KB
/
docs.google.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
module.exports = {
provides: "schemaFileObject",
re: [
/https:\/\/(?:docs|drive)\.google\.com\/(?:a\/[a-zA-Z0-9\-\_\.]+\/)?(forms|document|presentation|spreadsheets|file)\/d\/([a-zA-Z0-9_-]+)/i
],
mixins: [
"favicon",
"og-title",
"og-image",
"og-description",
"twitter-player-responsive" // fallback mixin
],
getMeta: function (schemaFileObject) {
return {
title: schemaFileObject.name,
site: "Google Docs"
// Mute canonical to bypass the validation and allow player.href=canonical
// Especially for video files and presentations:
// canonical: schemaFileObject.url
};
},
getLink: function(urlMatch, schemaFileObject) {
if (schemaFileObject.embedURL || schemaFileObject.embedUrl) {
var file = {
rel: [CONFIG.R.file, CONFIG.R.html5],
href: schemaFileObject.embedURL || schemaFileObject.embedUrl,
type: CONFIG.T.text_html
};
if (schemaFileObject.playerType) {
// HEADS UP:
// There is a problem with player as embedURL: x-frame-options is SAMEORIGIN
file.href = "https://drive.google.com/file/d/" + urlMatch[2] + "/preview";
file.rel.push(CONFIG.R.player);
// use default aspect
} else if (urlMatch[1] === "forms" || urlMatch[1] === "document" || urlMatch[1] === "file") {
file["aspect-ratio"] = 1 / Math.sqrt(2); // A4 portrait
// "App" to prevent Google Forms be presented as Player through Twitter-player mixin as Player prevails on Readers
file.rel.push (urlMatch[1] === "forms" ? CONFIG.R.app : CONFIG.R.reader);
/// } else if (urlMatch[1] === "file" && schemaFileObject.playerType) {
} else if (urlMatch[1] === "spreadsheets" ) {
file["aspect-ratio"] = Math.sqrt(2); // A4 landscape
file.rel.push (CONFIG.R.reader);
} else { // presentation
// file["aspect-ratio"] = 4/3; // use default aspect ratio
file.rel.push (CONFIG.R.player);
}
return file;
}
},
getData: function(cheerio, decode) {
var $scope = cheerio('[itemscope]');
if ($scope.length) {
var $aScope = cheerio($scope);
var result = {};
$aScope.find('[itemprop]').each(function() {
var $el = cheerio(this);
var scope = $el.attr('itemscope');
if (typeof scope !== 'undefined') {
return;
}
var key = $el.attr('itemprop');
if (key) {
var value = decode($el.attr('content') || $el.attr('href'));
result[key] = value;
}
});
return {
schemaFileObject: result
};
}
},
tests: [
"https://docs.google.com/document/d/17jg1RRL3RI969cLwbKBIcoGDsPwqaEdBxafGNYGwiY4/preview?sle=true",
"https://docs.google.com/document/d/1KHLQiZkTFvMvBHmYgntEQtNxXswOQISjkbpnRO3jLrk/edit",
"https://docs.google.com/presentation/d/1fE0PW1FMlYU9Xhig_QIGF8Yk1ApVfQQvntEEi4GbCm8/edit#slide=id.p",
"https://docs.google.com/presentation/d/1fE0PW1FMlYU9Xhig_QIGF8Yk1ApVfQQvntEEi4GbCm8/preview",
"https://docs.google.com/forms/d/1mJcBz16JAfxomVXIohDJv8w-AJw8t-jhAd1HgIwTlF8/viewform?c=0&w=1",
"https://docs.google.com/file/d/0BzufrRo-waV_NlpOTlI0ZnB4eVE/preview",
"https://drive.google.com/file/d/0BwGT3x6igRtkTWNtLWlhV3paZjA/view",
"https://docs.google.com/spreadsheets/d/10JLM1UniyGNuLaYTfs2fnki-U1iYFsQl4XNHPZTYunw/edit?pli=1#gid=0",
{
skipMixins: [
"og-image", "og-title", "og-description", "twitter-player-responsive"
],
skipMethods: [
"getLink",
"getMeta",
"getData"
]
}
]
};