@@ -10,38 +10,31 @@ const ejs = require('ejs')
10
10
// https://github.com/sass/node-sass
11
11
const sass = require ( 'node-sass' )
12
12
13
- module . exports = ( template = 'index' , lang = 'en_us' , themeColor = '#6c757d' ) => {
13
+ module . exports = ( template = 'index' , data = { } , lang = 'en_us' , themeColor = '#6c757d' ) => {
14
14
return new Promise ( ( resolve , reject ) => {
15
15
// setup dictionary object first
16
16
const i18n = path . join ( process . cwd ( ) , `i18n/${ lang } .json` )
17
17
fs . readFile ( i18n , 'utf8' , ( err , contents ) => {
18
- let i18n
19
18
if ( err ) {
20
19
return reject ( err )
21
20
}
22
21
23
22
try {
24
- i18n = JSON . parse ( contents )
23
+ data . i18n = JSON . parse ( contents )
25
24
} catch ( err ) {
26
25
// invalid JSON
27
26
return reject ( err )
28
27
}
29
28
30
29
// render Sass to CSS with theme color
31
- const renderSass = filename => sass . renderSync ( {
30
+ data . renderSass = filename => sass . renderSync ( {
32
31
data : `$theme-color: ${ themeColor } ;` ,
33
32
file : path . resolve ( process . cwd ( ) , `scss/${ filename } .scss` )
34
33
} )
34
+ data . themeColor = themeColor
35
35
36
- // setup data and parse template to HTML
36
+ // render EJS file to HTML
37
37
const view = path . join ( process . cwd ( ) , `views/${ template } .ejs` )
38
- const data = {
39
- i18n,
40
- themeColor,
41
- renderSass
42
- }
43
-
44
- // render EJS file
45
38
ejs . renderFile ( view , data , null , ( err , html ) => {
46
39
if ( err ) {
47
40
reject ( err )
0 commit comments