get-next-pathname-info.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.getNextPathnameInfo = getNextPathnameInfo;
  6. var _normalizeLocalePath = require("../../i18n/normalize-locale-path");
  7. var _removePathPrefix = require("./remove-path-prefix");
  8. var _pathHasPrefix = require("./path-has-prefix");
  9. function getNextPathnameInfo(pathname, options) {
  10. var _nextConfig;
  11. const { basePath , i18n , trailingSlash } = (_nextConfig = options.nextConfig) != null ? _nextConfig : {};
  12. const info = {
  13. pathname: pathname,
  14. trailingSlash: pathname !== '/' ? pathname.endsWith('/') : trailingSlash
  15. };
  16. if (basePath && (0, _pathHasPrefix).pathHasPrefix(info.pathname, basePath)) {
  17. info.pathname = (0, _removePathPrefix).removePathPrefix(info.pathname, basePath);
  18. info.basePath = basePath;
  19. }
  20. if (options.parseData === true && info.pathname.startsWith('/_next/data/') && info.pathname.endsWith('.json')) {
  21. const paths = info.pathname.replace(/^\/_next\/data\//, '').replace(/\.json$/, '').split('/');
  22. const buildId = paths[0];
  23. info.pathname = paths[1] !== 'index' ? `/${paths.slice(1).join('/')}` : '/';
  24. info.buildId = buildId;
  25. }
  26. if (i18n) {
  27. const pathLocale = (0, _normalizeLocalePath).normalizeLocalePath(info.pathname, i18n.locales);
  28. info.locale = pathLocale == null ? void 0 : pathLocale.detectedLocale;
  29. info.pathname = (pathLocale == null ? void 0 : pathLocale.pathname) || info.pathname;
  30. }
  31. return info;
  32. }
  33. //# sourceMappingURL=get-next-pathname-info.js.map