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 ( / \. ( m d | m d x ) $ / , '' ) ;
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 ) ;
0 commit comments