Skip to content

Commit e81317f

Browse files
author
Vache, Aurelie
committed
chore: fix typo and add asciidoctor generator to pdf
1 parent 577a28f commit e81317f

File tree

17 files changed

+3220
-13
lines changed

17 files changed

+3220
-13
lines changed

.gitignore

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
2+
# Created by https://www.gitignore.io/api/node
3+
# Edit at https://www.gitignore.io/?templates=node
4+
5+
### Node ###
6+
# Logs
7+
logs
8+
*.log
9+
npm-debug.log*
10+
yarn-debug.log*
11+
yarn-error.log*
12+
13+
# Runtime data
14+
pids
15+
*.pid
16+
*.seed
17+
*.pid.lock
18+
19+
# Directory for instrumented libs generated by jscoverage/JSCover
20+
lib-cov
21+
22+
# Coverage directory used by tools like istanbul
23+
coverage
24+
25+
# nyc test coverage
26+
.nyc_output
27+
28+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29+
.grunt
30+
31+
# Bower dependency directory (https://bower.io/)
32+
bower_components
33+
34+
# node-waf configuration
35+
.lock-wscript
36+
37+
# Compiled binary addons (https://nodejs.org/api/addons.html)
38+
build/Release
39+
40+
# Dependency directories
41+
node_modules/
42+
jspm_packages/
43+
44+
# TypeScript v1 declaration files
45+
typings/
46+
47+
# Optional npm cache directory
48+
.npm
49+
50+
# Optional eslint cache
51+
.eslintcache
52+
53+
# Optional REPL history
54+
.node_repl_history
55+
56+
# Output of 'npm pack'
57+
*.tgz
58+
59+
# Yarn Integrity file
60+
.yarn-integrity
61+
62+
# dotenv environment variables file
63+
.env
64+
65+
# parcel-bundler cache (https://parceljs.org/)
66+
.cache
67+
68+
# next.js build output
69+
.next
70+
71+
# nuxt.js build output
72+
.nuxt
73+
74+
# vuepress build output
75+
.vuepress/dist
76+
77+
# Serverless directories
78+
.serverless/
79+
80+
# FuseBox cache
81+
.fusebox/
82+
83+
#DynamoDB Local files
84+
.dynamodb/
85+
86+
# End of https://www.gitignore.io/api/node

