@@ -82,11 +82,22 @@ const getStackRemovalDate = async (pagePath) => {
8282 return stackReport ?. stack_meta ?. removal_date ? formatDate ( new Date ( stackReport . stack_meta . removal_date ) ) : null ;
8383} ;
8484
85+ const getStacksLink = ( path , useFallback = false ) => {
86+ if ( useFallback ) {
87+ return `/stacks/subpage?subpage=${ path . replace ( / ^ \/ / , '' ) } ` ;
88+ }
89+ return `/stacks${ path } ` ;
90+ } ;
91+
8592( async ( ) => {
8693 const url = new URL ( document . location . href ) ;
87- const pagePath = detectTopicFromUrl ( url , 'stacks' ) . replace ( / \/ $ / , '' ) ;
94+ const pagePath = detectTopicFromUrl ( url , 'stacks' , 'subpage' ) . replace ( / \/ $ / , '' ) ;
8895 const pageType = pagePath . split ( '/' ) [ 0 ] ;
8996
97+ const proxyAvailable = await fetch ( '/stacks-proxy' )
98+ . then ( ( response ) => response . ok )
99+ . catch ( ( ) => false ) ;
100+
90101 if ( pageType === '' ) {
91102 const stackService = new StacksService ( ) ;
92103 const stacksLinks = await stackService . fetchStacksIndexJson ( ) ;
@@ -468,6 +479,12 @@ const getStackRemovalDate = async (pagePath) => {
468479 window . location . href = '/stacks' ;
469480 }
470481
482+ document . querySelectorAll ( 'a[href^="/stacks"]' ) . forEach ( ( link ) => {
483+ if ( ! proxyAvailable && ! link . href . match ( / \. x m l $ / ) && ! link . href . match ( / \/ s t a c k s \/ s u b p a g e / ) ) {
484+ link . href = getStacksLink ( link . getAttribute ( 'href' ) . replace ( / ^ .* \/ s t a c k s \/ / , '' ) , true ) ;
485+ }
486+ } ) ;
487+
471488 fancyConsoleLog ( 'Bitrise.io Stacks' ) ;
472489} ) ( ) ;
473490
0 commit comments