forked from itteco/iframely
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfavicon.js
62 lines (47 loc) · 1.6 KB
/
favicon.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
module.exports = {
getLink: function(meta) {
function findIcons(links, filter) {
var key, l;
for(key in meta) {
if (filter(key)) {
l = meta[key];
if (!(l instanceof Array)) {
l = [l];
}
l.forEach(function(link) {
var m = link.sizes && link.sizes.match(/^(\d+)x(\d+)$/i);
var href = link.href;
if (typeof link === "string") {
href = link;
}
links.push({
href: href,
rel: key.split(' ').concat('icon'),
type: link.type || CONFIG.T.image,
width: m && parseInt(m[1]),
height: m && parseInt(m[2])
});
});
}
}
}
var links = [];
// Filter not 'shortcut icon'.
findIcons(links, function(key) {
return /icon/i.test(key) && key != 'shortcut icon';
});
// Use 'shortcut icon' if no other.
findIcons(links, function(key) {
return key == 'shortcut icon';
});
// Push default icon if no icons at all.
if (links.length == 0) {
links.push({
href: '/favicon.ico',
type: CONFIG.T.image,
rel: CONFIG.R.icon
});
}
return links;
}
};