@@ -14,8 +14,6 @@ const path = require('path');
14
14
const Metalsmith = require ( 'metalsmith' ) ;
15
15
const collections = require ( 'metalsmith-collections' ) ;
16
16
const feed = require ( 'metalsmith-feed' ) ;
17
- const discoverHelpers = require ( 'metalsmith-discover-helpers' ) ;
18
- const discoverPartials = require ( 'metalsmith-discover-partials' ) ;
19
17
const layouts = require ( 'metalsmith-layouts' ) ;
20
18
const markdown = require ( '@metalsmith/markdown' ) ;
21
19
const permalinks = require ( '@metalsmith/permalinks' ) ;
@@ -29,6 +27,8 @@ const ncp = require('ncp');
29
27
const junk = require ( 'junk' ) ;
30
28
const semver = require ( 'semver' ) ;
31
29
const replace = require ( 'metalsmith-one-replace' ) ;
30
+ const glob = require ( 'glob' ) ;
31
+ const Handlebars = require ( 'handlebars' ) ;
32
32
33
33
const githubLinks = require ( './scripts/plugins/githubLinks' ) ;
34
34
const navigation = require ( './scripts/plugins/navigation' ) ;
@@ -41,7 +41,7 @@ const latestVersion = require('./scripts/helpers/latestversion');
41
41
const DEFAULT_LANG = 'en' ;
42
42
43
43
// The history links of nodejs versions at doc/index.md
44
- const nodejsVersionsContent = require ( 'fs' )
44
+ const nodejsVersionsContent = fs
45
45
. readFileSync ( './source/nodejsVersions.md' )
46
46
. toString ( ) ;
47
47
@@ -190,18 +190,43 @@ function buildLocale(source, locale, opts) {
190
190
// Finally, this compiles the rest of the layouts present in ./layouts.
191
191
// They're language-agnostic, but have to be regenerated for every locale
192
192
// 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
+ } )
205
230
. use ( layouts ( ) )
206
231
// Pipes the generated files into their respective subdirectory in the build
207
232
// directory.
0 commit comments