forked from nodejs/nodejs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithubLinks.js
More file actions
32 lines (25 loc) · 1011 Bytes
/
Copy pathgithubLinks.js
File metadata and controls
32 lines (25 loc) · 1011 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
'use strict';
const sep = require('path').sep;
// add suffix (".html" or sep for windows test) to each part of regex
// to ignore possible occurrences in titles (e.g. blog posts)
const isEditable = `(security|index).html|(about|download|docs|foundation|get-involved|knowledge)\\${sep}`;
const isEditableReg = new RegExp(isEditable);
// This middleware adds "Edit on GitHub" links to every editable page
function githubLinks(options) {
return (files, m, next) => {
Object.keys(files).forEach((path) => {
if (!isEditableReg.test(path)) {
return;
}
const file = files[path];
path = path.replace('.html', '.md').replace(/\\/g, '/');
const url = `https://github.com/nodejs/nodejs.org/edit/main/locale/${options.locale}/${path}`;
const contents =
file.contents.toString() +
` <input type = "hidden" id = "editOnGitHubUrl" value="${url}"/> `;
file.contents = Buffer.from(contents);
});
next();
};
}
module.exports = githubLinks;