Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mj-include - allow absolute paths #1546

Closed
araphiel opened this issue Mar 19, 2019 · 4 comments
Closed

mj-include - allow absolute paths #1546

araphiel opened this issue Mar 19, 2019 · 4 comments

Comments

@araphiel
Copy link

araphiel commented Mar 19, 2019

Ideal behavior

File: archive/index.mjml

  • <mj-include root="true" path="/partials/footer.mjml" />

Command: npx mjml ./archive/**/*.mjml -o ./dist

  • ✅ All files in located in a the archive will compile into the /dist folder
  • 🚫 mj-include partials are referenced from project root directory, instead of file directory.

Why?: This would allow larger teams to provide a consistent workspace + archive

├── index.mjml // working file (untracked)
├── partials // template partials
|    ├── header.mjml
|    └── footer.mjml
└── archive // repo of old work
    └── events
    |   └── event-email-96.mjml
    └── newletters
        ├── newsletter-55.mjml
        └── random-campaign
            └── campaign-newsletter.mjml
@araphiel araphiel changed the title Question: Are absolute paths possible with mj-include mj-include: allow absolute paths Mar 21, 2019
@araphiel araphiel changed the title mj-include: allow absolute paths mj-include - allow absolute paths Mar 21, 2019
@araphiel
Copy link
Author

araphiel commented Mar 21, 2019

As it turns out, this functionality exist via the mjml2html options .

I do think the filePath option would be really useful if exposed via CLI.

It's basic but this was a work around for me.

const { readFile, writeFile } = require('fs')
const { parse, resolve } = require('path')
const recursive = require("recursive-readdir")
const mjml2html = require("mjml")


recursive('archive', (err, files) => {
    files.forEach((file, index) => {

        const { name } = parse(file)

        readFile(file, 'utf-8', (err, data) => {
            if (err) throw err;

            const options = {
                beautify: true, 
                filePath: resolve('partials'),
                minify: true,
            }

            const { html } = mjml2html(data, options)

            writeFile(`dist/${name}.html`, html, 'utf-8', err => {
                if (err) throw err
            })
        })
    })
})

@kmcb777
Copy link
Collaborator

kmcb777 commented Mar 22, 2019

@araphiel actually all the mjml2html options can be used with the cli with --config, so you can already do --config.filePath ./includes
We'll add this one to the cli documentation 👍

@araphiel
Copy link
Author

Thanks for reaching out @kmcb777

Just tested it out (using the command below) & the mj-include partials didn't compile.

npx mjml archive/general/webinar_thank-you.mjml --config.filePath ./partials -o index.html

Maybe filePath needs to be explictly exposed via the CLI?

const config = Object.assign(DEFAULT_OPTIONS, argv.c, fonts && {fonts}, minifyOptions && {minifyOptions})

compiled = mjml2html(i.mjml, { ...config, filePath: i.file })

@iRyusa
Copy link
Member

iRyusa commented Mar 22, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants