File tree Expand file tree Collapse file tree 3 files changed +41
-0
lines changed Expand file tree Collapse file tree 3 files changed +41
-0
lines changed Original file line number Diff line number Diff line change 18
18
/public /categories.json
19
19
/public /types-data.json
20
20
/public /tag-data.json
21
+ /public /aliases.json
21
22
22
23
# misc
23
24
.DS_Store
Original file line number Diff line number Diff line change @@ -46,6 +46,22 @@ function createTagCount(allTranscripts: ContentTranscriptType[]): { tagCounts: R
46
46
return { tagCounts } ;
47
47
}
48
48
49
+ const getTranscriptAliases = ( allTranscripts : ContentTranscriptType [ ] ) => {
50
+ const aliases : Record < string , string > = { } ;
51
+
52
+ for ( const transcript of allTranscripts ) {
53
+ if ( ! transcript . aliases ) continue ;
54
+
55
+ if ( transcript . aliases ) {
56
+ transcript . aliases . forEach ( ( alias ) => {
57
+ aliases [ alias ] = transcript . url ;
58
+ } ) ;
59
+ }
60
+ }
61
+
62
+ writeFileSync ( "./public/aliases.json" , JSON . stringify ( aliases ) ) ;
63
+ } ;
64
+
49
65
const getCategories = ( ) => {
50
66
const filePath = path . join ( process . cwd ( ) , "public" , "categories.json" ) ;
51
67
const fileContents = fs . readFileSync ( filePath , "utf8" ) ;
@@ -205,5 +221,6 @@ export default makeSource({
205
221
const { allDocuments } = await importData ( ) ;
206
222
organizeTags ( allDocuments ) ;
207
223
createTypesCount ( allDocuments ) ;
224
+ getTranscriptAliases ( allDocuments ) ;
208
225
} ,
209
226
} ) ;
Original file line number Diff line number Diff line change
1
+ import { NextResponse } from "next/server" ;
2
+ import type { NextRequest } from "next/server" ;
3
+ import aliasesJson from "../public/aliases.json" ;
4
+
5
+ const aliases = aliasesJson as { [ key : string ] : string } ;
6
+
7
+ export function middleware ( req : NextRequest ) {
8
+ const { pathname } = req . nextUrl ;
9
+ const alias = aliases [ pathname ] ;
10
+
11
+ if ( alias ) {
12
+ return NextResponse . redirect ( new URL ( alias , req . url ) ) ;
13
+ }
14
+ return NextResponse . next ( ) ;
15
+ }
16
+
17
+ export const config = {
18
+ matcher : [
19
+ "/:path/:subpath*" , // Matches any path with at least one subdirectory
20
+ "/:path*/:file((?!.*\\.).*)" , // Exclude paths with file extensions
21
+ "/((?!api|_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt|plugins).*)" , // Exclude specific Next.js paths and API routes
22
+ ] ,
23
+ } ;
You can’t perform that action at this time.
0 commit comments