Browse code

Warning banner should only show on `/devel/` docs, not on pages with 'devel' in their titles (#70849) (#71075)

* Update docs/docsite/_themes/sphinx_rtd_theme/ansible_banner.html
* Only match paths at the beginning

Co-authored-by: Alicia Cozine <acozine@users.noreply.github.com>
Co-authored-by: Sviatoslav Sydorenko <webknjaz@redhat.com>
(cherry picked from commit 8313cc8fb1a6f879328b5178f790086a2ba580b2)

Alicia Cozine authored on 2020/08/07 06:19:59
Showing 1 changed files
... ...
@@ -1,5 +1,8 @@
1 1
 <!--- Based on sphinx versionwarning extension. Extension currently only works on READTHEDOCS -->
2 2
   <script>
3
+    startsWith = function(str, needle) {
4
+      return str.slice(0, needle.length) == needle
5
+    }
3 6
     // Create a banner if we're not on the official docs site
4 7
     if (location.host == "docs.testing.ansible.com") {
5 8
       document.write('<div id="testing_banner_id" class="admonition important">');
... ...
@@ -12,10 +15,10 @@
12 12
     }
13 13
     {% if (not READTHEDOCS) and (available_versions is defined) %}
14 14
       // Create a banner if we're not the latest version
15
-      current_url = window.location.href;
16
-      if ((current_url.search("latest") > -1) || (current_url.search("/{{ latest_version }}/") > -1)) {
15
+      current_url_path = window.location.pathname;
16
+      if (startsWith(current_url_path, "/ansible/latest/") || startsWith(current_url_path, "/ansible/{{ latest_version }}/")) {
17 17
        // no banner for latest release
18
-      } else if (current_url.search("devel") > -1) {
18
+      } else if (startsWith(current_url_path, "/ansible/devel/")) {
19 19
         document.write('<div id="banner_id" class="admonition caution">');
20 20
         para = document.createElement('p');
21 21
         banner_text=document.createTextNode("You are reading the *devel* version of the Ansible documentation - this version is not guaranteed stable. Use the version selection to the left if you want the latest stable released version.");