@@ -22,6 +22,10 @@ export declare namespace Node {
22
22
root : FernNavigation . RootNode ;
23
23
products : readonly FernNavigation . ProductNode [ ] ;
24
24
currentProduct : FernNavigation . ProductNode | undefined ;
25
+ /**
26
+ * This is true if the current product is the default product node (without the product slug prefix)
27
+ */
28
+ isCurrentProductDefault : boolean ;
25
29
versions : readonly FernNavigation . VersionNode [ ] ;
26
30
currentVersion : FernNavigation . VersionNode | undefined ;
27
31
/**
@@ -69,39 +73,49 @@ export function findNode(
69
73
70
74
// if the slug points to a node that doesn't exist, we should redirect to the first likely node
71
75
if ( found == null ) {
72
- let maybeVersionNode : FernNavigation . RootNode | FernNavigation . VersionNode =
73
- root ;
74
-
75
- // the 404 behavior should be version-aware
76
- for ( const versionNode of collector . getVersionNodes ( ) ) {
77
- if ( slug . startsWith ( versionNode . slug ) ) {
78
- maybeVersionNode = versionNode ;
76
+ let maybeProductOrVersionNode :
77
+ | FernNavigation . RootNode
78
+ | FernNavigation . ProductNode
79
+ | FernNavigation . VersionNode = root ;
80
+ let foundProductNode = false ;
81
+
82
+ // the 404 behavior should be product-aware
83
+ for ( const productNode of collector . getProductNodes ( ) ) {
84
+ if ( slug . startsWith ( productNode . slug ) ) {
85
+ maybeProductOrVersionNode = productNode ;
86
+ foundProductNode = true ;
79
87
break ;
80
88
}
81
89
}
82
90
91
+ // if we didn't find a product node, try to find a version node
92
+ if ( ! foundProductNode ) {
93
+ // the 404 behavior should be version-aware
94
+ for ( const versionNode of collector . getVersionNodes ( ) ) {
95
+ if ( slug . startsWith ( versionNode . slug ) ) {
96
+ maybeProductOrVersionNode = versionNode ;
97
+ break ;
98
+ }
99
+ }
100
+ }
101
+
83
102
return {
84
103
type : "notFound" ,
85
- redirect : maybeVersionNode . pointsTo ,
86
- authed : maybeVersionNode . authed ,
104
+ redirect : maybeProductOrVersionNode . pointsTo ,
105
+ authed : maybeProductOrVersionNode . authed ,
87
106
} ;
88
107
}
89
108
90
109
const sidebar = found . parents . find ( isSidebarRootNode ) ;
91
110
const currentProductGroup = found . parents . find ( isProductGroupNode ) ;
92
- // TODO: remove console.log
93
- console . log ( "currentProduct" , currentProductGroup ) ;
94
- const productChildren = currentProductGroup ?. children ;
111
+ const currentProduct = found . parents . find ( isProductNode ) ;
112
+
95
113
const currentVersion = found . parents . find ( isVersionNode ) ;
96
114
const unversionedNode = found . parents . find ( isUnversionedNode ) ;
97
115
const versionChild = ( currentVersion ?? unversionedNode ) ?. child ;
98
116
const landingPage = ( currentProductGroup ?? currentVersion ?? unversionedNode )
99
117
?. landingPage ;
100
118
101
- const currentProduct = productChildren ?. find ( isProductNode ) ;
102
- // TODO: remove console.log
103
- console . log ( "currentProduct" , currentProduct ) ;
104
-
105
119
const tabbedNode =
106
120
found . parents . find ( isTabbedNode ) ??
107
121
// fallback to the version child because the current node may be a landing page
@@ -121,13 +135,14 @@ export function findNode(
121
135
) ;
122
136
const currentTabNode =
123
137
tabbedNodeIndex !== - 1 ? parentsAndNode [ tabbedNodeIndex + 1 ] : undefined ;
138
+
124
139
const products = collector . getProductNodes ( ) . map ( ( node ) => {
125
140
if ( node . default ) {
126
- // if we're currently viewing the default version , we may be viewing the non-pruned version
141
+ // if we're currently viewing the default product , we may be viewing the non-pruned product node
127
142
if ( node . id === currentProduct ?. id ) {
128
143
return currentProduct ;
129
144
}
130
- // otherwise, we should always use the pruned version node
145
+ // otherwise, we should always use the pruned product node
131
146
return collector . defaultProductNode ?? node ;
132
147
}
133
148
return node ;
@@ -164,6 +179,9 @@ export function findNode(
164
179
currentProduct,
165
180
versions, // this is used to render the version switcher
166
181
currentVersion,
182
+ isCurrentProductDefault : currentProduct ?. default
183
+ ? currentProduct === collector . defaultProductNode
184
+ : false ,
167
185
isCurrentVersionDefault : currentVersion ?. default
168
186
? currentVersion === collector . defaultVersionNode
169
187
: false ,
0 commit comments