UNPKG

next

Version:

The React Framework

47 lines (46 loc) 2.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "getNextPathnameInfo", { enumerable: true, get: function() { return getNextPathnameInfo; } }); const _normalizelocalepath = require("../../i18n/normalize-locale-path"); const _removepathprefix = require("./remove-path-prefix"); const _pathhasprefix = require("./path-has-prefix"); function getNextPathnameInfo(pathname, options) { var _options_nextConfig; const { basePath , i18n , trailingSlash } = (_options_nextConfig = options.nextConfig) != null ? _options_nextConfig : {}; const info = { pathname: pathname, trailingSlash: pathname !== "/" ? pathname.endsWith("/") : trailingSlash }; if (basePath && (0, _pathhasprefix.pathHasPrefix)(info.pathname, basePath)) { info.pathname = (0, _removepathprefix.removePathPrefix)(info.pathname, basePath); info.basePath = basePath; } if (options.parseData === true && info.pathname.startsWith("/_next/data/") && info.pathname.endsWith(".json")) { const paths = info.pathname.replace(/^\/_next\/data\//, "").replace(/\.json$/, "").split("/"); const buildId = paths[0]; info.pathname = paths[1] !== "index" ? "/" + paths.slice(1).join("/") : "/"; info.buildId = buildId; } // If provided, use the locale route normalizer to detect the locale instead // of the function below. if (options.i18nProvider) { const result = options.i18nProvider.analyze(info.pathname); info.locale = result.detectedLocale; var _result_pathname; info.pathname = (_result_pathname = result.pathname) != null ? _result_pathname : info.pathname; } else if (i18n) { const pathLocale = (0, _normalizelocalepath.normalizeLocalePath)(info.pathname, i18n.locales); info.locale = pathLocale.detectedLocale; var _pathLocale_pathname; info.pathname = (_pathLocale_pathname = pathLocale.pathname) != null ? _pathLocale_pathname : info.pathname; } return info; } //# sourceMappingURL=get-next-pathname-info.js.map