Skip to content

Commit 1f0f8b5

Browse files
authored
Merge pull request #17244 from github/repo-sync
repo sync
2 parents 42247fa + a2e65a0 commit 1f0f8b5

File tree

9 files changed

+158
-1
lines changed

9 files changed

+158
-1
lines changed

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = {
1313
babelOptions: { configFile: './.babelrc' },
1414
sourceType: 'module',
1515
},
16-
ignorePatterns: ['tmp/*', '!/.*', '/.next/'],
16+
ignorePatterns: ['tmp/*', '!/.*', '/.next/', 'script/bookmarklets/*'],
1717
rules: {
1818
'import/no-extraneous-dependencies': ['error', { packageDir: '.' }],
1919
},

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
translations/
22
includes/
33
data/release-notes/
4+
script/bookmarklets/

contributing/development.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ This repo has configuration for debugging with VS Code's built-in Node Debugger.
4848

4949
For more detailed instructions, please see this [VS Code recipe](https://github.com/Microsoft/vscode-recipes/tree/master/nodemon). You can also learn more about debugging using VS Code [here](https://code.visualstudio.com/docs/editor/debugging).
5050

51+
### Using browser shortcuts
52+
53+
The [`script/bookmarklets`](../script/bookmarklets) directory contains some browser shortcuts that can help with reviewing GitHub documentation. See [`script/bookmarklets/README.md`](../script/bookmarklets/README.md) for details.
54+
5155
### Viewing a top-level table of contents
5256

5357
While running the local server, you can visit [localhost:4000/dev-toc](http://localhost:4000/dev-toc) to view a top-level TOC of all the content in the site. This page is not available on https://docs.github.com. It was created for internal GitHub writers' use.

script/bookmarklets/README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Bookmarklets
2+
3+
The [bookmarklets](https://en.wikipedia.org/wiki/Bookmarklet) in this directory are browser shortcuts that may help with reviewing GitHub documentation. We may eventually build the functionality they provide into Docs preview environments, but these are handy hacks for now.
4+
5+
## Installing bookmarklets
6+
7+
For each bookmarklet described below, create a new bookmark in your browser with a descriptive name, open the JavaScript file and copy its contents, and paste the JavaScript _as the bookmark's URL_.
8+
9+
Clicking the bookmark will then execute the JavaScript.
10+
11+
⚠️ For Safari, you'll need to do the following:
12+
13+
1. Go to **Safari** > **Preferences** > **Advanced** and enable **Show Develop menu in menu bar**.
14+
2. Go to **Develop** and enable **Allow JavaScript from Smart Search field**.
15+
16+
## "View in development" toggle
17+
18+
[`script/bookmarklets/view-in-development.js`](./view-in-development.js)
19+
20+
When you're looking at a page on docs.github.com or a preview server at preview.ghdocs.com, clicking this bookmarklet will load the same path you're viewing but on your local server running at localhost:4000.
21+
22+
## "View in production" toggle
23+
24+
[`script/bookmarklets/view-in-production.js`](./view-in-production.js)
25+
26+
When you're looking at a page on a preview server at preview.ghdocs.com or your local server running at localhost:4000, clicking this bookmarklet will load the same path you're viewing but on the live documentation site at docs.github.com.
27+
28+
## Open a docs article in VS Code
29+
30+
[`script/bookmarklets/open-in-vscode.js`](./open-in-vscode.js)
31+
32+
When you're looking at a page on either docs.github.com, preview.ghdocs.com, or localhost:400, clicking this bookmarklet will open the source Markdown file from your local checkout in VS Code.
33+
34+
The installation requires a few steps:
35+
36+
1. Copy the contents of [`script/bookmarklets/open-in-vscode.js`](./open-in-vscode.js).
37+
1. Browse to https://chriszarate.github.io/bookmarkleter/ and paste the code into the box.
38+
1. Find the path of **your local checkout** of the docs repo you want to open files from (for example, `/Users/<USERNAME>/repos/docs`).
39+
1. Paste the path in place of where it says `REPLACE_ME` in line 1 (make sure to leave the single quotes around it).
40+
1. Change the title to something like `Open in VSC`.
41+
1. Drag the generated link onto your bookmarks bar.
42+
43+
## Add preview links to PRs
44+
45+
[`script/bookmarklets/add-pr-links.js`](./add-pr-links.js)
46+
47+
This bookmarklet modifies the `Files changed` page of a GitHub pull request that has a current staging deployment. For each Markdown file in the diff view, it adds links to the preview deployment of the file for each version: `FPT / GHEC / GHES / AE`. (Some of these may redirect to another version or 404 if that version of the page doesn't exist.)
48+
49+
Note: readable JavaScript source lives in `script/bookmarklets/pr-link-source.js`. The bookmarklet code was generated via https://chriszarate.github.io/bookmarkleter.

script/bookmarklets/add-pr-links.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* The path to your local copy of repo */
2+
const checkoutPath = 'REPLACE_ME'
3+
4+
const filepath = window.location.pathname.replace(/\/en\/([^@]+?@[^@]+?\/)?/, '/content/')
5+
const isIndexFile = filepath.split('/').length < 5
6+
const filename = isIndexFile ? '/index.md' : '.md'
7+
const fullpath = 'vscode://file' + checkoutPath + filepath + filename
8+
window.open(fullpath, '_blank')
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
!(async function () {
2+
const regexp = /https:\/\/github.com\/github\/([^\/]*)\/pull\/\d*\/files/;
3+
4+
if (!window.location.href.match(regexp)) {
5+
window.alert("You're not on a PR 'Files changed' page. 🙃");
6+
return
7+
}
8+
9+
let conversation_url = window.location.href.replace(/files.*/g, "");
10+
11+
// get the preview deployment URL by loading the 'Conversation' page, and searching for the 'View deployment' link
12+
let deployment_url = await fetch(conversation_url)
13+
.then(function (response) {
14+
return response.text();
15+
})
16+
.then(function (html) {
17+
// Convert the HTML string into a document object
18+
var parser = new DOMParser();
19+
var doc = parser.parseFromString(html, "text/html");
20+
21+
var elements = doc.getElementsByClassName("TimelineItem");
22+
// Find the element that is a link that contains the text "View deployment"
23+
for (var i = 0; i < elements.length; i++) {
24+
var element = elements[i];
25+
var links = element.getElementsByTagName("a");
26+
for (var j = 0; j < links.length; j++) {
27+
var link = links[j];
28+
if (link.innerText.match(/View deployment/)) {
29+
// Get the href of the link
30+
var deployment_url = link.getAttribute("href");
31+
}
32+
}
33+
}
34+
// This should return the last link that contains the text "View deployment" (there might be multiple ones if there are multiple deployments)
35+
return deployment_url;
36+
});
37+
if (deployment_url == null) {
38+
window.alert("No preview deployment found! 😭");
39+
return;
40+
}
41+
// strip any trailing slash from deployment_url
42+
deployment_url = deployment_url.replace(/\/$/, "");
43+
44+
var url_fpt = deployment_url + "/en";
45+
var url_ghec = deployment_url + "/en/enterprise-cloud@latest";
46+
var url_ghes = deployment_url + "/en/enterprise-server@latest";
47+
var url_ae = deployment_url + "/en/github-ae@latest";
48+
var fpt = "FPT";
49+
var ghes = "GHES";
50+
var ghec = "GHEC";
51+
var ae = "AE";
52+
53+
const file_info = document.querySelectorAll("div.file-info");
54+
for (var i = 0; i < file_info.length; i++) {
55+
var link = file_info[i].querySelector("a").title;
56+
if (link.search("data/") === 0) {
57+
continue;
58+
} else {
59+
var regex = /\.md$/;
60+
var markdownfile = link.search(regex) >= 0;
61+
if (markdownfile) {
62+
console.log("link: " + link);
63+
link = link.replace(regex, "");
64+
link = link.replace(/^content/, "");
65+
link = link.replace(/\/index/, "");
66+
var span = document.createElement("SPAN");
67+
span.style.fontFamily =
68+
"-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif";
69+
span.innerHTML = "&nbsp; View: ";
70+
71+
span = addLink(span, fpt, url_fpt + link);
72+
span.innerHTML += " / ";
73+
span = addLink(span, ghec, url_ghec + link);
74+
span.innerHTML += " / ";
75+
span = addLink(span, ghes, url_ghes + link);
76+
span.innerHTML += " / ";
77+
span = addLink(span, ae, url_ae + link);
78+
79+
file_info[i].appendChild(span);
80+
}
81+
}
82+
}
83+
84+
function addLink(span, link_name, link_href) {
85+
var anchor = document.createElement("A");
86+
anchor.innerHTML = link_name;
87+
anchor.href = link_href;
88+
anchor.target = "_blank";
89+
span.appendChild(anchor);
90+
return span;
91+
}
92+
})();
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
javascript:(()=>{window.location.href=window.location.href.replace(/https:\/\/docs\.github\.com/,'http://localhost:4000').replace(/https:\/\/.*\..*\.(com|net|dev|io|org|ms)/,'http://localhost:4000')})()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
javascript:(()=>{window.location.href=window.location.href.replace(/http:\/\/localhost:4000/,'https://docs.github.com').replace(/https:\/\/.*\..*\.(com|net|dev|io|org|ms)/,'https://docs.github.com')})()

0 commit comments

Comments
 (0)