From 94de0572f72e1b49d3e4fac09909208dc88d3001 Mon Sep 17 00:00:00 2001 From: Andrea Vos Date: Mon, 9 Nov 2020 20:33:18 +0100 Subject: [PATCH] [sources] generate default id --- server/routes/sources.js | 7 ++++++- src/helpers.js | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/server/routes/sources.js b/server/routes/sources.js index 0edaa27fd..13bdcd2e5 100644 --- a/server/routes/sources.js +++ b/server/routes/sources.js @@ -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 = [ `
  • user: ${user ? user.username : ''}
  • `, `
  • templates: ${data.templates}
  • `, ]; - const tsv = ['???']; + const tsv = [generateId(data.title) || '???']; for (let field of ['type','author','title','extra','year','fragments','comment','link']) { human.push(`
  • ${field}: ${field === 'fragments' ? `
    ${data[field]}
    `: data[field]}
  • `); diff --git a/src/helpers.js b/src/helpers.js index cd6707be9..ea4675735 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -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); }