-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdemo.js
39 lines (34 loc) · 1.03 KB
/
demo.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
const ejs = require('ejs');
const fs = require('fs');
const axios = require('axios');
const host = 'https://hbj2gyrf5l.execute-api.eu-west-1.amazonaws.com/production';
const file = process.argv[2];
const type = process.argv[3];
const originalHtml = fs.readFileSync(file, { encoding: 'utf8' });
const images = [
{
image: 'scienziati.jpg',
text: 'Ancora più scemo chi continua a leggere',
},
{
image: 'Logo_Scienza_Gioco.jpg',
text: 'Ancora più gay chi continua a leggere',
},
{
image: '37256.jpg',
text: 'Ancora più gay chi continua a leggere',
}
];
template(type, originalHtml).then( res => {
console.log(res.data.data);
const templateData = {};
templateData[type] = res.data.data;
fs.writeFileSync('./templated/' + type + '.html', ejs.render(originalHtml, Object.assign(templateData, { images })), { encoding: 'utf8' });
});
function template(type, html) {
if(type === 'articles') {
return axios.get(host + '/articles');
} else if(type === 'tags') {
return axios.get(host + '/tags');
}
}