Skip to content

Commit 0e1dc78

Browse files
authored
Create & migrate a subject folder for Redirects (github#39052)
1 parent 36c2210 commit 0e1dc78

40 files changed

+69
-63
lines changed

.github/actions-scripts/prune-for-preview-env.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
# need these legacy redirects. Only the redirects from
1212
# front-matter will be at play.
1313
# These static redirects json files are notoriously large
14-
echo '[]' > lib/redirects/static/archived-frontmatter-valid-urls.json
15-
echo '{}' > lib/redirects/static/archived-redirects-from-213-to-217.json
14+
echo '[]' > src/redirects/lib/static/archived-frontmatter-valid-urls.json
15+
echo '{}' > src/redirects/lib/static/archived-redirects-from-213-to-217.json

.github/actions-scripts/rendered-content-link-checker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { JSONFile } from 'lowdb/node'
1212
import shortVersions from '../../middleware/contextualizers/short-versions.js'
1313
import contextualize from '../../middleware/context.js'
1414
import features from '../../middleware/contextualizers/features.js'
15-
import getRedirect from '../../lib/get-redirect.js'
15+
import getRedirect from '../../src/redirects/lib/get-redirect.js'
1616
import warmServer from '../../lib/warm-server.js'
1717
import { liquid } from '../../src/content-render/index.js'
1818
import { deprecated } from '../../lib/enterprise-server-releases.js'

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ jobs:
5353
{ name: 'linting', path: 'src/content-linter/tests', },
5454
{ name: 'observability', path: 'src/observability/tests' },
5555
{ name: 'pageinfo', path: 'src/pageinfo/tests', },
56+
{ name: 'redirects', path: 'src/redirects/tests', },
5657
{ name: 'rendering', path: 'tests/rendering', },
5758
{ name: 'rendering-fixtures', path: 'tests/rendering-fixtures', },
5859
{ name: 'rest', path: 'src/rest/tests', },

content/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ Sometimes you want to link to a Dotcom-only article in Enterprise content and yo
382382
"[GitHub's Terms of Service](/free-pro-team@latest/github/site-policy/github-terms-of-service)"
383383
```
384384

385-
Sometimes the canonical home of content moves outside the docs site. None of the links included in [`lib/redirects/external-sites.json`](/lib/redirects/external-sites.json) get rewritten. See [`contributing/redirects.md`](/contributing/redirects.md) for more info about this type of redirect.
385+
Sometimes the canonical home of content moves outside the docs site. None of the links included in [`src/redirects/lib/external-sites.json`](/src/redirects/lib/external-sites.json) get rewritten. See [`contributing/redirects.md`](/contributing/redirects.md) for more info about this type of redirect.
386386

387387
### Legacy filepaths and redirects for links
388388

contributing/redirects.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Sometimes we change the name of an article but want its old URL to redirect to i
1212

1313
### Automatic redirects for URLs that do not include a version
1414

15-
If a URL for a docs page is entered without a version segment (e.g., `https://docs.github.com/foo` instead of `https://docs.github.com/<version>/foo`), the site will automatically redirect it to the **first available version** of the page. The order of precedence is specified in `lib/all-versions.js`, where the current order is:
15+
If a URL for a docs page is entered without a version segment (e.g., `https://docs.github.com/foo` instead of `https://docs.github.com/<version>/foo`), the site will automatically redirect it to the **first available version** of the page. The order of precedence is specified in `lib/all-versions.js`, where the current order is:
1616

1717
1. Free, Pro, & Team (`fpt`)
1818
1. Enterprise Cloud (`ghec`)
@@ -25,11 +25,11 @@ If `foo.md` is available in Free, Pro, & Team, no redirect will occur because `f
2525

2626
### Redirects across versions
2727

28-
If you want the URL for one version of an article to redirect to a URL for another version, you must use [/lib/redirects/static/redirect-exceptions.txt](/lib/redirects/static/redirect-exceptions.txt) instead. For example, if you remove the Free, Pro, & Team (`fpt`) version of an article, the URL will [automatically redirect](#automatic-redirects-for-urls-that-do-not-include-a-version) to the next available version of the page. If you want it to redirect to a version that is **lower in the order of precedence**, or to a different page entirely, you must specify an exception.
28+
If you want the URL for one version of an article to redirect to a URL for another version, you must use [/src/redirects/lib/static/redirect-exceptions.txt](/src/redirects/lib/static/redirect-exceptions.txt) instead. For example, if you remove the Free, Pro, & Team (`fpt`) version of an article, the URL will [automatically redirect](#automatic-redirects-for-urls-that-do-not-include-a-version) to the next available version of the page. If you want it to redirect to a version that is **lower in the order of precedence**, or to a different page entirely, you must specify an exception.
2929

3030
Another example: we removed the `ghes` version of "[Exporting member information for your organization](https://docs.github.com/en/organizations/managing-membership-in-your-organization/exporting-member-information-for-your-organization)," but we don't want URLs that include the `enterprise-server@<release>` version segment to 404. In order to redirect `ghes` URLs to another version (such as `ghec`), we need to add an exception.
3131

32-
Each entry in [the exceptions file](/lib/redirects/static/redirect-exceptions.txt) should start with the path you want to redirect _to_, including the version, followed by an unordered list of the paths you want to redirect _from_:
32+
Each entry in [the exceptions file](/src/redirects/lib/static/redirect-exceptions.txt) should start with the path you want to redirect _to_, including the version, followed by an unordered list of the paths you want to redirect _from_:
3333

3434
```
3535
/enterprise-cloud@latest/organizations/managing-membership-in-your-organization/exporting-member-information-for-your-organization
@@ -40,11 +40,11 @@ Each entry in [the exceptions file](/lib/redirects/static/redirect-exceptions.tx
4040

4141
## External redirects
4242

43-
Sometimes the canonical home of some content moves outside the help site. For these types of redirects, we add entries to [/lib/redirects/external-sites.json](/lib/redirects/external-sites.json).
43+
Sometimes the canonical home of some content moves outside the help site. For these types of redirects, we add entries to [/src/redirects/lib/external-sites.json](/src/redirects/lib/external-sites.json).
4444

4545
## Custom redirects
4646

47-
We also have custom routing code that automatically creates redirects under the hood for things like moved Admin guide pages. This code lives in [/lib/redirects/get-old-paths-from-permalink.js](/lib/redirects/get-old-paths-from-permalink.js). All redirects for the site are compiled when the server starts by [/lib/redirects/precompile.js](/lib/redirects/precompile.js).
47+
We also have custom routing code that automatically creates redirects under the hood for things like moved Admin guide pages. This code lives in [/src/redirects/lib/get-old-paths-from-permalink.js](/src/redirects/lib/get-old-paths-from-permalink.js). All redirects for the site are compiled when the server starts by [/src/redirects/lib/precompile.js](/src/redirects/lib/precompile.js).
4848

4949
See [Links and image paths](../content/README.md#links-and-image-paths) for info on how links and images are rewritten on the fly at page render time.
5050

lib/find-page.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getLanguageCode } from './patterns.js'
2-
import getRedirect from './get-redirect.js'
2+
import getRedirect from '#src/redirects/lib/get-redirect.js'
33

44
export default function findPage(href, pages, redirects) {
55
if (Array.isArray(pages)) throw new Error("'pages' is not supposed to be an array")

lib/page.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import path from 'path'
33
import cheerio from 'cheerio'
44
import patterns from './patterns.js'
55
import getApplicableVersions from './get-applicable-versions.js'
6-
import generateRedirectsForPermalinks from './redirects/permalinks.js'
6+
import generateRedirectsForPermalinks from '#src/redirects/lib/permalinks.js'
77
import getEnglishHeadings from './get-english-headings.js'
88
import getTocItems from './get-toc-items.js'
99
import pathUtils from './path-utils.js'

lib/update-internal-links.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import {
1313
getPathWithoutVersion,
1414
getVersionStringFromPath,
1515
} from './path-utils.js'
16-
import loadRedirects from './redirects/precompile.js'
16+
import loadRedirects from '#src/redirects/lib/precompile.js'
1717
import patterns from './patterns.js'
1818
import { loadUnversionedTree, loadPages, loadPageMap } from './page-data.js'
19-
import getRedirect, { splitPathByLanguage } from './get-redirect.js'
19+
import getRedirect, { splitPathByLanguage } from '#src/redirects/lib/get-redirect.js'
2020
import nonEnterpriseDefaultVersion from './non-enterprise-default-version.js'
2121
import { deprecated } from './enterprise-server-releases.js'
2222

lib/warm-server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import statsd from '#src/observability/lib/statsd.js'
22
import { loadUnversionedTree, loadSiteTree, loadPages, loadPageMap } from './page-data.js'
3-
import loadRedirects from './redirects/precompile.js'
3+
import loadRedirects from '#src/redirects/lib/precompile.js'
44

55
// Instrument these functions so that
66
// it's wrapped in a timer that reports to Datadog

middleware/archived-enterprise-versions.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import got from 'got'
1515
import { readCompressedJsonFileFallbackLazily } from '../lib/read-json-file.js'
1616
import { archivedCacheControl, languageCacheControl } from './cache-control.js'
1717
import { pathLanguagePrefixed, languagePrefixPathRegex } from '../lib/languages.js'
18-
import getRedirect, { splitPathByLanguage } from '../lib/get-redirect.js'
18+
import getRedirect, { splitPathByLanguage } from '../src/redirects/lib/get-redirect.js'
1919
import getRemoteJSON from './get-remote-json.js'
2020

2121
const REMOTE_ENTERPRISE_STORAGE_URL = 'https://githubdocs.azureedge.net/enterprise'
@@ -34,10 +34,10 @@ function splitByLanguage(uri) {
3434
// `readJsonFileLazily()` function will, at import-time, check that
3535
// the path does exist.
3636
const archivedRedirects = readCompressedJsonFileFallbackLazily(
37-
'./lib/redirects/static/archived-redirects-from-213-to-217.json',
37+
'./src/redirects/lib/static/archived-redirects-from-213-to-217.json',
3838
)
3939
const archivedFrontmatterValidURLS = readCompressedJsonFileFallbackLazily(
40-
'./lib/redirects/static/archived-frontmatter-valid-urls.json',
40+
'./src/redirects/lib/static/archived-frontmatter-valid-urls.json',
4141
)
4242

4343
// Combine all the things you need to make sure the response is

0 commit comments

Comments
 (0)