bin/asciidoctorjs-pdf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env node
2+
3+
'use strict'
4+
5+
process.title = 'asciidoctorjs-pdf'
6+
const cli = require('../lib/cli.js')
7+
8+
async function main () {
9+
const argv = cli.argsParser().argv
10+
return cli.run(argv)
11+
}
12+
13+
main()
14+
.then((result) => {
15+
if (result.exit) {
16+
process.exit(0)
17+
}
18+
})
19+
.catch((error) => {
20+
console.log('error', error)
21+
process.exit(1)
22+
})
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
@import 'https://fonts.googleapis.com/css?family=Roboto:400,500';
2+
3+
@page {
4+
size: 508mm 361mm;
5+
margin: 0.5cm;
6+
padding: 0.5cm;
7+
}
8+
9+
@page :first {
10+
margin: 0;
11+
padding: 0;
12+
}
13+
14+
html, body {
15+
height: 100%;
16+
margin: 0;
17+
padding: 0;
18+
color: #4a4a4a;
19+
text-align: justify;
20+
}
21+
22+
html {
23+
font-family: Roboto, 'DejaVu Sans', Arial, sans-serif;
24+
font-size: 18px;
25+
}
26+
27+
header {
28+
background-color: #131313;
29+
display: grid;
30+
grid-template-columns: auto 1fr auto;
31+
padding: 0.7cm 12em 0.7cm 0.7cm;
32+
align-items: center;
33+
color: white;
34+
}
35+
36+
header > a {
37+
color: white;
38+
}
39+
40+
header > .wordmark {
41+
max-height: 3em;
42+
}
43+
44+
header > .website {
45+
font-size: 1.4em;
46+
font-weight: 400;
47+
align-self: end;
48+
}
49+
50+
header > .logo {
51+
position: absolute;
52+
top: 1em;
53+
right: 3em;
54+
max-width: 6em;
55+
}
56+
57+
h1 {
58+
font-size: 2em;
59+
margin: 0;
60+
padding: 0 0 0 1em;
61+
font-weight: 400;
62+
}
63+
64+
section.content {
65+
margin: 0.5cm;
66+
padding: 0;
67+
columns: auto calc((100vw / 3) - 3cm);
68+
}
69+
70+
.admonitionblock div {
71+
font-weight: bold
72+
}
73+
74+
.sect1 {
75+
max-width: calc((100vw / 3) - 3cm);
76+
margin-right: 1.2cm;
77+
margin-left: 1.2cm;
78+
margin-top: 0.5cm;
79+
break-inside: avoid-region;
80+
}
81+
82+
h2 {
83+
color: #131313;
84+
font-size: 1.4em;
85+
font-weight: 500;
86+
margin-top: 0;
87+
}
88+
89+
h3 {
90+
font-size: 1.1em;
91+
font-weight: 500;
92+
}
93+
94+
.listingblock pre {
95+
background:#fafcfe;
96+
border: 1px solid #d5d4d9;
97+
color: #4a4a4a;
98+
}
99+
100+
101+
.listingblock pre,.listingblock pre[class] {
102+
font-size: 0.8em;
103+
line-height: 1.5em;
104+
border-radius: 4px;
105+
word-wrap: break-word;
106+
padding: 1em;
107+
}
108+
109+
.listingblock {
110+
margin-bottom: 2em;
111+
}
112+
113+
a {
114+
color: #131313;
115+
text-decoration: none;
116+
}
117+
118+
.authors {
119+
margin-top: auto;
120+
}
121+
122+
.author {
123+
display: grid;
124+
grid-template-columns: auto 1fr;
125+
align-items: center;
126+
padding-bottom: 1em;
127+
}
128+
129+
.author-avatar > img {
130+
border-radius: 50%;
131+
max-height: 2em;
132+
}
133+
134+
.author-avatar {
135+
grid-row-start: span 2;
136+
padding-right: 1em;
137+
}
138+
139+
.author-bio {
140+
font-size: 0.9em
141+
}
142+
143+
.page-break {
144+
page-break-after: always;
145+
}
146+
147+
pre {
148+
break-inside: avoid;
149+
}
150+
151+
.single-block {
152+
break-inside: avoid-column;
153+
}
Lines changed: 6 additions & 0 deletions
Loading
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
const getAuthors = function (node) {
2+
const result = [];
3+
const authorCount = node.getAttribute('authorcount')
4+
if (authorCount > 1) {
5+
for (let index = 1; index < authorCount + 1; index++) {
6+
const author = node.getAttribute(`author_${index}`)
7+
const email = node.getAttribute(`email_${index}`)
8+
const bio = node.getAttribute(`authorbio_${index}`)
9+
let twitter;
10+
if (email && email.startsWith("https://twitter.com/")) {
11+
twitter = email.replace("https://twitter.com/", "");
12+
}
13+
result.push({ name: author, email: email, bio: bio, twitter: twitter })
14+
}
15+
} else {
16+
const author = node.getAttribute('author')
17+
const email = node.getAttribute('email')
18+
const bio = node.getAttribute(`authorbio`)
19+
let twitter;
20+
if (email && email.startsWith("https://twitter.com/")) {
21+
twitter = email.replace("https://twitter.com/", "");
22+
}
23+
result.push({ name: author, email: email, bio: bio, twitter: twitter })
24+
}
25+
return result;
26+
}
27+
28+
const renderAuthors = function (authors) {
29+
return authors.map(author => {
30+
return `<div class="author">
31+
<div class="author-avatar"><img src="http://avatars.io/twitter/${author.twitter}"/></div>
32+
<div class="author-name"><a href="${author.email}">@${author.twitter}</a></div>
33+
<div class="author-bio">${author.bio}</div>
34+
</div>
35+
`;
36+
}).join('\n')
37+
}
38+
39+
40+
module.exports = [{
41+
paragraph: (ctx) => `<p class="${ctx.node.getRoles()}">${ctx.node.getContent()}</p>`,
42+
document: (ctx) => `<!DOCTYPE html>
43+
<html lang="en">
44+
<head>
45+
<meta charset="UTF-8">
46+
<link href="./template/assets/style.css" rel="stylesheet">
47+
</head>
48+
<body>
49+
<header>
50+
<h1>${ctx.node.getHeader().getTitle()}</h1>
51+
</header>
52+
<section class="content">
53+
${ctx.node.getContent()}
54+
<div class="sect1 authors">
55+
<h3>Authors :</h3>
56+
${renderAuthors(getAuthors(ctx.node))}
57+
<div class="author-bio">${ctx.node.getAttribute('version')}</div>
58+
</div>
59+
</section>
60+
</body>`,
61+
page_break: () => `<div class="page-break"></div>`
62+
}]

generate/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
# Generate
22

3+
## Pre-requisits
4+
5+
`$ npm i yargs --save`
6+
37
## 1. Markdown to AsciiDoc
48

59
`$ pandoc -s --columns=80 --atx-headers -t asciidoc -o out.adoc README.md`
610

7-
##2.
11+
##2. Asciidoc to PDF
812

9-
`$ ./bin/asciidoctorjs-pdf /home/scraly/git/src/github.com/scraly/terraform-cheat-sheet/out.adoc --template-require ../examples/cheat-sheet/redhat/template.js`
13+
`$ ./bin/asciidoctorjs-pdf terraform-cheat-sheet.adoc --template-require ../examples/cheat-sheet/template/template.js`

0 commit comments

Comments
 (0)