Bazel docs: Fix Edit button

The new doc website has a new URL structure. This change adapts the page extraction code.
It also restores the CSS for the edit button which got deleted during refactoring.

Fix #3272

RELNOTES: None
PiperOrigin-RevId: 160279009
diff --git a/site/_layouts/documentation.html b/site/_layouts/documentation.html
index 73e717f..77e46b4 100644
--- a/site/_layouts/documentation.html
+++ b/site/_layouts/documentation.html
@@ -108,13 +108,14 @@
         <div class="col-lg-9">
           <a id="gh-edit" class="gh-edit default-hidden"><i class="fa fa-pencil" aria-hidden="true"></i> Edit</a>
           <script>
+            var versionDocsURLRegex = /\/versions\/[\w\.]+\/(.*)/;
             var ghDocsBazeURL = 'https://github.com/bazelbuild/bazel/tree/master/site/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 there is an edit button and we are not in the Build Encyclopedia
             if (editButton
-                && window.location.pathname.split('docs/').length > 1
+                && window.location.pathname.match(versionDocsURLRegex)
                 && window.location.pathname.lastIndexOf('/be/') == -1) {
-              var docFile = window.location.pathname.split('docs/')[1];
+              var docFile = window.location.pathname.match(versionDocsURLRegex)[1];
               // some pages are now using markdown :(
               if (docFile !== 'bazel-user-manual.html'
                   && docFile !== 'build-ref.html'
diff --git a/site/_sass/docs.scss b/site/_sass/docs.scss
new file mode 100644
index 0000000..95cbf3a
--- /dev/null
+++ b/site/_sass/docs.scss
@@ -0,0 +1,7 @@
+.gh-edit {
+  float: right;
+}
+
+.gh-edit.default-hidden {
+  visibility: hidden;
+}
diff --git a/site/css/main.scss b/site/css/main.scss
index 0ee13b8..402b94f 100644
--- a/site/css/main.scss
+++ b/site/css/main.scss
@@ -5,6 +5,7 @@
 @import "footer.scss";
 @import "navbar.scss";
 @import "sidebar.scss";
+@import "docs.scss";
 @import "be.scss";
 
 @import "syntax.scss";