Skip to content
This repository was archived by the owner on May 10, 2021. It is now read-only.

Commit 9ba1646

Browse files
committed
make i18n getDataRoute helper more DRY
1 parent 3af66f8 commit 9ba1646

File tree

2 files changed

+5
-15
lines changed

2 files changed

+5
-15
lines changed
+3-14
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,8 @@
1-
const { join } = require("path");
2-
const { readFileSync } = require("fs-extra");
3-
const { NEXT_DIST_DIR } = require("../config");
4-
const getFilePathForRoute = require("./getFilePathForRoute");
1+
const getDataRouteForRoute = require("./getDataRouteForRoute");
52

6-
// TO-DO: make more DRY with other getDataRoute helper
7-
8-
// Get build ID that is used for data routes, e.g. /_next/data/BUILD_ID/...
9-
const fileContents = readFileSync(join(NEXT_DIST_DIR, "BUILD_ID"));
10-
const buildId = fileContents.toString();
11-
12-
// Return the data route for the given route
3+
// Return the data route for the given route with the correct locale
134
const getDataRouteForI18nRoute = (route, locale) => {
14-
const filePath = getFilePathForRoute(route, "json");
15-
16-
return join("/_next", "data", buildId, locale, filePath);
5+
return getDataRouteForRoute(route, locale);
176
};
187

198
module.exports = getDataRouteForI18nRoute;

lib/helpers/getDataRouteForRoute.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ const fileContents = readFileSync(join(NEXT_DIST_DIR, "BUILD_ID"));
88
const buildId = fileContents.toString();
99

1010
// Return the data route for the given route
11-
const getDataRouteForRoute = (route) => {
11+
const getDataRouteForRoute = (route, locale) => {
1212
const filePath = getFilePathForRoute(route, "json");
1313

14+
if (locale) return join("/_next", "data", buildId, locale, filePath);
1415
return join("/_next", "data", buildId, filePath);
1516
};
1617

0 commit comments

Comments
 (0)