hubspot-pages #5
@@ -7,8 +7,11 @@ const {modulesPath, projectPath} = getConfigs();
|
|||||||
export async function buildHubspotEmail(blockName) {
|
export async function buildHubspotEmail(blockName) {
|
||||||
const distPath = await createDistFolder(blockName);
|
const distPath = await createDistFolder(blockName);
|
||||||
|
|
||||||
await copyFile(`${projectPath}/src/${blockName}.template.hbs`, `${distPath}/module.html`)
|
// Template
|
||||||
|
let handlebars = await readFile(path.join(srcPath, `${blockName}.template.hbs`), "utf8");
|
||||||
|
await writeFile(path.join(distPath, 'module.html'), handlebarsToHubl(handlebars));
|
||||||
|
|
||||||
|
// JSON
|
||||||
await buildHubspotJSONFiles(distPath, {
|
await buildHubspotJSONFiles(distPath, {
|
||||||
global: false,
|
global: false,
|
||||||
host_template_types: ["EMAIL"],
|
host_template_types: ["EMAIL"],
|
||||||
@@ -243,3 +246,23 @@ export async function buildHubspotJSONFiles(distPath, metaData) {
|
|||||||
// Export JSON file.
|
// Export JSON file.
|
||||||
await writeFile(path.join(distPath, 'fields.json'), JSON.stringify(fields, null, 4));
|
await writeFile(path.join(distPath, 'fields.json'), JSON.stringify(fields, null, 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export function handlebarsToHubl(handlebars) {
|
||||||
|
handlebars = handlebars.replace(/{{#if /g, '{% if module.');
|
||||||
|
handlebars = handlebars.replace(/{{\/if}}/g, '{% endif %}');
|
||||||
|
handlebars = handlebars.replace(/{{#each /g, '{% for module.');
|
||||||
|
handlebars = handlebars.replace(/{{\/each}}/g, '{% endfor %}');
|
||||||
|
handlebars = handlebars.replace(/{{base_url}}/g, '');
|
||||||
|
handlebars = handlebars.replace(/{esc_attr /g, '{');
|
||||||
|
handlebars = handlebars.replace(/{esc_url /g, '{');
|
||||||
|
handlebars = handlebars.replace(/{esc_html /g, '{');
|
||||||
|
handlebars = handlebars.replace(/{{{ /g, '{{');
|
||||||
|
handlebars = handlebars.replace(/ }}}/g, '}}');
|
||||||
|
handlebars = handlebars.replace(/{{{/g, '{{');
|
||||||
|
handlebars = handlebars.replace(/}}}/g, '}}');
|
||||||
|
handlebars = handlebars.replace(/{{/g, '{{module.');
|
||||||
|
handlebars = handlebars.replace(/{{module. /g, '{{ module.');
|
||||||
|
|
||||||
|
return handlebars;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import path from "path";
|
import path from "path";
|
||||||
import {copyFile} from "fs/promises";
|
import {copyFile, readFile, writeFile} from "fs/promises";
|
||||||
import {copy} from "fs-extra";
|
|
||||||
import {capitalize, getConfigs} from "../../helpers.js";
|
import {capitalize, getConfigs} from "../../helpers.js";
|
||||||
import {buildHubspotJSONFiles, createDistFolder,} from "./hubspot-email-adapter.js";
|
import {buildHubspotJSONFiles, createDistFolder, handlebarsToHubl,} from "./hubspot-email-adapter.js";
|
||||||
|
|
||||||
const {modulesPath, projectPath} = getConfigs();
|
const {modulesPath, projectPath} = getConfigs();
|
||||||
|
|
||||||
@@ -10,11 +9,17 @@ export async function buildHubspotPage(blockName) {
|
|||||||
const distPath = await createDistFolder(blockName);
|
const distPath = await createDistFolder(blockName);
|
||||||
|
|
||||||
const srcPath = path.join(projectPath, 'src');
|
const srcPath = path.join(projectPath, 'src');
|
||||||
await copyFile(path.join(srcPath, `${blockName}.template.hbs`), path.join(distPath, 'module.html'));
|
|
||||||
|
// Template
|
||||||
|
let handlebars = await readFile(path.join(srcPath, `${blockName}.template.hbs`), "utf8");
|
||||||
|
await writeFile(path.join(distPath, 'module.html'), handlebarsToHubl(handlebars));
|
||||||
|
|
||||||
|
// Assets
|
||||||
await copyFile(path.join(srcPath, 'styles', `${blockName}.min.css`), path.join(distPath, 'module.css'));
|
await copyFile(path.join(srcPath, 'styles', `${blockName}.min.css`), path.join(distPath, 'module.css'));
|
||||||
await copyFile(path.join(srcPath, 'scripts', `${blockName}.min.js`), path.join(distPath, 'module.js'));
|
await copyFile(path.join(srcPath, 'scripts', `${blockName}.min.js`), path.join(distPath, 'module.js'));
|
||||||
await copy(path.join(projectPath, 'src', 'images'), path.join(distPath, 'images'));
|
// await copy(path.join(projectPath, 'src', 'images'), path.join(distPath, 'images'));
|
||||||
|
|
||||||
|
// JSON
|
||||||
await buildHubspotJSONFiles(distPath, {
|
await buildHubspotJSONFiles(distPath, {
|
||||||
global: false,
|
global: false,
|
||||||
host_template_types: ["PAGE"],
|
host_template_types: ["PAGE"],
|
||||||
@@ -22,4 +27,3 @@ export async function buildHubspotPage(blockName) {
|
|||||||
is_available_for_new_content: true
|
is_available_for_new_content: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user