@@ -2,33 +2,31 @@ const yaml = require('js-yaml');
2
2
const navigationPlugin = require ( '@11ty/eleventy-navigation' ) ;
3
3
const path = require ( 'path' ) ;
4
4
5
- // Generate the shortened commit hash and create (overwrite) `build_info.json`
6
- // file. This file will eventually be added to the footer of the page.
7
- const writeBuildInfoToFile = ( ) => {
8
- const version = require ( './package.json' ) . version ;
9
- const commitHash = require ( 'child_process' )
10
- . execSync ( 'git rev-parse --short HEAD' ) . toString ( ) . trim ( ) ;
11
- const commitDate = require ( 'child_process' )
12
- . execSync ( 'git show -s --format=%cd --date=short' ) . toString ( ) . trim ( ) ;
13
- const currentYear = ( new Date ( ) ) . getFullYear ( ) ;
14
- const jsonData = JSON . stringify ( {
15
- version : version ,
16
- revision : commitHash ,
17
- lastUpdated : commitDate ,
18
- copyrightYear : currentYear
5
+ module . exports = function ( eleventyConfig ) {
6
+ eleventyConfig . addGlobalData ( 'build_info' , ( ) => {
7
+ const version = require ( './package.json' ) . version ;
8
+ const commitHash = require ( 'child_process' )
9
+ . execSync ( 'git rev-parse --short HEAD' )
10
+ . toString ( )
11
+ . trim ( ) ;
12
+ const commitDate = require ( 'child_process' )
13
+ . execSync ( 'git show -s --format=%cd --date=short' )
14
+ . toString ( )
15
+ . trim ( ) ;
16
+ const currentYear = new Date ( ) . getFullYear ( ) ;
17
+ return {
18
+ version : version ,
19
+ revision : commitHash ,
20
+ lastUpdated : commitDate ,
21
+ copyrightYear : currentYear ,
22
+ } ;
19
23
} ) ;
20
- const fs = require ( 'fs' ) ;
21
- fs . writeFileSync ( 'src/_data/build_info.json' , jsonData ) ;
22
- } ;
23
-
24
- module . exports = function ( eleventyConfig ) {
25
- writeBuildInfoToFile ( ) ;
26
24
27
25
// See .eleventyignore for files to ignore.
28
26
eleventyConfig . setUseGitIgnore ( false ) ;
29
27
30
28
// To enable YAML files in `_data`.
31
- eleventyConfig . addDataExtension ( 'yaml' , contents => yaml . load ( contents ) ) ;
29
+ eleventyConfig . addDataExtension ( 'yaml' , ( contents ) => yaml . load ( contents ) ) ;
32
30
33
31
// To handle relative paths and basic navigation via breadcrumbs.
34
32
eleventyConfig . addPlugin ( navigationPlugin ) ;
@@ -82,11 +80,11 @@ module.exports = function(eleventyConfig) {
82
80
'src/sitemap.xml' ,
83
81
'src/lib/**/*.js' ,
84
82
'src/lib/**/*.html' ,
85
- ] . map ( path => eleventyConfig . addPassthroughCopy ( path ) ) ;
83
+ ] . map ( ( path ) => eleventyConfig . addPassthroughCopy ( path ) ) ;
86
84
87
85
// eleventyConfig.addPassthroughCopy('src/favicon');
88
86
89
87
return {
90
- dir : { input : 'src' }
88
+ dir : { input : 'src' } ,
91
89
} ;
92
90
} ;
0 commit comments