Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 40 additions & 15 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ const path = require('path');
const Metalsmith = require('metalsmith');
const collections = require('metalsmith-collections');
const feed = require('metalsmith-feed');
const discoverHelpers = require('metalsmith-discover-helpers');
const discoverPartials = require('metalsmith-discover-partials');
const layouts = require('metalsmith-layouts');
const markdown = require('@metalsmith/markdown');
const permalinks = require('@metalsmith/permalinks');
Expand All @@ -29,6 +27,8 @@ const ncp = require('ncp');
const junk = require('junk');
const semver = require('semver');
const replace = require('metalsmith-one-replace');
const glob = require('glob');
const Handlebars = require('handlebars');

const githubLinks = require('./scripts/plugins/githubLinks');
const navigation = require('./scripts/plugins/navigation');
Expand All @@ -41,7 +41,7 @@ const latestVersion = require('./scripts/helpers/latestversion');
const DEFAULT_LANG = 'en';

// The history links of nodejs versions at doc/index.md
const nodejsVersionsContent = require('fs')
const nodejsVersionsContent = fs
.readFileSync('./source/nodejsVersions.md')
.toString();

Expand Down Expand Up @@ -190,18 +190,43 @@ function buildLocale(source, locale, opts) {
// Finally, this compiles the rest of the layouts present in ./layouts.
// They're language-agnostic, but have to be regenerated for every locale
// anyways.
.use(
discoverPartials({
directory: 'layouts/partials',
pattern: /\.hbs$/
})
)
.use(
discoverHelpers({
directory: 'scripts/helpers',
pattern: /\.js$/
})
)
.use((files, metalsmith, done) => {
const fsPromises = require('fs/promises');
glob(
`${metalsmith.path('layouts/partials')}/**/*.hbs`,
{},
async (err, matches) => {
if (err) {
throw err;
}
await Promise.all(
matches.map(async (file) => {
const contents = await fsPromises.readFile(file, 'utf8');
const id = path.basename(file, path.extname(file));
return Handlebars.registerPartial(id, contents);
})
);
done();
}
);
})
.use((files, metalsmith, done) => {
glob(
`${metalsmith.path('scripts/helpers')}/**/*.js`,
{},
(err, matches) => {
if (err) {
throw err;
}
matches.forEach((file) => {
const fn = require(path.resolve(file));
const id = path.basename(file, path.extname(file));
return Handlebars.registerHelper(id, fn);
});
done();
}
);
})
.use(layouts())
// Pipes the generated files into their respective subdirectory in the build
// directory.
Expand Down
113 changes: 5 additions & 108 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@
"marked": "^4.0.14",
"metalsmith": "^2.4.2",
"metalsmith-collections": "^0.9.0",
"metalsmith-discover-helpers": "^0.1.1",
"metalsmith-discover-partials": "^0.1.2",
"metalsmith-feed": "^1.0.0",
"metalsmith-layouts": "^2.3.1",
"metalsmith-one-replace": "^0.1.7",
Expand All @@ -68,6 +66,7 @@
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-promise": "^6.0.0",
"glob": "^7.2.0",
"lockfile-lint": "^4.7.4",
"nock": "^13.2.4",
"node-fetch": "^2.6.7",
Expand Down