1 | 'use strict'
|
2 | const fs = require('fs')
|
3 | const path = require('path')
|
4 | const Templet = require('./templet')
|
5 |
|
6 |
|
7 | function heardHandle (headPath, htmlText) {
|
8 |
|
9 | const heardTempletArr = Templet.cutStringArray(htmlText, "<!-- *head-", "* -->")
|
10 | heardTempletArr.forEach(element => {
|
11 |
|
12 | const headFilePath = path.join(headPath, element + '.head')
|
13 | if (fs.existsSync(headFilePath)) {
|
14 |
|
15 | const headFileContent = fs.readFileSync(headFilePath, 'utf8')
|
16 |
|
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 | }
|
25 | module.exports = heardHandle |
\ | No newline at end of file |