danmindru / responsive-html-email-signature

✨ Template generator for (responsive) emails & email signatures
https://responsive-html-email-signature-generator.com
MIT License
841 stars 247 forks source link

Repeating Variables for Each id #134

Closed lukakemperle closed 5 months ago

lukakemperle commented 5 months ago

Is it feasible to utilize variables without having to repeat them for each individual _id/colleague? Currently, my config.js file is becoming cluttered due to the repetition with the same information:

[{
"id": "col-1",
"companyName": "Name of the Comany",
"signature": "Z lepimi pozdravi / Best regards,",
"name": "Col One"
}, {
"id": "col-2",
"companyName": "Name of the Comany",
"signature": "Z lepimi pozdravi / Best regards,",
"name": "Col Two"
},...
]

I am seeking assistance in implementing a variable system for all signatures, as I currently have to manually repeat the same information with each signature, with only the name changing. -Thank you!

danmindru commented 5 months ago

Hi there! Unfortunately there isn't a way to reference variables in the configuration currently.

One solution would be to create a small nodejs script that generates the conf.js file.

For example, create generateConfig.js:

const fs = require("fs");
const path = require("path");

const companyName = "Name of the Company";
const signature = "Z lepimi pozdravi / Best regards,";

// Configuration array
const config = [
  {
    id: "col-1",
    companyName,
    signature,
    name: "Col One",
  },
  {
    id: "col-2",
    companyName,
    signature,
    name: "Col Two",
  },
  // Add more objects as needed
];

// Function to create a single JSON file with the entire array
function createJsonFile(config) {
  const filePath = path.join(__dirname, 'conf.json');
  fs.writeFile(filePath, JSON.stringify(config, null, 2), (err) => {
    if (err) {
      console.error('Error writing file conf.json', err);
    } else {
      console.log('File conf.json created successfully');
    }
  });
}

// Run the function
createJsonFile(config);

then run node ./generateConfig.js to get the desired json.

Hope this helps!

lukakemperle commented 5 months ago

Hey Dan,

I just wanted to say that your idea of creating a separate file for conf.js is awesome and it has solved all of my problems! Thank you so much for that!

danmindru commented 5 months ago

That’s awesome! All the best 🍻