@@ -14,8 +14,6 @@ const path = require('path');
1414const Metalsmith = require ( 'metalsmith' ) ;
1515const collections = require ( 'metalsmith-collections' ) ;
1616const feed = require ( 'metalsmith-feed' ) ;
17- const discoverHelpers = require ( 'metalsmith-discover-helpers' ) ;
18- const discoverPartials = require ( 'metalsmith-discover-partials' ) ;
1917const layouts = require ( 'metalsmith-layouts' ) ;
2018const markdown = require ( '@metalsmith/markdown' ) ;
2119const permalinks = require ( '@metalsmith/permalinks' ) ;
@@ -29,6 +27,8 @@ const ncp = require('ncp');
2927const junk = require ( 'junk' ) ;
3028const semver = require ( 'semver' ) ;
3129const replace = require ( 'metalsmith-one-replace' ) ;
30+ const glob = require ( 'glob' ) ;
31+ const Handlebars = require ( 'handlebars' ) ;
3232
3333const githubLinks = require ( './scripts/plugins/githubLinks' ) ;
3434const navigation = require ( './scripts/plugins/navigation' ) ;
@@ -41,7 +41,7 @@ const latestVersion = require('./scripts/helpers/latestversion');
4141const DEFAULT_LANG = 'en' ;
4242
4343// The history links of nodejs versions at doc/index.md
44- const nodejsVersionsContent = require ( 'fs' )
44+ const nodejsVersionsContent = fs
4545 . readFileSync ( './source/nodejsVersions.md' )
4646 . toString ( ) ;
4747
@@ -190,18 +190,43 @@ function buildLocale(source, locale, opts) {
190190 // Finally, this compiles the rest of the layouts present in ./layouts.
191191 // They're language-agnostic, but have to be regenerated for every locale
192192 // anyways.
193- . use (
194- discoverPartials ( {
195- directory : 'layouts/partials' ,
196- pattern : / \. h b s $ /
197- } )
198- )
199- . use (
200- discoverHelpers ( {
201- directory : 'scripts/helpers' ,
202- pattern : / \. j s $ /
203- } )
204- )
193+ . use ( ( files , metalsmith , done ) => {
194+ const fsPromises = require ( 'fs/promises' ) ;
195+ glob (
196+ `${ metalsmith . path ( 'layouts/partials' ) } /**/*.hbs` ,
197+ { } ,
198+ async ( err , matches ) => {
199+ if ( err ) {
200+ throw err ;
201+ }
202+ await Promise . all (
203+ matches . map ( async ( file ) => {
204+ const contents = await fsPromises . readFile ( file , 'utf8' ) ;
205+ const id = path . basename ( file , path . extname ( file ) ) ;
206+ return Handlebars . registerPartial ( id , contents ) ;
207+ } )
208+ ) ;
209+ done ( ) ;
210+ }
211+ ) ;
212+ } )
213+ . use ( ( files , metalsmith , done ) => {
214+ glob (
215+ `${ metalsmith . path ( 'scripts/helpers' ) } /**/*.js` ,
216+ { } ,
217+ ( err , matches ) => {
218+ if ( err ) {
219+ throw err ;
220+ }
221+ matches . forEach ( ( file ) => {
222+ const fn = require ( path . resolve ( file ) ) ;
223+ const id = path . basename ( file , path . extname ( file ) ) ;
224+ return Handlebars . registerHelper ( id , fn ) ;
225+ } ) ;
226+ done ( ) ;
227+ }
228+ ) ;
229+ } )
205230 . use ( layouts ( ) )
206231 // Pipes the generated files into their respective subdirectory in the build
207232 // directory.
0 commit comments