| 187 | // (the pathname after the language and version part) until it |
| 188 | // finds one string replacement that yields either a page or a redirect. |
| 189 | function tryReplacements(prefix, suffix, { pages, redirects }) { |
| 190 | const test = (suffix) => { |
| 191 | // This is a generally broad search and replace and this particular |
| 192 | // replacement has never been present in api documentation only enterprise |
| 193 | // admin documentation, so we're excluding the REST api pages |
| 194 | if (suffix.includes('/rest')) { |
| 195 | return false |
| 196 | } |
| 197 | const candidateAsRedirect = prefix + suffix |
| 198 | const candidateAsURL = '/en' + candidateAsRedirect |
| 199 | return candidateAsRedirect in redirects || candidateAsURL in pages |
| 200 | } |
| 201 | |
| 202 | let attempt = suffix.replace('/user', '/github') |
| 203 | if (test(attempt)) return attempt |
| 204 | |
| 205 | attempt = suffix.replace('/user', '') |
| 206 | if (test(attempt)) return attempt |
| 207 | |
| 208 | attempt = suffix.replace('/admin/guides', '/admin') |
| 209 | if (test(attempt)) return attempt |
| 210 | |
| 211 | attempt = suffix.replace('/admin/guides/user', '/admin/github') |
| 212 | if (test(attempt)) return attempt |
| 213 | |
| 214 | attempt = suffix.replace('/admin/guides', '/admin').replace('/user', '/github') |
| 215 | if (test(attempt)) return attempt |
| 216 | } |