UNPKG

901 BJavaScriptView Raw
1'use strict'
2const fs = require('fs')
3const path = require('path')
4const Templet = require('./templet')
5
6// 处理Heard
7function heardHandle (headPath, htmlText) {
8 // 取出所有Heard标识
9 const heardTempletArr = Templet.cutStringArray(htmlText, "<!-- *head-", "* -->")
10 heardTempletArr.forEach(element => {
11 // 判断head模板目录中是否有指定heard
12 const headFilePath = path.join(headPath, element + '.head')
13 if (fs.existsSync(headFilePath)) {
14 // 读取出Head模板内容
15 const headFileContent = fs.readFileSync(headFilePath, 'utf8')
16 // 解析出head内容
17 const headContent = Templet.cutString(headFileContent, '<templet>', '</templet>')
18 htmlText = htmlText.replace(`<!-- *head-${element}* -->`, headContent)
19 } else {
20 console.error(`heard模板:${headFilePath}不存在!`)
21 }
22 })
23 return htmlText
24}
25module.exports = heardHandle
\No newline at end of file