[sources] generate default id

This commit is contained in:
Andrea Vos 2020-11-09 20:33:18 +01:00
parent 83ab39bf63
commit 94de0572f7
2 changed files with 11 additions and 1 deletions

View File

@ -1,12 +1,17 @@
import { Router } from 'express';
import mailer from "../../src/mailer";
import {camelCase, capitalise} from "../../src/helpers";
const generateId = title => {
return camelCase(title.split(' ').slice(0, 2));
}
const buildEmail = (data, user) => {
const human = [
`<li><strong>user:</strong> ${user ? user.username : ''}</li>`,
`<li><strong>templates:</strong> ${data.templates}</li>`,
];
const tsv = ['???'];
const tsv = [generateId(data.title) || '???'];
for (let field of ['type','author','title','extra','year','fragments','comment','link']) {
human.push(`<li><strong>${field}:</strong> ${field === 'fragments' ? `<pre>${data[field]}</pre>`: data[field]}</li>`);

View File

@ -119,6 +119,11 @@ export const capitalise = function (word) {
return word.substring(0, 1).toUpperCase() + word.substring(1);
}
export const camelCase = function (words) {
const text = words.map(capitalise).join('');
return text.substring(0, 1).toLowerCase() + text.substring(1);
}
export const now = function () {
return Math.floor(Date.now() / 1000);
}