forked from brycewray/eleventy_solo_starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsshash.js
34 lines (29 loc) · 964 Bytes
/
csshash.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const fs = require('fs')
const md5 = require('md5')
const globAll = require('glob-all')
const DATAFILE = '_data/csshash.json'
const PCSSFILE = 'csshash'
const YEARFILE = '_data/year.json' // for use by Nunjucks templates
cssFiles = globAll.sync([
'src/assets/css/*.css'
])
var cssMd5Total = 0
var cssContent = ''
for(i=0; i<cssFiles.length; i++) {
cssContent += (fs.readFileSync(cssFiles[i]))
}
cssMd5Total = md5(cssContent)
console.log(`CSS MD5 result =`, cssMd5Total)
var jsonValue = `{
"indexCSS": "index-${cssMd5Total}.css"
}`
fs.writeFileSync(DATAFILE, jsonValue)
var yearValue = `{
"copyrightYear": "${new Date().getFullYear()}"
}`
fs.writeFileSync(YEARFILE, yearValue)
// for use by Nunjucks templates
var txtValue = `index-${cssMd5Total}.css`
fs.writeFileSync(PCSSFILE, txtValue)
// ...the latter because, otherwise, you get the following error:
// The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView.