MCPcopy Index your code
hub / github.com/github/docs / getNewVersionedPath

Function getNewVersionedPath

lib/old-versions-utils.js:49–72  ·  view source on GitHub ↗
(oldPath, languageCode = '')

Source from the content-addressed store, hash-verified

47// Given an old path like /en/enterprise/2.21/user/github/category/article,
48// return a new path like /en/enterprise-server@2.21/github/category/article.
49export function getNewVersionedPath(oldPath, languageCode = '') {
50 // It's possible a new version has been injected into an old path
51 // via syntax like: /en/enterprise/{{ currentVersion }}/admin/category/article
52 // which could resolve to /en/enterprise/private-instances@latest/admin/category/article,
53 // in which case the new version is the `private-instances@latest` segment.
54 // Get the second or third segment depending on whether there is a lang code.
55 const pathParts = oldPath.split('/')
56 const possibleVersion = languageCode ? pathParts[3] : pathParts[2]
57 let newVersion = newVersions.includes(possibleVersion) ? possibleVersion : ''
58
59 // If no new version was found, assume path contains an old version, like 2.21
60 if (!newVersion) {
61 const oldVersion = getOldVersionFromOldPath(oldPath, languageCode)
62 newVersion = getNewVersionFromOldVersion(oldVersion)
63 }
64
65 // Remove /<lang>?/enterprise?/<version>?/user? if present.
66 // This leaves only the part of the string that starts with the product.
67 // Example: /github/category/article
68 const restOfString = oldPath.replace(patterns.oldEnterprisePath, '')
69
70 // Add the language and new version to the product part of the string
71 return path.posix.join('/', languageCode, newVersion, restOfString)
72}
73
74export default {
75 oldVersions,

Callers 1

getNewHrefFunction · 0.90

Calls 2

getOldVersionFromOldPathFunction · 0.85

Tested by

no test coverage detected