diff --git a/build.js b/build.js index a7e4d4cef8c66..2db0866731bd4 100755 --- a/build.js +++ b/build.js @@ -23,6 +23,7 @@ const stylus = require('stylus') const ncp = require('ncp') const junk = require('junk') +const githubLinks = require('./scripts/plugins/githubLinks') const navigation = require('./scripts/plugins/navigation') const anchorMarkdownHeadings = require('./scripts/plugins/anchor-markdown-headings') const loadVersions = require('./scripts/load-versions') @@ -209,33 +210,6 @@ function withPreserveLocale (preserveLocale) { } } -// This middleware adds "Edit on GitHub" links to every editable page -function githubLinks (options) { - return (files, m, next) => { - // add suffix (".html" or "/" or "\" for windows) to each part of regex - // to ignore possible occurrences in titles (e.g. blog posts) - const isEditable = /security\.html|about(\/|\\)|docs(\/|\\)|foundation(\/|\\)|get-involved(\/|\\)|knowledge(\/|\\)/ - - Object.keys(files).forEach((path) => { - if (!isEditable.test(path)) { - return - } - - const file = files[path] - const url = `https://github.com/nodejs/nodejs.org/edit/master/locale/${options.locale}/${path.replace('.html', '.md').replace(/\\/g, '/')}` - const editText = options.site.editOnGithub || 'Edit on GitHub' - - const contents = file.contents.toString().replace(/(.*?)<\/h1>/, (match, $1, $2) => { - return `${editText} ${$2}` - }) - - file.contents = Buffer.from(contents) - }) - - next() - } -} - // This function builds the static/css folder for all the Stylus files. function buildCSS () { console.log('[stylus] static/css started') diff --git a/scripts/plugins/githubLinks.js b/scripts/plugins/githubLinks.js new file mode 100644 index 0000000000000..28b45ca73f07a --- /dev/null +++ b/scripts/plugins/githubLinks.js @@ -0,0 +1,30 @@ +'use strict' + +// This middleware adds "Edit on GitHub" links to every editable page +function githubLinks (options) { + return (files, m, next) => { + // add suffix (".html" or "/" or "\" for Windows) to each part of regex + // to ignore possible occurrences in titles (e.g. blog posts) + const isEditable = /security\.html|about(\/|\\)|docs(\/|\\)|foundation(\/|\\)|get-involved(\/|\\)|knowledge(\/|\\)/ + + Object.keys(files).forEach((path) => { + if (!isEditable.test(path)) { + return + } + + const file = files[path] + const url = `https://github.com/nodejs/nodejs.org/edit/master/locale/${options.locale}/${path.replace('.html', '.md').replace(/\\/g, '/')}` + const editText = options.site.editOnGithub || 'Edit on GitHub' + + const contents = file.contents.toString().replace(/(.*?)<\/h1>/, (match, $1, $2) => { + return `${editText} ${$2}` + }) + + file.contents = Buffer.from(contents) + }) + + next() + } +} + +module.exports = githubLinks