From 03ff09289ff6c321d519b29048f1cea55e6dc919 Mon Sep 17 00:00:00 2001 From: ningmengchongshui <916415899@qq.com> Date: Mon, 10 Jun 2024 10:46:16 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E6=88=AA=E5=9B=BE?= =?UTF-8?q?=E6=96=B0=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/index.tsx | 6 ++++-- src/utils/component.ts | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/example/index.tsx b/example/index.tsx index 5e2ef34..0e513b6 100644 --- a/example/index.tsx +++ b/example/index.tsx @@ -13,19 +13,21 @@ export class Image { * @returns */ getHelloComponent(uid: number, data: DataType) { - // 生成 html 地址 + // 生成 html 地址 或 html字符串 const Address = Com.create(, { /** * 注意,不设置json_dir时, * html_head路径应该是../public/output.css * 且html_head默认值路径也是../public/output.css - * 因此,不增加其他head的话,html_head和join_dir都可以胜利 + * 因此,不增加其他head的话,html_head和join_dir都可以省略 * { html_name: `${uid}.html`} */ html_head: ``, // html/hello/uid.html join_dir: 'hello', html_name: `${uid}.html` + // 不生成文件,返回的将是html字符串 + // file_create:false }) return Pup.render(Address) } diff --git a/src/utils/component.ts b/src/utils/component.ts index fdc4ffa..77cf9a4 100644 --- a/src/utils/component.ts +++ b/src/utils/component.ts @@ -8,6 +8,7 @@ type ComponentCreateOpsionType = { html_name?: string join_dir?: string html_body?: string + file_create?: boolean } /** @@ -39,6 +40,12 @@ export class Component { const head = `${options?.html_head ?? Link}` const body = ` ${str} ${options?.html_body ?? ''}` const html = `${DOCTYPE}${head}${body}` + if ( + typeof options?.file_create == 'boolean' && + options?.file_create == false + ) { + return html + } writeFileSync(address, html) return address }