Skip to content

Commit c34e2c0

Browse files
author
Maledong
authored
fix: Wrong URL to a missing translation page (#4885)
There're some files that aren't translated into the locale, which causes the "404 Page Not Found" Error when clicking "Edit on GitHub". Now the current solution is: If the file doesn't exist, it will create a new blank file, with a link of translation guide there to guide what to do next. The user can either continue translating or abandoning it by clicking "Cancel" or "Submit".
1 parent c8aaa76 commit c34e2c0

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

scripts/plugins/githubLinks.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const fs = require('fs');
77
const isEditable = `(security|index).html|(about|download|docs|foundation|get-involved|knowledge)\\${sep}`;
88
const isEditableReg = new RegExp(isEditable);
99

10-
// This middleware adds "Edit on GitHub" links to every editable page
1110
function githubLinks(options) {
1211
return (files, m, next) => {
1312
Object.keys(files).forEach((path) => {
@@ -18,7 +17,9 @@ function githubLinks(options) {
1817
const file = files[path];
1918
path = path.replace('.html', '.md').replace(/\\/g, '/');
2019

21-
const currentFilePath = resolve(
20+
// Step 1: Check each page's URL (generated by "permalinks") really matches
21+
// the real file when converted back to "md".
22+
let currentFilePath = resolve(
2223
__dirname,
2324
`../../locale/${options.locale}/${path}`
2425
);
@@ -27,7 +28,23 @@ function githubLinks(options) {
2728
path = path.replace('/index.md', '.md');
2829
}
2930

30-
const url = `https://github.com/nodejs/nodejs.org/edit/main/locale/${options.locale}/${path}`;
31+
// Step 2: Check again each page URL's really exists or not (Because some files aren't
32+
// localized, you can NEVER find the md file under such localization but under 'en').
33+
// we have to create a new file with the given name here:
34+
// E.g: 1. Create a new file named "aaa.md" under "locale/zh-cn/":
35+
// https://github.com/nodejs/nodejs.org/new/main/locale/zh-cn/locale?filename=aaa.md
36+
// E.g: 2. Create a new file with new folders:
37+
// https://github.com/nodejs/nodejs.org/new/main/locale/zh-cn/locale?filename=folder1/folder2.../folderN/filename.md
38+
let url = `https://github.com/nodejs/nodejs.org/edit/main/locale/${options.locale}/${path}`;
39+
40+
currentFilePath = resolve(
41+
__dirname,
42+
`../../locale/${options.locale}/${path}`
43+
);
44+
if (!fs.existsSync(currentFilePath)) {
45+
url = `https://github.com/nodejs/nodejs.org/new/main/locale/${options.locale}/locale?filename=${path}&value=contribute%20your%20translation%20here,for%20more%20you%20can%20see:%20https://github.com/nodejs/nodejs.org/blob/main/TRANSLATION.md`;
46+
}
47+
3148
const editOnGitHubTrans = options.site.editOnGithub || 'Edit on GitHub';
3249
const replCallBack = (match, $1, $2) => {
3350
return `<div class="openjsfoundation-footer-edit">

0 commit comments

Comments
 (0)