1
1
const { join } = require ( "path" ) ;
2
2
const { logTitle, logItem } = require ( "../../helpers/logger" ) ;
3
3
const { NETLIFY_PUBLISH_PATH } = require ( "../../config" ) ;
4
+ const getDataRouteForI18nRoute = require ( "../../helpers/getDataRouteForI18nRoute" ) ;
4
5
const getFilePathForRoute = require ( "../../helpers/getFilePathForRoute" ) ;
5
6
const getFilePathForRouteWithI18n = require ( "../../helpers/getFilePathForRouteWithI18n" ) ;
6
7
const getNextConfig = require ( "../../helpers/getNextConfig" ) ;
@@ -31,30 +32,24 @@ const setup = () => {
31
32
const { locales } = nextConfig . i18n ;
32
33
if ( ! locales || locales . length === 0 ) return ;
33
34
34
- // ok so you dont need to loop over for srcRoutes and do the
35
- // set up twice
36
35
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
39
38
if ( isNotDynamic ) {
40
39
locales . forEach ( ( locale ) => {
41
40
// Copy pre-rendered HTML page
42
- const htmlPath = getFilePathForRouteWithI18n ( route , "html" , locale ) ;
41
+ const route_ = route === "/" ? "" : route ;
42
+ const htmlPath = getFilePathForRouteWithI18n ( route_ , "html" , locale ) ;
43
43
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 ) ;
44
52
} ) ;
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 ) ;
58
53
} else {
59
54
// Copy pre-rendered HTML page
60
55
const htmlPath = getFilePathForRoute ( route , "html" ) ;
@@ -64,6 +59,7 @@ const setup = () => {
64
59
const jsonPath = getFilePathForRoute ( route , "json" ) ;
65
60
setupStaticFileForPage ( jsonPath , dataRoute ) ;
66
61
}
62
+ // TO-DO combine these conditions
67
63
} else {
68
64
// Copy pre-rendered HTML page
69
65
const htmlPath = getFilePathForRoute ( route , "html" ) ;
0 commit comments