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

Function addRestClientSideRedirects

src/rest/scripts/utils/decorator.js:254–296  ·  view source on GitHub ↗
(operations, clientSideRedirects)

Source from the content-addressed store, hash-verified

252}
253
254async function addRestClientSideRedirects(operations, clientSideRedirects) {
255 // For each rest operation that doesn't have an override defined
256 // in src/rest/scripts/utils/rest-api-overrides.json,
257 // add a client-side redirect
258 operations.forEach((operation) => {
259 // A handful of operations don't have external docs properties
260 const externalDocs = operation.getExternalDocs()
261 if (!externalDocs) {
262 return
263 }
264 const oldUrl = `/rest${externalDocs.url.replace('/rest/reference', '/rest').split('/rest')[1]}`
265
266 if (!(oldUrl in clientSideRedirects)) {
267 // There are some operations that aren't nested in the sidebar
268 // For these, don't need to add a client-side redirect, the
269 // frontmatter redirect will handle it for us.
270 if (categoriesWithoutSubcategories.includes(operation.category)) {
271 return
272 }
273 const anchor = oldUrl.split('#')[1]
274 const subcategory = operation.subcategory
275
276 // If there is no subcategory, a new page with the same name as the
277 // category was created. That page name may change going forward.
278 const redirectTo = subcategory
279 ? `/rest/${operation.category}/${subcategory}#${anchor}`
280 : `/rest/${operation.category}/${operation.category}#${anchor}`
281 clientSideRedirects[oldUrl] = redirectTo
282 }
283
284 // There are a lot of section headings that we'll want to redirect too,
285 // now that subcategories are on their own page. For example,
286 // /rest/reference/actions#artifacts should redirect to
287 // /rest/actions/artifacts
288 if (operation.subcategory) {
289 const sectionRedirectFrom = `/rest/${operation.category}#${operation.subcategory}`
290 const sectionRedirectTo = `/rest/${operation.category}/${operation.subcategory}`
291 if (!(sectionRedirectFrom in clientSideRedirects)) {
292 clientSideRedirects[sectionRedirectFrom] = sectionRedirectTo
293 }
294 }
295 })
296}
297
298export async function getOpenApiSchemaFiles(schemas) {
299 const webhookSchemas = []

Callers 1

createStaticRestFilesFunction · 0.85

Calls 1

getExternalDocsMethod · 0.80

Tested by

no test coverage detected