Skip to content

Commit ca8a08c

Browse files
committed
fix(Markdown): 支持直接传入模板字符串作为配置
现在可以传入模板字符串而不仅是文件路径,增加了配置的灵活性
1 parent 1d85885 commit ca8a08c

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/index.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,15 @@ export class Markdown {
127127

128128
/** 检查是否有传入模板 */
129129
if (this.config?.template) {
130-
if (!fs.existsSync(this.config.template)) throw TypeError('Template file not found')
131-
this.templatepath = this.config.template
132-
this.template = fs.readFileSync(this.config.template, 'utf-8')
130+
// 判断是文件路径还是模板字符串
131+
if (fs.existsSync(this.config.template)) {
132+
// 是文件路径
133+
this.templatepath = this.config.template
134+
this.template = fs.readFileSync(this.config.template, 'utf-8')
135+
} else {
136+
// 是模板字符串
137+
this.template = this.config.template
138+
}
133139
} else {
134140
this.template = fs.readFileSync(this.templatepath, 'utf-8')
135141
}

0 commit comments

Comments
 (0)