mulmocast-vision 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -24,7 +24,7 @@ const generateHtml = async (args, options) => {
|
|
|
24
24
|
const tmpName = name.replace(/^create/, "");
|
|
25
25
|
const fileName = tmpName.charAt(0).toLowerCase() + tmpName.slice(1);
|
|
26
26
|
console.log(path_1.default.resolve(exports.baseDir, `${index}.png`));
|
|
27
|
-
await (0, utils_1.createPage)(path_1.default.resolve(exports.baseDir, `${index}.png`), nunjucks_1.default.render(filePath(fileName), args));
|
|
27
|
+
await (0, utils_1.createPage)(rootDir, path_1.default.resolve(exports.baseDir, `${index}.png`), nunjucks_1.default.render(filePath(fileName), args));
|
|
28
28
|
};
|
|
29
29
|
const createSectionDividerPage = async (args, options) => {
|
|
30
30
|
await generateHtml(args, options);
|
|
@@ -16,7 +16,7 @@ class htmlPlugin {
|
|
|
16
16
|
const templateFileName = path_1.default.resolve(this.rootDir, "./assets/html2", `${fileName}.html`);
|
|
17
17
|
const outfile = imageFilePath ?? path_1.default.resolve(this.outputDir, `${index}.png`);
|
|
18
18
|
const htmlFile = htmlFilePath ?? path_1.default.resolve(this.outputDir, `${index}.html`);
|
|
19
|
-
return await (0, utils_1.createPage)(outfile, nunjucks_1.default.render(templateFileName, args), { htmlFile, ...this.templateOptions });
|
|
19
|
+
return await (0, utils_1.createPage)(this.rootDir, outfile, nunjucks_1.default.render(templateFileName, args), { htmlFile, ...this.templateOptions });
|
|
20
20
|
};
|
|
21
21
|
this.createSectionDividerPage = async (args, options) => {
|
|
22
22
|
await this.generateHtml(args, options);
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const renderHTMLToImage: (html: string, outputPath: string, width: number, height: number) => Promise<void>;
|
|
2
2
|
export declare const interpolate: (template: string, data: Record<string, string | undefined>) => string;
|
|
3
|
-
export declare const getHTMLFile: (filename: string) => string;
|
|
4
|
-
export declare const createPage: (outputFile: string, htmlBody: string, options?: {
|
|
3
|
+
export declare const getHTMLFile: (rootDir: string, filename: string) => string;
|
|
4
|
+
export declare const createPage: (rootDir: string, outputFile: string, htmlBody: string, options?: {
|
|
5
5
|
htmlTemplateFile?: string;
|
|
6
6
|
headerStyle?: string;
|
|
7
7
|
htmlFile?: string;
|
package/lib/utils.js
CHANGED
|
@@ -8,7 +8,6 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const puppeteer_1 = __importDefault(require("puppeteer"));
|
|
10
10
|
const isCI = process.env.CI === "true";
|
|
11
|
-
const rootDir = path_1.default.resolve(__dirname, "../");
|
|
12
11
|
const renderHTMLToImage = async (html, outputPath, width, height) => {
|
|
13
12
|
// Use Puppeteer to render HTML to an image
|
|
14
13
|
const browser = await puppeteer_1.default.launch({
|
|
@@ -30,14 +29,14 @@ const interpolate = (template, data) => {
|
|
|
30
29
|
return template.replace(/\$\{(.*?)\}/g, (_, key) => data[key.trim()] ?? "");
|
|
31
30
|
};
|
|
32
31
|
exports.interpolate = interpolate;
|
|
33
|
-
const getHTMLFile = (filename) => {
|
|
32
|
+
const getHTMLFile = (rootDir, filename) => {
|
|
34
33
|
return fs_1.default.readFileSync(path_1.default.resolve(rootDir, `./assets/templates/${filename}.html`), "utf-8");
|
|
35
34
|
};
|
|
36
35
|
exports.getHTMLFile = getHTMLFile;
|
|
37
|
-
const createPage = async (outputFile, htmlBody, options) => {
|
|
36
|
+
const createPage = async (rootDir, outputFile, htmlBody, options) => {
|
|
38
37
|
const canvasSize = { width: 1536, height: 1024 };
|
|
39
38
|
const { htmlTemplateFile, headerStyle, htmlFile } = options ?? {};
|
|
40
|
-
const template = (0, exports.getHTMLFile)(htmlTemplateFile ?? "tailwind");
|
|
39
|
+
const template = (0, exports.getHTMLFile)(rootDir, htmlTemplateFile ?? "tailwind");
|
|
41
40
|
// console.log(template)
|
|
42
41
|
const htmlData = (0, exports.interpolate)(template, { htmlBody, headerStyle });
|
|
43
42
|
// console.log(htmlData);
|