File tree Expand file tree Collapse file tree 3 files changed +45
-3
lines changed Expand file tree Collapse file tree 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({
3131 props . target = '_self' ;
3232 }
3333
34+ if ( item . customProps ) {
35+ for ( const key of Object . keys ( item . customProps ) ) {
36+ props [ `data-${ key } ` ] = item . customProps [ key ] ;
37+ }
38+ }
39+
3440 return (
3541 < li
3642 className = { clsx (
Original file line number Diff line number Diff line change @@ -84,8 +84,14 @@ function redirectOpenApiDocs() {
8484 }
8585
8686 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+ }
8995 }
9096
9197 if ( hash . startsWith ( '#tag/' ) ) {
@@ -109,7 +115,7 @@ document.addEventListener('scroll', () => {
109115} ) ;
110116
111117window . addEventListener ( 'load' , ( ) => {
112- redirectOpenApiDocs ( ) ;
118+ setTimeout ( ( ) => redirectOpenApiDocs ( ) , 500 ) ;
113119
114120 // we need to wait a bit more, since the event fires too soon, and a lot of hydration is done after it
115121 setTimeout ( ( ) => scrollSidebarItemIntoView ( ) , 1000 ) ;
Original file line number Diff line number Diff line change 11const { join } = require ( 'node:path' ) ;
22
3+ const clsx = require ( 'clsx' ) ;
4+
35const { config } = require ( './apify-docs-theme' ) ;
46const { collectSlugs } = require ( './tools/utils/collectSlugs' ) ;
57const { externalLinkProcessor } = require ( './tools/utils/externalLink' ) ;
@@ -190,6 +192,34 @@ module.exports = {
190192 groupPathsBy : 'tag' ,
191193 sidebarCollapsed : false ,
192194 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+ } ,
193223 } ,
194224 } ,
195225 } ,
You can’t perform that action at this time.
0 commit comments