Html 如何识别不同的把手模板?

Html 如何识别不同的把手模板?,html,node.js,typescript,handlebars.js,Html,Node.js,Typescript,Handlebars.js,我有几个html文件在我的项目,这是模板的电子邮件消息,如电子邮件验证,密码重置等 我需要预编译这些文件,并在正确的位置使用它们,例如,电子邮件验证模板必须在注册功能中发送。问题是,如果我不知道它们是哪种类型的,我如何识别要使用它们的模板?如何为模板创建某种标识符?您可以将编译后的模板保存在某种数据结构中,以某种方式返回,然后使用 下面是一个基于处理函数并使用Map作为数据存储的示例: export function preCompileTemplates(globString: string)

我有几个html文件在我的项目,这是模板的电子邮件消息,如电子邮件验证,密码重置等


我需要预编译这些文件,并在正确的位置使用它们,例如,电子邮件验证模板必须在注册功能中发送。问题是,如果我不知道它们是哪种类型的,我如何识别要使用它们的模板?如何为模板创建某种标识符?

您可以将编译后的模板保存在某种数据结构中,以某种方式返回,然后使用

下面是一个基于处理函数并使用
Map
作为数据存储的示例:

export function preCompileTemplates(globString: string) {

  const paths = getPathsFromGlob(globString)

  const preCompiledTemplatesPs = paths.map(path => {
      const templateName = path.substring(path.lastIndexOf('/') + 1, path.length - 5);
      return fs.promises.readFile(path).then(template => {
          return {name: templateName, content: Handlebars.precompile(template)}
      })
  })

  const templates = new Map()
  return Promises.all(preCompiledTemplatesPs, (preCompiledTemplates) => {
    preCompiledTemplates.forEach(template => {
      templates.set(template.name, template.content)
    })
    return templates
  })
}

请避免添加捕获屏幕,并添加相关源代码。这对回答问题很有帮助。