From 7252864b31c83dadf1cde598e4e90e178ef60051 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sat, 7 Jul 2018 15:33:06 -0700 Subject: [PATCH 1/5] doc: add "Edit on GitHub" link Proof of concept for an "Edit on GitHub" link, inspired by the Serverless docs. One issue is that the link is to the version of the docs on the master branch even if the person was reading a different version of the doc. I don't consider that a big problem, although we can always remove the link if it turns out to be a big problem. I don't think there is a good solution. PRs need to be opened against the master branch generally. Having a bunch of PRs against staging branches is probably not what we want. If there's an update to one version of the doc, there will usually be an update to other versions. --- doc/template.html | 1 + tools/doc/html.js | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/doc/template.html b/doc/template.html index bb3e2bf8b4f2f0..fdcf0d5821b56f 100644 --- a/doc/template.html +++ b/doc/template.html @@ -35,6 +35,7 @@

Node.js __VERSION__ Documentation

View as JSON __ALTDOCS__ + __EDIT_ON_GITHUB__
diff --git a/tools/doc/html.js b/tools/doc/html.js index 0e254f1203f7a6..edd9c7fd882317 100644 --- a/tools/doc/html.js +++ b/tools/doc/html.js @@ -96,6 +96,8 @@ function toHTML({ input, filename, nodeVersion, analytics }, cb) { HTML = HTML.replace('__ALTDOCS__', ''); } + HTML = HTML.replace('__EDIT_ON_GITHUB__', editOnGitHub(filename)); + // Content insertion has to be the last thing we do with the lexed tokens, // because it's destructive. HTML = HTML.replace('__CONTENT__', marked.parser(lexed)); @@ -377,3 +379,8 @@ function altDocs(filename, docCreated) { ` : ''; } + +function editOnGitHub(filename) { + const svg = ''; + return `
  • ${svg}Edit on GitHub
  • `; +} From 9d6f38dfdc93a61057b7b0a3ea1a6a31f5d85972 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 10 Jul 2018 15:47:23 -0700 Subject: [PATCH 2/5] squash! update svg per silverwind --- tools/doc/html.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/doc/html.js b/tools/doc/html.js index edd9c7fd882317..f54937e8b14738 100644 --- a/tools/doc/html.js +++ b/tools/doc/html.js @@ -381,6 +381,7 @@ function altDocs(filename, docCreated) { } function editOnGitHub(filename) { - const svg = ''; + // eslint-disable-next-line max-len + const svg = ''; return `
  • ${svg}Edit on GitHub
  • `; } From 3620da2136886a528099dc44243ed36219d21fb5 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 10 Jul 2018 16:57:20 -0700 Subject: [PATCH 3/5] squash! move css and svg to own files --- doc/api_assets/github_icon.svg | 3 +++ doc/api_assets/style.css | 7 +++++++ tools/doc/html.js | 4 +--- 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 doc/api_assets/github_icon.svg diff --git a/doc/api_assets/github_icon.svg b/doc/api_assets/github_icon.svg new file mode 100644 index 00000000000000..8b983b1ade0e79 --- /dev/null +++ b/doc/api_assets/github_icon.svg @@ -0,0 +1,3 @@ + + + diff --git a/doc/api_assets/style.css b/doc/api_assets/style.css index b4da3375d5b521..f9e1cc170d8880 100644 --- a/doc/api_assets/style.css +++ b/doc/api_assets/style.css @@ -504,6 +504,13 @@ th > *:last-child, td > *:last-child { visibility: hidden; } +.github_icon { + height: 17px; + width: 16px; + vertical-align: middle; + margin: -2px 3px 0 0; +} + @media only screen and (max-width: 1024px) { #content { overflow: visible; diff --git a/tools/doc/html.js b/tools/doc/html.js index f54937e8b14738..a7cc505c38179c 100644 --- a/tools/doc/html.js +++ b/tools/doc/html.js @@ -381,7 +381,5 @@ function altDocs(filename, docCreated) { } function editOnGitHub(filename) { - // eslint-disable-next-line max-len - const svg = ''; - return `
  • ${svg}Edit on GitHub
  • `; + return `
  • Edit on GitHub
  • `; } From d0df43f06231c1cdc44af6e61bbf2f8edae1cf27 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Thu, 12 Jul 2018 20:12:20 -0700 Subject: [PATCH 4/5] squash! do not include edit-on-github link in all.html --- tools/doc/allhtml.js | 3 ++- tools/doc/html.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/doc/allhtml.js b/tools/doc/allhtml.js index 1c84e13d0ab79c..67c6533f548c14 100644 --- a/tools/doc/allhtml.js +++ b/tools/doc/allhtml.js @@ -52,7 +52,8 @@ let all = toc.replace(/index\.html/g, 'all.html') .replace('', '') .replace('index.json', 'all.json') .replace('api-section-index', 'api-section-all') - .replace('data-id="index"', 'data-id="all"'); + .replace('data-id="index"', 'data-id="all"') + .replace(/
  • .*?<\/li>/, ''); // Clean up the title. all = all.replace(/.*?\| /, '<title>'); diff --git a/tools/doc/html.js b/tools/doc/html.js index a7cc505c38179c..94f18b6fdf3287 100644 --- a/tools/doc/html.js +++ b/tools/doc/html.js @@ -381,5 +381,5 @@ function altDocs(filename, docCreated) { } function editOnGitHub(filename) { - return `<li><a href="https://github.com/nodejs/node/edit/master/doc/api/${filename}.md"><img src="assets/github_icon.svg" alt="" class="github_icon">Edit on GitHub</a></li>`; + return `<li class="edit-on-github"><a href="https://github.com/nodejs/node/edit/master/doc/api/${filename}.md"><img src="assets/github_icon.svg" alt="" class="github_icon">Edit on GitHub</a></li>`; } From c69cae7ef957c529fbced9218cde29a3a21165ae Mon Sep 17 00:00:00 2001 From: Rich Trott <rtrott@gmail.com> Date: Thu, 12 Jul 2018 20:34:02 -0700 Subject: [PATCH 5/5] squash! move svg inline again --- doc/api_assets/github_icon.svg | 3 --- doc/api_assets/style.css | 2 -- tools/doc/allhtml.js | 2 +- tools/doc/html.js | 4 +++- 4 files changed, 4 insertions(+), 7 deletions(-) delete mode 100644 doc/api_assets/github_icon.svg diff --git a/doc/api_assets/github_icon.svg b/doc/api_assets/github_icon.svg deleted file mode 100644 index 8b983b1ade0e79..00000000000000 --- a/doc/api_assets/github_icon.svg +++ /dev/null @@ -1,3 +0,0 @@ -<svg xmlns="http://www.w3.org/2000/svg"> - <path d="M8 0a8 8 0 0 0-2.5 15.6c.4 0 .5-.2.5-.4v-1.5c-2 .4-2.5-.5-2.7-1 0-.1-.5-.9-.8-1-.3-.2-.7-.6 0-.6.6 0 1 .6 1.2.8.7 1.2 1.9 1 2.4.7 0-.5.2-.9.5-1-1.8-.3-3.7-1-3.7-4 0-.9.3-1.6.8-2.2 0-.2-.3-1 .1-2 0 0 .7-.3 2.2.7a7.4 7.4 0 0 1 4 0c1.5-1 2.2-.8 2.2-.8.5 1.1.2 2 .1 2.1.5.6.8 1.3.8 2.2 0 3-1.9 3.7-3.6 4 .3.2.5.7.5 1.4v2.2c0 .2.1.5.5.4A8 8 0 0 0 16 8a8 8 0 0 0-8-8z"/> -</svg> diff --git a/doc/api_assets/style.css b/doc/api_assets/style.css index f9e1cc170d8880..f59f3770048097 100644 --- a/doc/api_assets/style.css +++ b/doc/api_assets/style.css @@ -505,8 +505,6 @@ th > *:last-child, td > *:last-child { } .github_icon { - height: 17px; - width: 16px; vertical-align: middle; margin: -2px 3px 0 0; } diff --git a/tools/doc/allhtml.js b/tools/doc/allhtml.js index 67c6533f548c14..d185538ab683b6 100644 --- a/tools/doc/allhtml.js +++ b/tools/doc/allhtml.js @@ -53,7 +53,7 @@ let all = toc.replace(/index\.html/g, 'all.html') .replace('index.json', 'all.json') .replace('api-section-index', 'api-section-all') .replace('data-id="index"', 'data-id="all"') - .replace(/<li class="edit-on-github">.*?<\/li>/, ''); + .replace(/<li class="edit_on_github">.*?<\/li>/, ''); // Clean up the title. all = all.replace(/<title>.*?\| /, '<title>'); diff --git a/tools/doc/html.js b/tools/doc/html.js index 94f18b6fdf3287..0f3293dadd51d1 100644 --- a/tools/doc/html.js +++ b/tools/doc/html.js @@ -380,6 +380,8 @@ function altDocs(filename, docCreated) { ` : ''; } +// eslint-disable-next-line max-len +const githubLogo = '<span class="github_icon"><svg height="16" width="16" viewBox="0 0 16.1 16.1" fill="currentColor"><path d="M8 0a8 8 0 0 0-2.5 15.6c.4 0 .5-.2.5-.4v-1.5c-2 .4-2.5-.5-2.7-1 0-.1-.5-.9-.8-1-.3-.2-.7-.6 0-.6.6 0 1 .6 1.2.8.7 1.2 1.9 1 2.4.7 0-.5.2-.9.5-1-1.8-.3-3.7-1-3.7-4 0-.9.3-1.6.8-2.2 0-.2-.3-1 .1-2 0 0 .7-.3 2.2.7a7.4 7.4 0 0 1 4 0c1.5-1 2.2-.8 2.2-.8.5 1.1.2 2 .1 2.1.5.6.8 1.3.8 2.2 0 3-1.9 3.7-3.6 4 .3.2.5.7.5 1.4v2.2c0 .2.1.5.5.4A8 8 0 0 0 16 8a8 8 0 0 0-8-8z"/></svg></span>'; function editOnGitHub(filename) { - return `<li class="edit-on-github"><a href="https://github.com/nodejs/node/edit/master/doc/api/${filename}.md"><img src="assets/github_icon.svg" alt="" class="github_icon">Edit on GitHub</a></li>`; + return `<li class="edit_on_github"><a href="https://github.com/nodejs/node/edit/master/doc/api/${filename}.md">${githubLogo}Edit on GitHub</a></li>`; }