xref: /expo/docs/next.config.js (revision f10e66fc)
1const LATEST_VERSION = 'v' + require('./package.json').version;
2
3module.exports = {
4  async exportPathMap(defaultPathMap, {dev}) {
5    if (dev) {
6      return defaultPathMap
7    }
8    return Object.assign(
9      ...Object.entries(defaultPathMap).map(([pathname, page]) => {
10        if (pathname.match(/\/v[1-9][^\/]*$/)) {
11          // ends in "/v<version>"
12          pathname += '/index.html'; // TODO: find out why we need to do this
13        }
14
15        result = { [pathname]: page };
16
17        // For every path which doesn't end in ".html" (except "/"), create a matching copy with ".html" added
18        // (We have many internal links of this sort)
19        if (! pathname.match(/\.html$/) && pathname.match(/[a-z]$/)) {
20          result[pathname + ".html"] = page;
21        }
22
23        // For every path for the latest version, create a matching `latest` one
24        if (pathname.match(LATEST_VERSION)) {
25          latestPath = pathname.replace(LATEST_VERSION, 'latest');
26          result[latestPath] = page;
27          // TODO: fix duplication
28          if (! pathname.match(/\.html$/) && pathname.match(/[a-z]$/)) {
29            result[latestPath + ".html"] = page;
30          }
31        }
32
33        return result;
34      })
35    );
36  },
37};
38