@@ -36,28 +36,59 @@ export default {
36
36
async fetch ( request : Request ) : Promise < Response > {
37
37
const url = new URL ( request . url ) ;
38
38
const path = url . pathname ;
39
-
40
- // Check if this is a repository path
39
+ // Split the pathname by '/' and remove empty items (leading slash, etc.)
41
40
const pathParts = path . split ( '/' ) . filter ( Boolean ) ;
42
41
42
+ // -------------------------------------------------------------------
43
+ // 1) Handle single-segment paths that correspond to "go-get" repos.
44
+ //
45
+ // That is, if someone does: `go get code.vikunja.io/vikunja`
46
+ // or `go get code.vikunja.io/goget`, we serve the meta tags
47
+ // so that "go get" knows which Git repo to use.
48
+ // -------------------------------------------------------------------
43
49
if ( pathParts . length === 1 ) {
44
50
const repo = pathParts [ 0 ] ;
45
51
46
52
// Check if this is one of our special repositories
47
53
if ( [ 'goget' , 'web' , 'vikunja' ] . includes ( repo ) ) {
48
- return showGoGetMeta ( path ) ;
54
+ return showGoGetMeta ( `/ ${ repo } ` ) ;
49
55
}
50
56
}
51
57
52
- if ( path === '/desktop' || path === '/desktop/' ) {
53
- return redirectToBase ( '/vikunja/tree/main/desktop' ) ;
58
+ // -------------------------------------------------------------------
59
+ // 2) Handle /desktop and all its subpaths.
60
+ //
61
+ // Examples:
62
+ // - /desktop => https://github.com/go-vikunja/vikunja/tree/main/desktop
63
+ // - /desktop/main.js => https://github.com/go-vikunja/vikunja/tree/main/desktop/main.js
64
+ // -------------------------------------------------------------------
65
+ if ( pathParts [ 0 ] === 'desktop' ) {
66
+ const subPath = pathParts . slice ( 1 ) . join ( '/' ) ;
67
+ // If subPath is not empty, prepend '/'
68
+ const maybeSlash = subPath ? `/${ subPath } ` : '' ;
69
+ return redirectToBase ( `/vikunja/tree/main/desktop${ maybeSlash } ` ) ;
54
70
}
55
71
56
- if ( path === '/frontend' || path === '/frontend/' ) {
57
- return redirectToBase ( '/vikunja/tree/main/frontend' ) ;
72
+ // -------------------------------------------------------------------
73
+ // 3) Handle /frontend and all its subpaths.
74
+ //
75
+ // Examples:
76
+ // - /frontend => https://github.com/go-vikunja/vikunja/tree/main/frontend
77
+ // - /frontend/lang/i18n => https://github.com/go-vikunja/vikunja/tree/main/frontend/lang/i18n
78
+ // -------------------------------------------------------------------
79
+ if ( pathParts [ 0 ] === 'frontend' ) {
80
+ const subPath = pathParts . slice ( 1 ) . join ( '/' ) ;
81
+ const maybeSlash = subPath ? `/${ subPath } ` : '' ;
82
+ return redirectToBase ( `/vikunja/tree/main/frontend${ maybeSlash } ` ) ;
58
83
}
59
84
60
- // Default: redirect to base URL
85
+ // -------------------------------------------------------------------
86
+ // 4) Default fallback:
87
+ // If nothing above applies, just redirect to the base URL
88
+ // with the entire path appended. This ensures that any other
89
+ // repos or subpaths which don't need special handling
90
+ // still redirect to the correct GitHub path.
91
+ // -------------------------------------------------------------------
61
92
return redirectToBase ( path ) ;
62
93
} ,
63
94
} satisfies ExportedHandler ;
0 commit comments