// Copyright @ 2018-2021 xiejiahe. All rights reserved. MIT license. import fs from 'fs' import config from './nav.config.js' import path from 'path' function addZero(num) { return num < 10 ? '0' + num : num } const now = new Date() const date = `${now.getFullYear()}年${addZero(now.getMonth() + 1)}月${addZero(now.getDate())}日 ${addZero(now.getHours())}:${addZero(now.getMinutes())}` const { description, title, keywords, baiduStatisticsUrl } = config.default const htmlTemplate = ` ${title} `.trim() const scriptTemplate = ` `.trim() try { const htmlPath = path.join('.', 'src', 'index.html') const readHtml = fs.readFileSync(htmlPath).toString() let t = readHtml.replace('', htmlTemplate) if (baiduStatisticsUrl) { t = t.replace('', scriptTemplate) } fs.writeFileSync(htmlPath, t, { encoding: 'utf-8' }) fs.unlinkSync('./nav.config.js') console.log('Build done!') } catch (error) { console.log(error) }