1
0
mirror of synced 2025-12-30 12:02:01 -05:00
Files
docs/lib/redirects
Robert Sese 79c48070c4 Deprecate 3.0 (#25646)
* Deprecate 3.0

* 3.0 deprecation: remove 3.0 markup (#25647)

* Remove liquid conditionals and content for 3.0 deprecation

* Remove manually, no longer versioned in a supported version

* Remove translations manually, no longer versioned in a supported version

* Remove 'if', now in all supported versions

* Remove dangling 'elseif', now in all supported versions

* Remove dangling 'elseif' and 3.0 screenshot reference, now in all supported versions

* Nudge to latest supported GHES version

* Nudge to latest supported release GHES version

* Bump all the version for the liquid tests

* Bump first deprecated version for linting tests

* Prefer double quotes

Co-authored-by: Laura Coursen <lecoursen@github.com>

* Prefer double quotes

Co-authored-by: Laura Coursen <lecoursen@github.com>

* Prefer double quotes

Co-authored-by: Laura Coursen <lecoursen@github.com>

* Prefer double quotes

Co-authored-by: Laura Coursen <lecoursen@github.com>

* Prefer double quotes

Co-authored-by: Laura Coursen <lecoursen@github.com>

* Prefer double quotes

Co-authored-by: Laura Coursen <lecoursen@github.com>

* Prefer double quotes

Co-authored-by: Laura Coursen <lecoursen@github.com>

* Prefer double quotes

Co-authored-by: Laura Coursen <lecoursen@github.com>

* Prefer double quotes

Co-authored-by: Laura Coursen <lecoursen@github.com>

* Remove extra newline

Co-authored-by: Laura Coursen <lecoursen@github.com>

* Remove extra newline

Co-authored-by: Laura Coursen <lecoursen@github.com>

* Remove extra newline

Co-authored-by: Laura Coursen <lecoursen@github.com>

* One reusable per line

Co-authored-by: Laura Coursen <lecoursen@github.com>

* One reusable per line

Co-authored-by: Laura Coursen <lecoursen@github.com>

* One reusable per line

Co-authored-by: Laura Coursen <lecoursen@github.com>

* Version check not needed anymore

Co-authored-by: Laura Coursen <lecoursen@github.com>

* Version check not needed anymore

Co-authored-by: Laura Coursen <lecoursen@github.com>

* Version check not needed anymore

Co-authored-by: Laura Coursen <lecoursen@github.com>

* Version check not needed anymore

Co-authored-by: Laura Coursen <lecoursen@github.com>

* Version check not needed anymore

Co-authored-by: Laura Coursen <lecoursen@github.com>

* Version check not needed anymore

Co-authored-by: Laura Coursen <lecoursen@github.com>

* Version check not needed anymore

Co-authored-by: Laura Coursen <lecoursen@github.com>

* Stray whitespace ✂️

Co-authored-by: Laura Coursen <lecoursen@github.com>

* Stray whitespace ✂️

Co-authored-by: Laura Coursen <lecoursen@github.com>

* Stray whitespace ✂️

Co-authored-by: Laura Coursen <lecoursen@github.com>

* Stray whitespace ✂️

Co-authored-by: Laura Coursen <lecoursen@github.com>

* Stray whitespace ✂️

Co-authored-by: Laura Coursen <lecoursen@github.com>

* Stray whitespace ✂️

Co-authored-by: Laura Coursen <lecoursen@github.com>

* Stray whitespace ✂️

Co-authored-by: Laura Coursen <lecoursen@github.com>

* Stray whitespace ✂️

Co-authored-by: Laura Coursen <lecoursen@github.com>

* Version check not needed anymore

Co-authored-by: Laura Coursen <lecoursen@github.com>

* Version check not needed anymore

Co-authored-by: Laura Coursen <lecoursen@github.com>

* Just 'ghes' since we're deprecating 3.0

Co-authored-by: Laura Coursen <lecoursen@github.com>

* Just 'ghes' since we're deprecating 3.0

Co-authored-by: Laura Coursen <lecoursen@github.com>

* Just 'ghes' since we're deprecating 3.0

Co-authored-by: Laura Coursen <lecoursen@github.com>

* Just 'ghes' since we're deprecating 3.0

Co-authored-by: Laura Coursen <lecoursen@github.com>

* Just 'ghes' since we're deprecating 3.0

Co-authored-by: Laura Coursen <lecoursen@github.com>

* Just 'ghes' since we're deprecating 3.0

Co-authored-by: Laura Coursen <lecoursen@github.com>

* Just 'ghes' since we're deprecating 3.0

Co-authored-by: Laura Coursen <lecoursen@github.com>

* Just 'ghes' since we're deprecating 3.0

Co-authored-by: Laura Coursen <lecoursen@github.com>

* Don't depend on hardcoded versions

Co-authored-by: Laura Coursen <lecoursen@github.com>

* Remove static files for 3.0 deprecation (#25649)

Co-authored-by: Laura Coursen <lecoursen@github.com>
2022-03-03 13:08:24 -06:00
..
2022-03-03 13:08:24 -06:00
2021-10-15 15:41:33 -05:00

Redirects

Docs redirects are complex! Some reasons why:

  • Docs URLs have changed many times over the years, whether because docs team members have renamed individual articles or made global changes (e.g., moving all /articles to /github).
  • Redirects can be hardcoded in frontmatter or generated via code in this directory (or both!).
  • Live docs and archived docs require different redirect handling because they may have differently formatted URLs (e.g., legacy /enterprise/2.17 vs. modern /enterprise-server@2.22).

Read on for more about how redirects work under the hood.

Precompiled redirects

Precompiled redirects account for the majority of the docs site's redirect handling.

When lib/warm-server.js runs on server start, it creates all pages in the site by instantiating the Page class for each content file, then passes the pages to lib/redirects/precompile.js to create redirects. The precompile script runs lib/redirects/permalinks.js, which:

  1. Includes all legacy redirects from static/developerjson
  2. Loops over each page's frontmatter redirect_from entries and creates an array of legacy paths for each one (using the same handling as for permalinks).
  3. Any other exceptions from the static/redirect-exceptions.txt file

The results comprise the page.redirects object, whose keys are always only the path without language. Sometimes it contains the specific plan/version (e.g. /enterprise-server@3.0/v3/integrations to enterprise-server@3.0/developers/apps) and sometimes it's just the plain path (e.g. /articles/viewing-your-repositorys-workflows to /actions/monitoring-and-troubleshooting-workflows)

All of the above are merged into a global redirects object. This object gets added to req.context via middleware/context.js and is made accessible on every request.

In the handle-redirects.js middleware, the language part of the URL is removed, looked up, and if matched to something, redirects with language put back in. Demonstrated with pseudo code:

var fullPath = '/ja/foo'
var newPath = redirects['/foo']
if (newPath) {
  redirect('/ja' + newPath)
}

Archived Enterprise redirects

Archived Enterprise redirects account for a much smaller percentage of redirects on the docs site.

Some background on archival: a snapshot of the HTML files for each deprecated Enterprise Server version is archived in a separate repo and proxied to docs.github.com via middleware/archived-enterprise-versions.js.

Starting with Enterprise Server 2.18, we updated the archival process to start preserving frontmatter and permalink redirects. But these redirects for 2.13 to 2.17 are not recoverable.

As a workaround for these lost redirects, we have two files in lib/redirects/static:

  • archived-redirects-from-213-to-217.json

    This file contains keys equal to old routes and values equal to new routes (aka snapshots of permalinks at the time) for versions 2.13 to 2.17. (The old routes were generated via lib/redirects/get-old-paths-from-permalink.js.)

  • archived-frontmatter-fallbacks.json

    This file contains an array of arrays, where the child arrays are a group of all frontmatter redirects for each content file. This is essentially list of all the historical paths for the articles in old versions. The problem is, we don't know which historical paths correspond to which versions.

Here's how the middleware/archived-enterprise-versions.js fallback works: if someone tries to access an article that was updated via a now-lost frontmatter redirect (for example, an article at the path /en/enterprise/2.15/user/articles/viewing-contributions-on-your-profile-page), the middleware will first look for a redirect in archived-redirects-from-213-to-217.json. If it does not find one, it will look for a child array in archived-frontmatter-fallbacks.json that contains the requested path. If it finds a relevant array, it will try accessing all the other paths in the array until it finds one that returns a 200. For this example, it would successfully reach /en/enterprise/2.15/user/articles/viewing-contributions-on-your-profile (no -page).

This is admittedly an inefficient brute-force approach. But requests for archived docs <2.18 are getting less and less common as organizations upgrade their Enterprise instances, and all the expensive calculation happens in the middleware on page request, not on server warmup, so at least it's a relatively isolated process.

Tests

Redirect tests are mainly found in tests/routing/*, with some additional tests in tests/rendering/server.js.

The tests/fixtures/* directory includes developer-redirects.json, graphql-redirects.json, and rest-redirects.json.