Topppy / hexo-blog

my hexo new blog
https://topppy.github.io/hexo-blog/
2 stars 0 forks source link

replace rem to px #37

Open Topppy opened 4 years ago

Topppy commented 4 years ago
const fs = require('fs')
const FS = 200

function replaceRem(filepath) {
  fs.readFile(filepath, 'utf8', (err, data) => {
    if (err) {
      return console.log(err);
    }
    const result = data.replace(/(\d+\.*\d*)rem/g, ($1, $2) => `${$2 * FS}px`)

    fs.writeFile(filepath, result, 'utf8', e => {
      if (err) return console.log(err);
    });
  })
}

module.exports = replaceRem