| 
7 | 7 |     <img src=" {{< relurl " images/ [email protected]"  >}}" alt="404" width="456" height="149" / >  | 
8 | 8 |   </p>  | 
9 | 9 |   <h1>That page doesn't exist.</h1>  | 
10 |  | -  <p>  | 
 | 10 | +  <p id='explanation'>  | 
11 | 11 |     We recently redesigned the site and older URLs may now lead to missing pages. We apologize for the inconvenience.  | 
12 | 12 |   </p>  | 
 | 13 | +  <script>  | 
 | 14 | +    /* Be more helpful for outdated manual versions */  | 
 | 15 | +    const match = window.location.pathname.match(/^(.*\/docs\/([^/]*))\/([0-9.]*)$/)  | 
 | 16 | +    if (match) {  | 
 | 17 | +      const [, path, command, version] = match  | 
 | 18 | + | 
 | 19 | +      const el = document.querySelector('#explanation')  | 
 | 20 | +      el.innerHTML = `Version ${version} of <a href="${  | 
 | 21 | +        path}${window.location.search}${window.location.hash  | 
 | 22 | +      }">the <code>${command}</code> manual page</a> is no longer available.`  | 
 | 23 | + | 
 | 24 | +      const url = window.location.href.substring(0, window.location.href.length - version.length - 1);  | 
 | 25 | +      (async () => {  | 
 | 26 | +        // fetch the newest version to obtain the list of versions  | 
 | 27 | +        const result = await fetch(url)  | 
 | 28 | + | 
 | 29 | +        const div = document.createElement('div')  | 
 | 30 | +        div.innerHTML = await result.text()  | 
 | 31 | +        const versions = Array.from(  | 
 | 32 | +          div  | 
 | 33 | +          .querySelector('#previous-versions-dropdown')  | 
 | 34 | +          .querySelectorAll('.version')  | 
 | 35 | +        ).map(e => e.innerHTML)  | 
 | 36 | + | 
 | 37 | +        const versionCompare = (a, b) => {  | 
 | 38 | +          b = String(b).split('.')  | 
 | 39 | +          for (const p of String(a).split('.')) {  | 
 | 40 | +            const q = b.shift()  | 
 | 41 | +            if (isNaN(q)) return +1  | 
 | 42 | +            if (p != q) return p - q  | 
 | 43 | +          }  | 
 | 44 | +          return b.length > 0 ? -1 : 0  | 
 | 45 | +        }  | 
 | 46 | + | 
 | 47 | +        let i = -1  | 
 | 48 | +        while (i + 1 < versions.length && versionCompare(version, versions[i + 1]) < 0) i++  | 
 | 49 | +        if (versions[i]) el.innerHTML += `<br />The most closesely matching page describes version <a href="${  | 
 | 50 | +          path}/${versions[i]}${window.location.search}${window.location.hash  | 
 | 51 | +        }">${versions[i]}</a>.`  | 
 | 52 | +      })().catch(console.error)  | 
 | 53 | +    }  | 
 | 54 | +  </script>  | 
13 | 55 | </div>  | 
0 commit comments