Skip to content

Commit b807035

Browse files
authored
Merge pull request #16775 from github/support-hardcoded-versions-in-links
Support hardcoded versions in links
2 parents 9fef524 + 639e324 commit b807035

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

content/rest/overview/troubleshooting.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ curl -H 'Authorization: token my-oauth-token' https://api.github.com/user/repos
6363

6464
#### Calls to OAuth Authorizations API
6565

66-
If you're making [OAuth Authorization API](/enterprise-server@2.22/rest/reference/oauth-authorizations) calls to manage your OAuth app's authorizations or to generate access tokens, similar to this example:
66+
If you're making [OAuth Authorization API](/enterprise-server/rest/reference/oauth-authorizations) calls to manage your OAuth app's authorizations or to generate access tokens, similar to this example:
6767

6868
```bash
6969
curl -u my_username:my_password -X POST "https://api.github.com/authorizations" -d '{"scopes":["public_repo"], "note":"my token", "client_id":"my_client_id", "client_secret":"my_client_secret"}'

lib/rewrite-local-links.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const externalRedirects = Object.keys(require('./redirects/external-sites'))
22
const pathUtils = require('./path-utils')
33
const assert = require('assert')
44
const nonEnterpriseDefaultVersion = require('./non-enterprise-default-version')
5+
const supportedPlans = Object.values(require('./all-versions')).map(v => v.plan)
56

67
// Content authors write links like `/some/article/path`, but they need to be
78
// rewritten on the fly to match the current language and page version
@@ -24,11 +25,21 @@ function getNewHref (link, languageCode, version) {
2425
// e.g. `/contact` should not be replaced with `/en/contact`
2526
if (externalRedirects.includes(href)) return
2627

28+
let newHref
29+
30+
// If the link has a hardcoded plan name in it (e.g., /enterprise-server/rest/reference/oauth-authorizations),
31+
// only rewrite it with a language code
32+
if (supportedPlans.includes(href.split('/')[1])) {
33+
newHref = pathUtils.getPathWithLanguage(href, languageCode)
34+
}
35+
2736
// If link is dotcom-only, just get the language code
2837
// Otherwise, get the versioned path with language code
29-
const newHref = link.hasClass('dotcom-only')
30-
? pathUtils.getVersionedPathWithLanguage(href, nonEnterpriseDefaultVersion, languageCode)
31-
: pathUtils.getVersionedPathWithLanguage(href, version, languageCode)
38+
if (!newHref) {
39+
newHref = link.hasClass('dotcom-only')
40+
? pathUtils.getVersionedPathWithLanguage(href, nonEnterpriseDefaultVersion, languageCode)
41+
: pathUtils.getVersionedPathWithLanguage(href, version, languageCode)
42+
}
3243

3344
if (href !== newHref) link.attr('href', newHref)
3445
}

0 commit comments

Comments
 (0)