UNPKG

736 BJavaScriptView Raw
1'use strict';
2
3module.exports = faviconLinkTags;
4
5const hasTarget = require('./has-target');
6const resolveURL = require('./resolve-url');
7
8function faviconLinkTags(manifest, config) {
9 const links = [];
10 const rootURL = config.rootURL || '/';
11
12 if (manifest.icons && manifest.icons.length) {
13 for (let icon of manifest.icons) {
14 if (hasTarget(icon, 'favicon')) {
15 let sizes = '';
16 if (icon.sizes) {
17 sizes = ` sizes="${icon.sizes}"`
18 }
19
20 let type = '';
21 if (icon.type) {
22 type = ` type="${icon.type}"`
23 }
24
25 const url = resolveURL(rootURL, icon.src);
26
27 links.push(`<link rel="icon" href="${url}"${sizes}${type}>`);
28 }
29 }
30 }
31
32 return links;
33}