Skip to content

chochinlu/gen_email_html

Repository files navigation

Html Email Generator

Here is a simple script for generating html email.

Features

  • use mustache to generate email html template.
  • you don't need to write inline style hard code, just use <style></style> block or import css file.
  • use config and language jsons to generate multi-language email htmls at once.
  • minify the html result.
  • pre-append/ post-append string between your final html string (for example: sql statements)
  • live-reload development

Usage

First create a folder at src folder, you can name your folder by your project name or issue number, for example: issue999.

The file structure will look like this:

issue999
  - [image folder]
  - config.json
  - en.json
  - cn.json
  - index.mustache

config.json

Declare which language html files you want to generate, and the pre-appen/post-append stings.

for example:

{
  "langs": ["en","cn"],
  "inject": {
    "frontString": [
       "INSERT INTO ...",
       "'; \n"
    ],
    "endString": [
       "SELECT * FROM ... \n"
    ]
  }
}

lang and inject parameters are required.

lang parameter declares which languages html email you want to generate.

if you dont want inject anything, just:

{
  "inject": {
    "frontString":[],
    "endString":[]
  }
}

index.mustache

The default entry template is index.mustache (Mustache syntax)

Make sure you have index.mustache in your source project folder.

[language].json

Depend on your lang defined on config.json

if you define "lang":["en", "cn"], you should add two files: en.json, and cn.json

The json name should be the same as lang you defined in config.json

output

dist
  - [your source project folder name]
    -- [img folder]
    -- cn.html
    -- cn.sql
    -- en.html
    -- en.sql

Npm commands

First create the project source folder and json files:

$ npm run gen

It will help you to create the basic config.json, en.json and index.mustache

You can check basic information you set:

$npm run hello

Development:

$ npm run go [your source project folder name]

The target url will look like localhost:3000/en.html or localhost:3000/cn.html

Build final result:

$ npm run build [your source project folder name]

Email build result htmls for testing actual result (you need build first):

$npm run send:email

Build all en/zh/js html files to one file:

$ npm run build:copy 

About

A html email generator.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published