UPDATE from phantomjs to electroshot

This commit is contained in:
unpregnant 2017-02-05 17:57:23 +01:00
parent 7351c79953
commit a619a5017e
13 changed files with 22 additions and 50 deletions

View File

@ -6,11 +6,6 @@
@darkgrey: #343444; @darkgrey: #343444;
@main: #E77171; @main: #E77171;
html {
zoom: 0.75;
-webkit-text-size-adjust: auto;
}
body { body {
background: @background; background: @background;
font-family: 'Open Sans', sans-serif; font-family: 'Open Sans', sans-serif;

View File

@ -24,6 +24,7 @@
"@typopro/web-montserrat": "^3.4.9", "@typopro/web-montserrat": "^3.4.9",
"buffer-to-string": "^0.1.0", "buffer-to-string": "^0.1.0",
"clean-css": "^4.0.4", "clean-css": "^4.0.4",
"electroshot": "^1.2.0",
"express": "^4.14.1", "express": "^4.14.1",
"font-awesome": "^4.7.0", "font-awesome": "^4.7.0",
"fs": "0.0.1-security", "fs": "0.0.1-security",

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because one or more lines are too long

View File

@ -128,22 +128,24 @@
font-size: @fontSize; font-size: @fontSize;
.skill-block { .skill-block {
display: flex;
padding-bottom: 10px; padding-bottom: 10px;
display: inline-block;
.skill { .skill {
width: 100px; width: 100px;
color: #616161; color: #616161;
float: left;
} }
.skill-bar { .skill-bar {
float: right;
background: #E0E0E0; background: #E0E0E0;
overflow: hidden; overflow: hidden;
height: 8px; height: 8px;
flex: 1;
border-radius: 3px; border-radius: 3px;
margin-top: 6.5px; margin-top: 6.5px;
position: relative; position: relative;
width: 249px;
.level { .level {
background: #757575; background: #757575;

View File

@ -83,6 +83,7 @@
background: url('person.jpg'); background: url('person.jpg');
background-position: center; background-position: center;
background-size: cover; background-size: cover;
background-repeat: no-repeat;
height: 200px; height: 200px;
width: 200px; width: 200px;
border-radius: 50%; border-radius: 50%;

View File

@ -11,12 +11,8 @@
<body> <body>
{{>content}} {{>content}}
<script>
var userAgent = navigator.userAgent;
if (userAgent.indexOf('PhantomJS') < 0) document.getElementsByTagName('html')[0].style['zoom'] = 1;
</script>
</body> </body>
</html> </html>

View File

@ -3,7 +3,7 @@ const Mustache = require('mustache');
const pdf = require('html-pdf'); const pdf = require('html-pdf');
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
var exec = require('child_process').exec;
const dir = path.join(__dirname, '../resumes'); const dir = path.join(__dirname, '../resumes');
const directories = getDirectories(dir); const directories = getDirectories(dir);
@ -12,43 +12,20 @@ function getDirectories(srcpath) {
.filter(file => file.includes('resume-')) .filter(file => file.includes('resume-'))
} }
function readFileContent(fileName) {
const dir = path.join(__dirname, '../resumes/' + fileName);
return new Promise((res, rej) => {
fs.readFile(dir, 'utf8', (err, template) => {
if (err) rej(err);
else res(template);
});
});
}
function generatePdf(html, fileName) {
const dir = path.join(__dirname, '../pdf/' + fileName);
return new Promise((resolve, rej) => {
pdf.create(html, {
'type': 'pdf',
'format': 'A4',
'base': 'http://localhost:3000'
}).toFile(dir, function(err, res) {
if (err) rej(err);
else resolve();
});
});
}
async function convertToPdf() { async function convertToPdf() {
const layoutTemplate = await readFileContent('views/layout.mustache'); let script = '';
for (let resume of directories) { let dir = path.join(__dirname, '../pdf');
const resumeTemplate = await readFileContent(resume + '/' + resume + '.mustache'); directories.forEach(async(resume) => {
const html = Mustache.render( script += 'electroshot localhost:3000/' + resume +
layoutTemplate, { ' 2481x3508 --pdf-margin none --format pdf --out ' + dir +
person: person ' --filename "' + resume + '.pdf" --pdf-background; ';
}, { });
content: resumeTemplate script = script.substring(0, script.length - 2);
}); exec(script,
await generatePdf(html, resume + '.pdf'); (error, stdout, stderr) => {
} if (error) console.log(error);
console.log('Generated resumes into /pdf.'); else console.log(stderr);
});
} }
convertToPdf(); convertToPdf();