@@ -2,33 +2,31 @@ const yaml = require('js-yaml');
22const navigationPlugin = require ( '@11ty/eleventy-navigation' ) ;
33const path = require ( 'path' ) ;
44
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+ } ;
1923 } ) ;
20- const fs = require ( 'fs' ) ;
21- fs . writeFileSync ( 'src/_data/build_info.json' , jsonData ) ;
22- } ;
23-
24- module . exports = function ( eleventyConfig ) {
25- writeBuildInfoToFile ( ) ;
2624
2725 // See .eleventyignore for files to ignore.
2826 eleventyConfig . setUseGitIgnore ( false ) ;
2927
3028 // To enable YAML files in `_data`.
31- eleventyConfig . addDataExtension ( 'yaml' , contents => yaml . load ( contents ) ) ;
29+ eleventyConfig . addDataExtension ( 'yaml' , ( contents ) => yaml . load ( contents ) ) ;
3230
3331 // To handle relative paths and basic navigation via breadcrumbs.
3432 eleventyConfig . addPlugin ( navigationPlugin ) ;
@@ -82,11 +80,11 @@ module.exports = function(eleventyConfig) {
8280 'src/sitemap.xml' ,
8381 'src/lib/**/*.js' ,
8482 'src/lib/**/*.html' ,
85- ] . map ( path => eleventyConfig . addPassthroughCopy ( path ) ) ;
83+ ] . map ( ( path ) => eleventyConfig . addPassthroughCopy ( path ) ) ;
8684
8785 // eleventyConfig.addPassthroughCopy('src/favicon');
8886
8987 return {
90- dir : { input : 'src' }
88+ dir : { input : 'src' } ,
9189 } ;
9290} ;
0 commit comments