|
| 1 | +// Redirect mappings from Next.js (tailor-web/apps/docs) to VitePress |
| 2 | +// Generated based on comparison of old and new structures |
| 3 | + |
| 4 | +export const redirectMap: Record<string, string> = { |
| 5 | + // ============================================ |
| 6 | + // tailor-sdk → sdk (MAIN MIGRATION PATTERN) |
| 7 | + // ============================================ |
| 8 | + "/tailor-sdk": "/sdk/", |
| 9 | + "/tailor-sdk/": "/sdk/", |
| 10 | + "/tailor-sdk/quickstart": "/sdk/quickstart", |
| 11 | + "/tailor-sdk/configuration": "/sdk/configuration", |
| 12 | + "/tailor-sdk/testing": "/sdk/testing", |
| 13 | + "/tailor-sdk/cli-reference": "/sdk/cli-reference", |
| 14 | + |
| 15 | + // CLI pages |
| 16 | + "/tailor-sdk/cli/application": "/sdk/cli/application", |
| 17 | + "/tailor-sdk/cli/auth": "/sdk/cli/auth", |
| 18 | + "/tailor-sdk/cli/completion": "/sdk/cli/completion", |
| 19 | + "/tailor-sdk/cli/executor": "/sdk/cli/executor", |
| 20 | + "/tailor-sdk/cli/function": "/sdk/cli/function", |
| 21 | + "/tailor-sdk/cli/secret": "/sdk/cli/secret", |
| 22 | + "/tailor-sdk/cli/staticwebsite": "/sdk/cli/staticwebsite", |
| 23 | + "/tailor-sdk/cli/tailordb": "/sdk/cli/tailordb", |
| 24 | + "/tailor-sdk/cli/user": "/sdk/cli/user", |
| 25 | + "/tailor-sdk/cli/workflow": "/sdk/cli/workflow", |
| 26 | + "/tailor-sdk/cli/workspace": "/sdk/cli/workspace", |
| 27 | + |
| 28 | + // Services |
| 29 | + "/tailor-sdk/services": "/sdk/services/", |
| 30 | + "/tailor-sdk/services/auth": "/sdk/services/auth", |
| 31 | + "/tailor-sdk/services/executor": "/sdk/services/executor", |
| 32 | + "/tailor-sdk/services/idp": "/sdk/services/idp", |
| 33 | + "/tailor-sdk/services/resolver": "/sdk/services/resolver", |
| 34 | + "/tailor-sdk/services/secret": "/sdk/services/secret", |
| 35 | + "/tailor-sdk/services/staticwebsite": "/sdk/services/staticwebsite", |
| 36 | + "/tailor-sdk/services/tailordb": "/sdk/services/tailordb", |
| 37 | + "/tailor-sdk/services/workflow": "/sdk/services/workflow", |
| 38 | + |
| 39 | + // Generator |
| 40 | + "/tailor-sdk/generator": "/sdk/generator/", |
| 41 | + "/tailor-sdk/generator/builtin": "/sdk/generator/builtin", |
| 42 | + "/tailor-sdk/generator/custom": "/sdk/generator/custom", |
| 43 | + "/tailor-sdk/generator/index-file": "/sdk/generator/index", |
| 44 | + |
| 45 | + // Plugin |
| 46 | + "/tailor-sdk/plugin": "/sdk/plugin/", |
| 47 | + "/tailor-sdk/plugin/custom": "/sdk/plugin/custom", |
| 48 | + "/tailor-sdk/plugin/index-file": "/sdk/plugin/index", |
| 49 | + |
| 50 | + // ============================================ |
| 51 | + // tailorctl → DEPRECATED (redirect to SDK) |
| 52 | + // ============================================ |
| 53 | + "/tailorctl": "/sdk/", |
| 54 | + "/tailorctl/": "/sdk/", |
| 55 | + "/tailorctl/auth": "/sdk/cli/auth", |
| 56 | + "/tailorctl/auth/login": "/sdk/cli/auth", |
| 57 | + "/tailorctl/auth/logout": "/sdk/cli/auth", |
| 58 | + "/tailorctl/auth/get": "/sdk/cli/auth", |
| 59 | + "/tailorctl/auth/machineuser": "/sdk/cli/auth", |
| 60 | + "/tailorctl/auth/machineuser_get": "/sdk/cli/auth", |
| 61 | + "/tailorctl/auth/machineuser_list": "/sdk/cli/auth", |
| 62 | + "/tailorctl/auth/pat": "/sdk/cli/auth", |
| 63 | + "/tailorctl/auth/pat_create": "/sdk/cli/auth", |
| 64 | + "/tailorctl/auth/pat_delete": "/sdk/cli/auth", |
| 65 | + "/tailorctl/auth/pat_list": "/sdk/cli/auth", |
| 66 | + "/tailorctl/config": "/sdk/configuration", |
| 67 | + "/tailorctl/config/delete": "/sdk/configuration", |
| 68 | + "/tailorctl/config/describe": "/sdk/configuration", |
| 69 | + "/tailorctl/config/list": "/sdk/configuration", |
| 70 | + "/tailorctl/config/set": "/sdk/configuration", |
| 71 | + "/tailorctl/config/switch": "/sdk/configuration", |
| 72 | + "/tailorctl/workspace": "/sdk/cli/workspace", |
| 73 | + "/tailorctl/workspace/create": "/sdk/cli/workspace", |
| 74 | + "/tailorctl/workspace/list": "/sdk/cli/workspace", |
| 75 | + "/tailorctl/workspace/machineuser_list": "/sdk/cli/workspace", |
| 76 | + |
| 77 | + // ============================================ |
| 78 | + // Getting Started (minor changes) |
| 79 | + // ============================================ |
| 80 | + "/getting-started/quickstart/cue": "/getting-started/quickstart", |
| 81 | + "/getting-started/quickstart/terraform": "/getting-started/quickstart", |
| 82 | + "/getting-started/cue": "/getting-started/", |
| 83 | + "/getting-started/overview": "/getting-started/", |
| 84 | + |
| 85 | + // ============================================ |
| 86 | + // Tutorials base-template → develop-from-scratch |
| 87 | + // ============================================ |
| 88 | + "/tutorials/base-template": "/tutorials/develop-from-scratch/", |
| 89 | + "/tutorials/base-template/cue": "/tutorials/develop-from-scratch/", |
| 90 | + "/tutorials/base-template/sdk": "/tutorials/develop-from-scratch/", |
| 91 | + "/tutorials/base-template/terraform": "/tutorials/develop-from-scratch/", |
| 92 | + |
| 93 | + // ============================================ |
| 94 | + // Root pages that moved to /reference |
| 95 | + // ============================================ |
| 96 | + "/security": "/reference/security", |
| 97 | + |
| 98 | + // ============================================ |
| 99 | + // Common variations with /docs prefix |
| 100 | + // ============================================ |
| 101 | + "/docs/tailor-sdk": "/sdk/", |
| 102 | + "/docs/tailor-sdk/": "/sdk/", |
| 103 | + "/docs/getting-started": "/getting-started/", |
| 104 | + "/docs/guides": "/guides/", |
| 105 | + "/docs/tutorials": "/tutorials/", |
| 106 | + "/docs/reference": "/reference/", |
| 107 | + "/docs/sdk": "/sdk/", |
| 108 | + "/docs/administration": "/administration/", |
| 109 | + "/docs/security": "/reference/security", |
| 110 | + |
| 111 | + // ============================================ |
| 112 | + // Index pages → overview pages |
| 113 | + // ============================================ |
| 114 | + "/guides/auth/index": "/guides/auth/overview", |
| 115 | + "/guides/executor/index": "/guides/executor/overview", |
| 116 | + "/guides/function/index": "/guides/function/overview", |
| 117 | + "/guides/tailordb/index": "/guides/tailordb/overview", |
| 118 | + "/guides/workflow/index": "/guides/workflow/overview", |
| 119 | + "/guides/integration/index": "/guides/integration/overview", |
| 120 | +}; |
| 121 | + |
| 122 | +// Fuzzy match redirects - tries to find similar pages |
| 123 | +export function findBestMatch(path: string): string | null { |
| 124 | + // Remove trailing slashes and normalize |
| 125 | + const normalizedPath = path.replace(/\/$/, "").toLowerCase(); |
| 126 | + |
| 127 | + // Direct match |
| 128 | + if (redirectMap[normalizedPath]) { |
| 129 | + return redirectMap[normalizedPath]; |
| 130 | + } |
| 131 | + |
| 132 | + // Try with /docs prefix removed (common Next.js → VitePress migration) |
| 133 | + if (normalizedPath.startsWith("/docs/")) { |
| 134 | + const withoutDocs = normalizedPath.replace("/docs/", "/"); |
| 135 | + if (redirectMap[withoutDocs]) { |
| 136 | + return redirectMap[withoutDocs]; |
| 137 | + } |
| 138 | + // If no redirect map, try the path without /docs directly |
| 139 | + return withoutDocs; |
| 140 | + } |
| 141 | + |
| 142 | + // Try tailor-sdk → sdk conversion |
| 143 | + if (normalizedPath.includes("/tailor-sdk/")) { |
| 144 | + const converted = normalizedPath.replace("/tailor-sdk/", "/sdk/"); |
| 145 | + // Check if this new path might exist |
| 146 | + return converted; |
| 147 | + } |
| 148 | + |
| 149 | + // Try fuzzy matching based on path segments |
| 150 | + const segments = normalizedPath.split("/").filter(Boolean); |
| 151 | + const lastSegment = segments[segments.length - 1]; |
| 152 | + |
| 153 | + // Look for pages with the same last segment in redirect map |
| 154 | + for (const [oldPath, newPath] of Object.entries(redirectMap)) { |
| 155 | + if (oldPath.endsWith("/" + lastSegment) && newPath) { |
| 156 | + return newPath; |
| 157 | + } |
| 158 | + } |
| 159 | + |
| 160 | + // No match found |
| 161 | + return null; |
| 162 | +} |
| 163 | + |
| 164 | +// Check if a path should redirect |
| 165 | +export function shouldRedirect(path: string): string | null { |
| 166 | + const match = findBestMatch(path); |
| 167 | + if (match && match !== path) { |
| 168 | + return match; |
| 169 | + } |
| 170 | + return null; |
| 171 | +} |
0 commit comments