@@ -149,7 +149,7 @@ let DS_SEARCH = (function () {
149149 $ ( "#filtered_code_examples" ) . append (
150150 "<h4 id="
151151 + "example" . concat ( "0" . repeat ( 3 - example . ExampleNumber . toString ( ) . length ) ) . concat ( example . ExampleNumber ) + ">"
152- + "<a href = 'index.php?page="
152+ + "<a href = '" + getExampleUrlBase ( )
153153 + linkToCodeExample . concat ( "0" . repeat ( 3 - example . ExampleNumber . toString ( ) . length ) ) . concat ( example . ExampleNumber )
154154 + "' >"
155155 + example . ExampleName
@@ -204,13 +204,30 @@ let DS_SEARCH = (function () {
204204 $ ( "#filtered_code_examples" ) . append ( processJSONData ( ) . SupportingTexts . SearchFailed ) ;
205205 }
206206
207+ function getExampleUrlBase ( ) {
208+ // Create a temporary link element
209+ let tempLink = document . createElement ( 'a' ) ;
210+
211+ // Set the href property of the temporary link
212+ tempLink . href = 'index.php' ;
213+
214+ // Check if resolved URL contains 'public' in pathname
215+ const hasPublicInPathname = tempLink . href . includes ( 'public' ) ;
216+
217+ // Remove the temporary link from the DOM
218+ tempLink . remove ( ) ;
219+
220+ return hasPublicInPathname ? 'index.php?page=' : 'public/index.php?page=' ;
221+ }
222+
207223 return {
208224 processJSONData : processJSONData ,
209225 getEnteredAPIType : getEnteredAPIType ,
210226 getExamplesByAPIType : getExamplesByAPIType ,
211227 findCodeExamplesByKeywords : findCodeExamplesByKeywords ,
212228 textCouldNotBeFound : textCouldNotBeFound ,
213- addCodeExampleToHomepage : addCodeExampleToHomepage
229+ addCodeExampleToHomepage : addCodeExampleToHomepage ,
230+ getExampleUrlBase : getExampleUrlBase ,
214231 }
215232} ) ( ) ;
216233
0 commit comments