@koine/next 1.2.0 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/config/index.js CHANGED
@@ -126,6 +126,12 @@ function getRoutesMap(map, routes, pathnameBuffer, templateBuffer) {
126
126
  }
127
127
  return map;
128
128
  }
129
+ /**
130
+ * Removes `/index` from a template/url path
131
+ */
132
+ function getWithoutIndex(template) {
133
+ return template.replace(/\/index$/, "");
134
+ }
129
135
  /**
130
136
  * Get path rewrite
131
137
  */
@@ -136,7 +142,7 @@ function getPathRewrite(route) {
136
142
  // console.log(`rewrite pathname "${source}" to template "${destination}"`);
137
143
  return {
138
144
  source: source,
139
- destination: destination.replace(/\/index$/, ""),
145
+ destination: getWithoutIndex(destination),
140
146
  };
141
147
  }
142
148
  exports.getPathRewrite = getPathRewrite;
@@ -150,7 +156,7 @@ function getPathRedirect(locale, route, permanent) {
150
156
  var destination = "/".concat(normaliseUrlPathname(pathname));
151
157
  // console.log(`redirect template "${source}" to pathname "${destination}"`);
152
158
  return {
153
- source: source.replace(/\/index$/, ""),
159
+ source: getWithoutIndex(source),
154
160
  destination: destination,
155
161
  permanent: Boolean(permanent),
156
162
  locale: false,
@@ -167,8 +173,16 @@ function getRedirects(defaultLocale, routes, permanent, debug) {
167
173
  routesMap = getRoutesMap({}, routes);
168
174
  Object.keys(routesMap).forEach(function (template) {
169
175
  var route = routesMap[template];
170
- if (route.pathname !== template) {
171
- redirects.push(getPathRedirect(defaultLocale, route, permanent));
176
+ // TODO: add option hideDefaultLocaleInUrl?
177
+ // this is meant to redirect the URL with the default locale to the same
178
+ // url without locale prefix, e.g.: /en/about -> /about (assuming en is the
179
+ // defualt locale).
180
+ // Actually this redirect seem not to be necessary, probably the i18n routing
181
+ // mechanism of next 12 already does this, enabling causes infinite redirects
182
+ // if (hideDefaultLocaleInUrl) {
183
+ // redirects.push(getPathRedirect(defaultLocale, route, permanent));
184
+ // }
185
+ if (route.pathname !== getWithoutIndex(template)) {
172
186
  redirects.push(getPathRedirect("", route, permanent));
173
187
  }
174
188
  });
@@ -189,7 +203,7 @@ function getRewrites(routes, debug) {
189
203
  routesMap = getRoutesMap({}, routes);
190
204
  Object.keys(routesMap).forEach(function (template) {
191
205
  var route = routesMap[template];
192
- if (route.pathname !== template) {
206
+ if (route.pathname !== getWithoutIndex(template)) {
193
207
  rewrites.push(getPathRewrite(route));
194
208
  }
195
209
  });
package/config/index.mjs CHANGED
@@ -120,6 +120,12 @@ function getRoutesMap(map, routes, pathnameBuffer, templateBuffer) {
120
120
  }
121
121
  return map;
122
122
  }
123
+ /**
124
+ * Removes `/index` from a template/url path
125
+ */
126
+ function getWithoutIndex(template) {
127
+ return template.replace(/\/index$/, "");
128
+ }
123
129
  /**
124
130
  * Get path rewrite
125
131
  */
@@ -130,7 +136,7 @@ export function getPathRewrite(route) {
130
136
  // console.log(`rewrite pathname "${source}" to template "${destination}"`);
131
137
  return {
132
138
  source: source,
133
- destination: destination.replace(/\/index$/, ""),
139
+ destination: getWithoutIndex(destination),
134
140
  };
135
141
  }
136
142
  /**
@@ -143,7 +149,7 @@ export function getPathRedirect(locale, route, permanent) {
143
149
  var destination = "/".concat(normaliseUrlPathname(pathname));
144
150
  // console.log(`redirect template "${source}" to pathname "${destination}"`);
145
151
  return {
146
- source: source.replace(/\/index$/, ""),
152
+ source: getWithoutIndex(source),
147
153
  destination: destination,
148
154
  permanent: Boolean(permanent),
149
155
  locale: false,
@@ -159,8 +165,16 @@ export function getRedirects(defaultLocale, routes, permanent, debug) {
159
165
  routesMap = getRoutesMap({}, routes);
160
166
  Object.keys(routesMap).forEach(function (template) {
161
167
  var route = routesMap[template];
162
- if (route.pathname !== template) {
163
- redirects.push(getPathRedirect(defaultLocale, route, permanent));
168
+ // TODO: add option hideDefaultLocaleInUrl?
169
+ // this is meant to redirect the URL with the default locale to the same
170
+ // url without locale prefix, e.g.: /en/about -> /about (assuming en is the
171
+ // defualt locale).
172
+ // Actually this redirect seem not to be necessary, probably the i18n routing
173
+ // mechanism of next 12 already does this, enabling causes infinite redirects
174
+ // if (hideDefaultLocaleInUrl) {
175
+ // redirects.push(getPathRedirect(defaultLocale, route, permanent));
176
+ // }
177
+ if (route.pathname !== getWithoutIndex(template)) {
164
178
  redirects.push(getPathRedirect("", route, permanent));
165
179
  }
166
180
  });
@@ -180,7 +194,7 @@ export function getRewrites(routes, debug) {
180
194
  routesMap = getRoutesMap({}, routes);
181
195
  Object.keys(routesMap).forEach(function (template) {
182
196
  var route = routesMap[template];
183
- if (route.pathname !== template) {
197
+ if (route.pathname !== getWithoutIndex(template)) {
184
198
  rewrites.push(getPathRewrite(route));
185
199
  }
186
200
  });
package/package.json CHANGED
@@ -98,13 +98,13 @@
98
98
  "type-fest": "^3.6.0"
99
99
  },
100
100
  "peerDependencies": {
101
- "@koine/browser": "1.2.0",
102
- "@koine/dom": "1.2.0",
103
- "@koine/react": "1.2.0",
104
- "@koine/utils": "1.2.0"
101
+ "@koine/browser": "1.2.2",
102
+ "@koine/dom": "1.2.2",
103
+ "@koine/react": "1.2.2",
104
+ "@koine/utils": "1.2.2"
105
105
  },
106
106
  "main": "./index.js",
107
107
  "types": "./index.d.ts",
108
- "version": "1.2.0",
108
+ "version": "1.2.2",
109
109
  "module": "./index.mjs"
110
110
  }