Skip to content

Commit 86e5206

Browse files
Fix href tests
1 parent 432f431 commit 86e5206

File tree

3 files changed

+47
-6
lines changed

3 files changed

+47
-6
lines changed

package-lock.json

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"@mdx-js/react": "^2.3.0",
6868
"autoprefixer": "^10.4.14",
6969
"cssnano": "^6.0.1",
70+
"dotenv": "^16.4.7",
7071
"esbuild-loader": "^2.20.0",
7172
"postcss": "^8.4.27",
7273
"postcss-cli": "^8.3.0",

scripts/test-hrefs.mjs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,19 @@
99
import unified from "unified";
1010
import markdown from "remark-parse";
1111
import stringify from "remark-stringify";
12+
import {config} from "dotenv"
1213
import glob from "glob";
1314
import path from "path";
1415
import fs from "fs";
1516
import urlModule from "url";
1617
import { URL } from 'url';
1718
import {getAllPosts, blogPathToSlug} from '../src/common/BlogApi.mjs'
1819

20+
config()
21+
22+
let latestVersion = process.env.VERSION_LATEST
23+
let nextVersion = process.env.VERSION_NEXT
24+
1925
const pathname = new URL('.', import.meta.url).pathname;
2026
const __dirname = process.platform !== 'win32' ? pathname : pathname.substring(1)
2127

@@ -120,18 +126,27 @@ const createApiIndexModules = version => {
120126

121127
return acc.concat(paths);
122128
}, []);
123-
return ["latest/api", ...paths];
129+
return [`${version}/api`, ...paths];
124130
};
125131

126-
const apiIndexModules = createApiIndexModules("latest")
132+
const apiIndexModules = [...createApiIndexModules(latestVersion), ...createApiIndexModules(nextVersion)]
127133

128134
const testFile = (pageMap, test) => {
129135
const filepath = test.filepath;
130-
136+
131137
// Used for storing failed / ok hrefs
132138
const results = [];
133139

134140
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+
135150
const parsed = urlModule.parse(link.url);
136151

137152
// Drops .md / .mdx / .html file extension in pathname section, since UI ignores them
@@ -177,7 +192,12 @@ const testFile = (pageMap, test) => {
177192
}
178193
}
179194

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+
) {
181201
const pathToModule = resolved.replace("/pages/docs/manual/", "");
182202
const pathExists = apiIndexModules.includes(pathToModule);
183203

@@ -259,9 +279,9 @@ const main = () => {
259279
const allFiles = pageMapFiles.concat(staticFiles);
260280

261281
const pageMap = createPageIndex(allFiles);
262-
282+
263283
const processedFiles = files.map(processFile);
264-
284+
265285
const allTested = processedFiles.map(file => testFile(pageMap, file));
266286

267287
const failed = allTested.reduce((acc, test) => {

0 commit comments

Comments
 (0)