@@ -82,11 +82,38 @@ function changeCatalogMenueFunction(event) {
8282
8383//?: ืืฉืื ืฉื ืืืจืืข ืฉืืจืขื ื ืืช ืืืคืื
8484document . addEventListener ( 'DOMContentLoaded' , ( ) => {
85+ // ืืืืฃ ืึพusername ืึพrepo ืฉืื
86+ const githubUsername = 'shaialt' ;
87+ const githubRepo = 'Moto-Ride' ;
88+
89+ // ืืืืง ืื ืื ืื ื ืึพGitHub Pages ืืคื ื-hostname (ืืคืฉืจ ืืืชืืื ืืคื ืืฆืืจื)
90+ const isGitHubPages = window . location . hostname === `${ githubUsername } .github.io` ;
91+
92+ // ืืืืืจ ืืช ืืกืืก ืื ืชืื ืืคื ืืกืืืื:
93+ // ืื GitHub Pages: /repo-name/
94+ // ืืืจืช (ืืืื ืกืจืืจ ืืงืืื ืื ืกืืืื ืืืจืช): ../
95+ const basePath = isGitHubPages ? `/${ githubRepo } /` : '/' ;
96+
8597 //?: ืืื ืกืช ืืืฆืจืื ืืชืื ื'ืืืกืื ืืงืืืื ืืืคื ืืขืื
86- fetch ( '/ public/data/products.json' )
98+ fetch ( ` ${ basePath } public/data/products.json` )
8799 . then ( response => response . json ( ) )
88100 . then ( products => {
89101
102+ // ืืชืงื ื ืชืืืื ืฉื ืชืืื ืืช ืืื ืืืฆืจ
103+ products . forEach ( product => {
104+ // ืืื ืื ืงืื ืืช ืื ืชืื ืืืืกื "../" ืืืืกืืคืื ืืช basePath
105+ // ืฉืื ืื ืฉืฆืจืื ืืืชืืื ืืช ืื ืชืื ืื ืฉืืชืืื ืืชืืงืืืช images ืืืขืจืืช ืฉืื
106+ if ( product . image ) {
107+ product . image = product . image . replace ( / ^ ( \. \. \/ ) + / , basePath ) ;
108+ }
109+ if ( product . logo ) {
110+ product . logo = product . logo . replace ( / ^ ( \. \. \/ ) + / , basePath ) ;
111+ }
112+ if ( Array . isArray ( product . images ) ) {
113+ product . images = product . images . map ( imgPath => imgPath . replace ( / ^ ( \. \. \/ ) + / , basePath ) ) ;
114+ }
115+ } ) ;
116+
90117 // ืืืืงืช ืืืืช ืืืฆืจืื ืืืชืจ
91118 let productsNumbersTotal = 0 ;
92119 products . forEach ( ( ) => productsNumbersTotal ++ ) ;
0 commit comments