|
9 | 9 | import unified from "unified";
|
10 | 10 | import markdown from "remark-parse";
|
11 | 11 | import stringify from "remark-stringify";
|
| 12 | +import {config} from "dotenv" |
12 | 13 | import glob from "glob";
|
13 | 14 | import path from "path";
|
14 | 15 | import fs from "fs";
|
15 | 16 | import urlModule from "url";
|
16 | 17 | import { URL } from 'url';
|
17 | 18 | import {getAllPosts, blogPathToSlug} from '../src/common/BlogApi.mjs'
|
18 | 19 |
|
| 20 | +config() |
| 21 | + |
| 22 | +let latestVersion = process.env.VERSION_LATEST |
| 23 | +let nextVersion = process.env.VERSION_NEXT |
| 24 | + |
19 | 25 | const pathname = new URL('.', import.meta.url).pathname;
|
20 | 26 | const __dirname = process.platform !== 'win32' ? pathname : pathname.substring(1)
|
21 | 27 |
|
@@ -120,18 +126,27 @@ const createApiIndexModules = version => {
|
120 | 126 |
|
121 | 127 | return acc.concat(paths);
|
122 | 128 | }, []);
|
123 |
| - return ["latest/api", ...paths]; |
| 129 | + return [`${version}/api`, ...paths]; |
124 | 130 | };
|
125 | 131 |
|
126 |
| -const apiIndexModules = createApiIndexModules("latest") |
| 132 | +const apiIndexModules = [...createApiIndexModules(latestVersion), ...createApiIndexModules(nextVersion)] |
127 | 133 |
|
128 | 134 | const testFile = (pageMap, test) => {
|
129 | 135 | const filepath = test.filepath;
|
130 |
| - |
| 136 | + |
131 | 137 | // Used for storing failed / ok hrefs
|
132 | 138 | const results = [];
|
133 | 139 |
|
134 | 140 | test.links.forEach(link => {
|
| 141 | + // Simulate the redirect of "latest" and "next" version aliases. |
| 142 | + if (link.url.includes("/manual/latest/")) { |
| 143 | + link.url = link.url.replace("/latest/", `/${latestVersion}/`); |
| 144 | + } |
| 145 | + |
| 146 | + if (link.url.includes("/manual/next/")) { |
| 147 | + link.url = link.url.replace("/next/", `/${nextVersion}/`); |
| 148 | + } |
| 149 | + |
135 | 150 | const parsed = urlModule.parse(link.url);
|
136 | 151 |
|
137 | 152 | // Drops .md / .mdx / .html file extension in pathname section, since UI ignores them
|
@@ -177,7 +192,12 @@ const testFile = (pageMap, test) => {
|
177 | 192 | }
|
178 | 193 | }
|
179 | 194 |
|
180 |
| - if (resolved.startsWith("/pages/docs/manual/latest/api")) { |
| 195 | + |
| 196 | + |
| 197 | + if ( |
| 198 | + resolved.startsWith(`/pages/docs/manual/${latestVersion}/api`) || |
| 199 | + resolved.startsWith(`/pages/docs/manual/${nextVersion}/api`) |
| 200 | + ) { |
181 | 201 | const pathToModule = resolved.replace("/pages/docs/manual/", "");
|
182 | 202 | const pathExists = apiIndexModules.includes(pathToModule);
|
183 | 203 |
|
@@ -259,9 +279,9 @@ const main = () => {
|
259 | 279 | const allFiles = pageMapFiles.concat(staticFiles);
|
260 | 280 |
|
261 | 281 | const pageMap = createPageIndex(allFiles);
|
262 |
| - |
| 282 | + |
263 | 283 | const processedFiles = files.map(processFile);
|
264 |
| - |
| 284 | + |
265 | 285 | const allTested = processedFiles.map(file => testFile(pageMap, file));
|
266 | 286 |
|
267 | 287 | const failed = allTested.reduce((acc, test) => {
|
|
0 commit comments