2021-12-12 21:49:32 -05:00
|
|
|
const TEMPLATE = "./src/index.handlebars"
|
|
|
|
const RESPONSES = "./src/responses.csv"
|
|
|
|
|
|
|
|
const handlebars = require('handlebars');
|
|
|
|
const fs = require('fs');
|
|
|
|
const parse = require('csv-parse/lib/sync');
|
|
|
|
|
|
|
|
const template_source = fs.readFileSync(TEMPLATE).toString();
|
|
|
|
|
|
|
|
var messages = [];
|
|
|
|
|
|
|
|
const content = fs.readFileSync(RESPONSES);
|
|
|
|
const records = parse(content, { from_line: 2 });
|
|
|
|
|
|
|
|
records.map(record => {
|
|
|
|
let twitter = record[2];
|
|
|
|
|
|
|
|
if (!twitter.startsWith("@")) {
|
|
|
|
twitter = `@${twitter}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
message_row = {
|
|
|
|
timestamp: record[0],
|
|
|
|
name: record[1],
|
|
|
|
twitter: twitter.trim(),
|
2022-01-02 14:57:55 -05:00
|
|
|
content: record[3],
|
|
|
|
image_link: record[4],
|
2021-12-12 21:49:32 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
messages.push(message_row);
|
|
|
|
});
|
|
|
|
|
|
|
|
handlebars.registerHelper('breaklines', function(text) {
|
|
|
|
text = handlebars.Utils.escapeExpression(text);
|
|
|
|
text = text.replace(/(\r\n|\n|\r)/gm, '<br>');
|
|
|
|
return new handlebars.SafeString(text);
|
|
|
|
});
|
|
|
|
|
|
|
|
var compiled = handlebars.compile(template_source);
|
|
|
|
var html = compiled(
|
|
|
|
{ messages: messages }
|
|
|
|
);
|
|
|
|
|
|
|
|
console.log(html);
|