forked from ggrossetie/asciidoctor-web-pdf
-
Notifications
You must be signed in to change notification settings - Fork 1
/
template.js
63 lines (60 loc) · 1.96 KB
/
template.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
const getAuthors = function (node) {
const result = [];
const authorCount = node.getAttribute('authorcount')
if (authorCount > 1) {
for (let index = 1; index < authorCount + 1; index++) {
const author = node.getAttribute(`author_${index}`)
const email = node.getAttribute(`email_${index}`)
const bio = node.getAttribute(`authorbio_${index}`)
let twitter;
if (email && email.startsWith("https://twitter.com/")) {
twitter = email.replace("https://twitter.com/", "");
}
result.push({ name: author, email: email, bio: bio, twitter: twitter })
}
} else {
const author = node.getAttribute('author')
const email = node.getAttribute('email')
const bio = node.getAttribute(`authorbio`)
let twitter;
if (email && email.startsWith("https://twitter.com/")) {
twitter = email.replace("https://twitter.com/", "");
}
result.push({ name: author, email: email, bio: bio, twitter: twitter })
}
return result;
}
const renderAuthors = function (authors) {
return authors.map(author => {
return `<div class="author">
<div class="author-avatar"><img src="http://avatars.io/twitter/${author.twitter}"/></div>
<div class="author-name"><a href="${author.email}">@${author.twitter}</a></div>
<div class="author-bio">${author.bio}</div>
</div>
`;
}).join('\n')
}
module.exports = {
paragraph: (node) => `<p class="${node.getRoles().join(' ')}">${node.getContent()}</p>`,
document: (node) => `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link href="./snyk/assets/style.css" rel="stylesheet">
</head>
<body>
<header>
<img class="wordmark" src="./snyk/assets/wordmark.svg"/>
<h1>${node.getHeader().getTitle()}</h1>
<a class="website" href="www.snyk.io">www.snyk.io</a>
<img class="logo" src="./snyk/assets/logo.svg"/>
</header>
<section class="content">
${node.getContent()}
<div class="sect1 authors">
<h3>Authors :</h3>
${renderAuthors(getAuthors(node))}
</div>
</section>
</body>`
}