-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.js
62 lines (53 loc) · 1.45 KB
/
index.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
function buildStylesheets (sheets, async) {
var output = ''
if (!sheets) return output
if (typeof sheets === 'string') {
sheets = [sheets]
}
sheets.forEach(function (sheet) {
output += !async
? `<link rel="stylesheet" href="${sheet}">\n`
: `<link rel="stylesheet" href="${sheet}" media="none" onload="if(media!=='all')media='all'">\n`
})
return output
}
function buildScripts (scripts, async) {
var output = ''
if (!scripts) return output
if (typeof scripts === 'string') {
scripts = [scripts]
}
scripts.forEach(function (script) {
output += !async
? `<script src="${script}"></script>\n`
: `<script src="${script}" async></script>\n`
})
return output
}
module.exports = function (opts) {
var title = opts.title ? `<title>${opts.title}</title>` : ''
var headScript = (opts.script && opts.scriptAsync) ? buildScripts(opts.script, opts.scriptAsync) : ''
var bodyScript = (opts.script && !opts.scriptAsync) ? buildScripts(opts.script, opts.scriptAsync) : ''
var favicon = opts.favicon ? `<link rel="icon" href="${opts.favicon}">` : ''
var css = buildStylesheets(opts.css, opts.cssAsync)
var lang = opts.lang || 'en'
var dir = opts.dir || 'ltr'
var head = opts.head || ''
var body = opts.body || ''
return `<!doctype html>
<html lang="${lang}" dir="${dir}">
<head>
${title}
<meta charset="utf-8">
${favicon}
${head}
${css}
${headScript}
</head>
<body>
${body}
${bodyScript}
</body>
</html>
`
}