11const { join } = require ( "path" ) ;
22const { logTitle, logItem } = require ( "../../helpers/logger" ) ;
33const { NETLIFY_PUBLISH_PATH } = require ( "../../config" ) ;
4+ const getDataRouteForI18nRoute = require ( "../../helpers/getDataRouteForI18nRoute" ) ;
45const getFilePathForRoute = require ( "../../helpers/getFilePathForRoute" ) ;
56const getFilePathForRouteWithI18n = require ( "../../helpers/getFilePathForRouteWithI18n" ) ;
67const getNextConfig = require ( "../../helpers/getNextConfig" ) ;
@@ -31,30 +32,24 @@ const setup = () => {
3132 const { locales } = nextConfig . i18n ;
3233 if ( ! locales || locales . length === 0 ) return ;
3334
34- // ok so you dont need to loop over for srcRoutes and do the
35- // set up twice
3635 const isNotDynamic = ! srcRoute ;
37- // Dynamic routes dont need special helper, Next auto prepends with locale
38- // in prerender-manifest
36+ // Dynamic routes don't need special helper, Next auto prepends with locale
37+ // in prerender-manifest, but static routes are missing locale
3938 if ( isNotDynamic ) {
4039 locales . forEach ( ( locale ) => {
4140 // Copy pre-rendered HTML page
42- const htmlPath = getFilePathForRouteWithI18n ( route , "html" , locale ) ;
41+ const route_ = route === "/" ? "" : route ;
42+ const htmlPath = getFilePathForRouteWithI18n ( route_ , "html" , locale ) ;
4343 setupStaticFileForPage ( htmlPath ) ;
44+
45+ const jsonPath = getFilePathForRouteWithI18n ( route_ , "json" , locale ) ;
46+
47+ // the actual route to the json is under pages/{locale}
48+ // but the dataRoutes are the same for all locales according to
49+ // prerender-manifest..
50+ const realJsonDataRoute = getDataRouteForI18nRoute ( route , locale ) ;
51+ setupStaticFileForPage ( jsonPath , realJsonDataRoute ) ;
4452 } ) ;
45- // Copy page's JSON data
46- // TO-DO: get more clarity on dataRoute logic/files;
47- // dataRoute is the same for both/all locales (as is route above)
48- // BUT in setupStaticFileForPage we use the second arg as the outputhPath
49- // (unlike the html pages above where we use the first arg/route as the outputPath)
50- // and its not clear why.. but assuming we only have/need this
51- // one json we dont need to do in the locale loop/for each locale
52- const jsonPath = getFilePathForRouteWithI18n (
53- route ,
54- "json" ,
55- nextConfig . i18n . defaultLocale || locales [ 0 ]
56- ) ;
57- setupStaticFileForPage ( jsonPath , dataRoute ) ;
5853 } else {
5954 // Copy pre-rendered HTML page
6055 const htmlPath = getFilePathForRoute ( route , "html" ) ;
@@ -64,6 +59,7 @@ const setup = () => {
6459 const jsonPath = getFilePathForRoute ( route , "json" ) ;
6560 setupStaticFileForPage ( jsonPath , dataRoute ) ;
6661 }
62+ // TO-DO combine these conditions
6763 } else {
6864 // Copy pre-rendered HTML page
6965 const htmlPath = getFilePathForRoute ( route , "html" ) ;
0 commit comments