File tree 3 files changed +45
-3
lines changed
3 files changed +45
-3
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,12 @@ export default function DocSidebarItemLink({
31
31
props . target = '_self' ;
32
32
}
33
33
34
+ if ( item . customProps ) {
35
+ for ( const key of Object . keys ( item . customProps ) ) {
36
+ props [ `data-${ key } ` ] = item . customProps [ key ] ;
37
+ }
38
+ }
39
+
34
40
return (
35
41
< li
36
42
className = { clsx (
Original file line number Diff line number Diff line change @@ -84,8 +84,14 @@ function redirectOpenApiDocs() {
84
84
}
85
85
86
86
if ( hash . startsWith ( '#/reference/' ) ) {
87
- const id = hash . substring ( '/#reference/' . length ) ;
88
- console . log ( 'redirect' , { id, hash } ) ;
87
+ const sidebarItems = document . querySelectorAll ( '[data-altids]' ) ;
88
+
89
+ for ( const item of sidebarItems ) {
90
+ const ids = item . getAttribute ( 'data-altids' ) . split ( ',' ) ;
91
+ if ( ids . find ( ( variant ) => variant === hash ) ) {
92
+ item . click ( ) ;
93
+ }
94
+ }
89
95
}
90
96
91
97
if ( hash . startsWith ( '#tag/' ) ) {
@@ -109,7 +115,7 @@ document.addEventListener('scroll', () => {
109
115
} ) ;
110
116
111
117
window . addEventListener ( 'load' , ( ) => {
112
- redirectOpenApiDocs ( ) ;
118
+ setTimeout ( ( ) => redirectOpenApiDocs ( ) , 500 ) ;
113
119
114
120
// we need to wait a bit more, since the event fires too soon, and a lot of hydration is done after it
115
121
setTimeout ( ( ) => scrollSidebarItemIntoView ( ) , 1000 ) ;
Original file line number Diff line number Diff line change 1
1
const { join } = require ( 'node:path' ) ;
2
2
3
+ const clsx = require ( 'clsx' ) ;
4
+
3
5
const { config } = require ( './apify-docs-theme' ) ;
4
6
const { collectSlugs } = require ( './tools/utils/collectSlugs' ) ;
5
7
const { externalLinkProcessor } = require ( './tools/utils/externalLink' ) ;
@@ -190,6 +192,34 @@ module.exports = {
190
192
groupPathsBy : 'tag' ,
191
193
sidebarCollapsed : false ,
192
194
sidebarCollapsible : false ,
195
+ sidebarGenerators : {
196
+ createDocItem : ( item , context ) => {
197
+ const legacyUrls = item . api [ 'x-legacy-doc-urls' ] ?? [ ] ;
198
+ const altIds = legacyUrls . map ( ( url ) => {
199
+ const { hash } = new URL ( url ) ;
200
+ return hash ;
201
+ } ) ;
202
+ const sidebarLabel = item . frontMatter . sidebar_label ;
203
+ const { title } = item ;
204
+ const id = item . type === 'schema' ? `schemas/${ item . id } ` : item . id ;
205
+ const className = item . type === 'api'
206
+ ? clsx ( {
207
+ 'menu__list-item--deprecated' : item . api . deprecated ,
208
+ 'api-method' : ! ! item . api . method ,
209
+ } , item . api . method )
210
+ : clsx ( {
211
+ 'menu__list-item--deprecated' : item . schema . deprecated ,
212
+ } , 'schema' ) ;
213
+
214
+ return {
215
+ type : 'doc' ,
216
+ id : context . basePath === '' ? `${ id } ` : `${ context . basePath } /${ id } ` ,
217
+ label : sidebarLabel ?? title ?? id ,
218
+ customProps : { altIds } ,
219
+ className,
220
+ } ;
221
+ } ,
222
+ } ,
193
223
} ,
194
224
} ,
195
225
} ,
You can’t perform that action at this time.
0 commit comments