Skip to content

Commit a5e7d82

Browse files
committed
[FLUSS-2062] Support redirect for latest stable document version
1 parent 8635169 commit a5e7d82

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

website/docusaurus.config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ const config: Config = {
121121
],
122122
},
123123
],
124+
[
125+
'@docusaurus/plugin-client-redirects',
126+
{
127+
redirects: require('./generate-redirects.cjs'), // 可留空
128+
},
129+
],
124130
],
125131
themeConfig: {
126132
image: 'img/logo/png/colored_logo.png',

website/generate-redirects.cjs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import { loadVersionData } from './src/utils/versionData';
19+
20+
const fs = require('fs');
21+
const path = require('path');
22+
23+
const { latestVersion } = loadVersionData();
24+
25+
const redirects = [];
26+
27+
console.log('DEBUG: latestVersion =', latestVersion);
28+
29+
if (latestVersion && latestVersion !== 'current') {
30+
const docsDir = path.join(__dirname, 'versioned_docs', `version-${latestVersion}`);
31+
console.log('DEBUG: docsDir =', docsDir);
32+
33+
if (fs.existsSync(docsDir)) {
34+
function walk(dir) {
35+
const files = fs.readdirSync(dir);
36+
for (const file of files) {
37+
const fullPath = path.join(dir, file);
38+
const stat = fs.statSync(fullPath);
39+
if (stat.isDirectory()) {
40+
walk(fullPath);
41+
} else if ((file.endsWith('.md') || file.endsWith('.mdx'))&& !file.endsWith("index.md")) {
42+
const relPath = path.relative(docsDir, fullPath).replace(/\.(md|mdx)$/, '');
43+
console.log('DEBUG: relPath =', docsDir);
44+
redirects.push({
45+
from: `/docs/${latestVersion}/${relPath}`,
46+
to: `/docs/${relPath}`,
47+
});
48+
}
49+
}
50+
}
51+
walk(docsDir);
52+
}
53+
}
54+
55+
module.exports = redirects;
56+
console.log('Generated redirects:', redirects);

website/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
},
3030
"devDependencies": {
3131
"@docusaurus/module-type-aliases": "^3.8.0",
32+
"@docusaurus/plugin-client-redirects": "^3.9.2",
3233
"@docusaurus/tsconfig": "^3.8.0",
3334
"@docusaurus/types": "^3.8.0",
3435
"typescript": "~5.5.2"

0 commit comments

Comments
 (0)