add an edit button on Documentation pages I successfully tested the change by playing with Chrome DevTools on bazel.build, as I could not find instructions about how to run the site locally :(. Closes #2992. PiperOrigin-RevId: 156349018
diff --git a/site/_layouts/documentation.html b/site/_layouts/documentation.html index c671b29..f15444c 100644 --- a/site/_layouts/documentation.html +++ b/site/_layouts/documentation.html
@@ -107,6 +107,27 @@ </nav> </div> <div class="col-lg-9"> + <a id="gh-edit" class="default-hidden"><i class="fa fa-pencil" aria-hidden="true"></i> Edit</a> + <script> + var ghDocsBazeURL = 'https://github.com/bazelbuild/bazel/tree/master/site/versions/master/docs/'; + var editButton = document.getElementById('gh-edit'); + // if there is an edit button and we are on a doc page but not in the Build Encyclopedia + if(editButton + && window.location.pathname.split('docs/').length > 1 + && window.location.pathname.lastIndexOf('/be/') == -1) { + var docFile = window.location.pathname.split('docs/')[1]; + // some pages are now using markdown :( + if( docFile !== 'bazel-user-manual.html' + && docFile !== 'build-ref.html' + && docFile !== 'query.html' + && docFile !== 'test-encyclopedia.html') { + docFile = docFile.replace('html', 'md'); + } + editButton.href = ghDocsBazeURL + docFile; + editButton.style.visibility = 'visible'; + } + </script> + {{ content }} </div> </div>