Skip to content

Commit f8f72c5

Browse files
author
Maledong
authored
remove useless js snippets of codes for "Edit On GitHub" (#4867)
We don't need to implement it through the client side but serve side only by generating them together. Refs: #4315.
1 parent 07c543a commit f8f72c5

File tree

4 files changed

+15
-28
lines changed

4 files changed

+15
-28
lines changed

build.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ function buildLocale(source, locale, opts) {
159159
})
160160
)
161161
.use(markdown(markedOptions))
162-
.use(githubLinks({ locale, site: i18nJSON(locale) }))
163162
// Set pretty permalinks, we don't want .html suffixes everywhere.
164163
.use(
165164
permalinks({
@@ -195,6 +194,7 @@ function buildLocale(source, locale, opts) {
195194
.use(hbsReg())
196195
.use(scriptReg())
197196
.use(layouts())
197+
.use(githubLinks({ locale, site: i18nJSON(locale) }))
198198
// Pipes the generated files into their respective subdirectory in the build
199199
// directory.
200200
.destination(path.join(__dirname, 'build', locale))

layouts/partials/footer.hbs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414
<a href="https://trademark-policy.openjsf.org">Trademark Policy</a> |
1515
<a href="https://trademark-list.openjsf.org">Trademark List</a> |
1616
<a href="https://www.linuxfoundation.org/cookies">Cookie Policy</a>
17-
</p>
18-
<div class="openjsfoundation-footer-edit">
19-
| <a id="editOnGitHubLink" href="#">{{site.editOnGithub}}</a>
20-
</div>
17+
</p>
18+
<div class="openjsfoundation-footer-edit"></div>
2119
</div>
2220
</div>
2321

scripts/plugins/githubLinks.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,18 @@ function githubLinks(options) {
1717
const file = files[path];
1818
path = path.replace('.html', '.md').replace(/\\/g, '/');
1919
const url = `https://github.com/nodejs/nodejs.org/edit/main/locale/${options.locale}/${path}`;
20-
21-
const contents =
22-
file.contents.toString() +
23-
` <input type = "hidden" id = "editOnGitHubUrl" value="${url}"/> `;
20+
const editOnGitHubTrans = options.site.editOnGithub || 'Edit on GitHub';
21+
const replCallBack = (match, $1, $2) => {
22+
return `<div class="openjsfoundation-footer-edit">
23+
| <a href="${url}">${editOnGitHubTrans}</a>
24+
</div>`;
25+
};
26+
const contents = file.contents
27+
.toString()
28+
.replace(
29+
/<div class="openjsfoundation-footer-edit"><\/div>/,
30+
replCallBack
31+
);
2432

2533
file.contents = Buffer.from(contents);
2634
});

static/js/main.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -159,22 +159,3 @@
159159
winText.textContent = winText.textContent.replace(/x(86|64)/, arch);
160160
}
161161
})();
162-
(function () {
163-
// This function is used to replace the anchor
164-
// link of Edit on GitHub
165-
166-
var editOnGitHubElement = document.getElementById('editOnGitHubLink');
167-
var editOnGitHubUrlElement = document.getElementById('editOnGitHubUrl');
168-
169-
if (!editOnGitHubElement) {
170-
return;
171-
}
172-
173-
if (editOnGitHubUrlElement) {
174-
editOnGitHubElement.setAttribute('href', editOnGitHubUrlElement.value);
175-
} else {
176-
editOnGitHubElement.parentNode.parentNode.removeChild(
177-
editOnGitHubElement.parentNode
178-
);
179-
}
180-
})();

0 commit comments

Comments
 (0)