.
This commit is contained in:
+22
@@ -0,0 +1,22 @@
|
||||
import type { PAGE_TYPES } from '../../../lib/page-types';
|
||||
/**
|
||||
* Given the absolute path to the pages folder, an absolute file path for a
|
||||
* page and the page extensions, this function will return the page path
|
||||
* relative to the pages folder. It doesn't consider index tail. Example:
|
||||
* - `/Users/rick/my-project/pages/foo/bar/baz.js` -> `/foo/bar/baz`
|
||||
*
|
||||
* It also handles special metadata routes mapping. Example:
|
||||
* - `/Users/rick/my-project/app/sitemap.js` -> `/sitemap/route`
|
||||
*
|
||||
* @param filepath Absolute path to the page.
|
||||
* @param opts.dir Absolute path to the pages/app folder.
|
||||
* @param opts.extensions Extensions allowed for the page.
|
||||
* @param opts.keepIndex When true the trailing `index` kept in the path.
|
||||
* @param opts.pagesType Whether the page is in the pages or app directory.
|
||||
*/
|
||||
export declare function absolutePathToPage(pagePath: string, options: {
|
||||
extensions: string[] | readonly string[];
|
||||
keepIndex: boolean;
|
||||
dir: string;
|
||||
pagesType: PAGE_TYPES;
|
||||
}): string;
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "absolutePathToPage", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return absolutePathToPage;
|
||||
}
|
||||
});
|
||||
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
||||
const _ensureleadingslash = require("./ensure-leading-slash");
|
||||
const _normalizepathsep = require("./normalize-path-sep");
|
||||
const _path = /*#__PURE__*/ _interop_require_default._(require("../isomorphic/path"));
|
||||
const _removepagepathtail = require("./remove-page-path-tail");
|
||||
const _getmetadataroute = require("../../../lib/metadata/get-metadata-route");
|
||||
function absolutePathToPage(pagePath, options) {
|
||||
const isAppDir = options.pagesType === 'app';
|
||||
const page = (0, _removepagepathtail.removePagePathTail)((0, _normalizepathsep.normalizePathSep)((0, _ensureleadingslash.ensureLeadingSlash)(_path.default.relative(options.dir, pagePath))), {
|
||||
extensions: options.extensions,
|
||||
keepIndex: options.keepIndex
|
||||
});
|
||||
return isAppDir ? (0, _getmetadataroute.normalizeMetadataRoute)(page) : page;
|
||||
}
|
||||
|
||||
//# sourceMappingURL=absolute-path-to-page.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../../src/shared/lib/page-path/absolute-path-to-page.ts"],"sourcesContent":["import { ensureLeadingSlash } from './ensure-leading-slash'\nimport { normalizePathSep } from './normalize-path-sep'\nimport path from '../isomorphic/path'\nimport { removePagePathTail } from './remove-page-path-tail'\nimport { normalizeMetadataRoute } from '../../../lib/metadata/get-metadata-route'\nimport type { PAGE_TYPES } from '../../../lib/page-types'\n\n/**\n * Given the absolute path to the pages folder, an absolute file path for a\n * page and the page extensions, this function will return the page path\n * relative to the pages folder. It doesn't consider index tail. Example:\n * - `/Users/rick/my-project/pages/foo/bar/baz.js` -> `/foo/bar/baz`\n *\n * It also handles special metadata routes mapping. Example:\n * - `/Users/rick/my-project/app/sitemap.js` -> `/sitemap/route`\n *\n * @param filepath Absolute path to the page.\n * @param opts.dir Absolute path to the pages/app folder.\n * @param opts.extensions Extensions allowed for the page.\n * @param opts.keepIndex When true the trailing `index` kept in the path.\n * @param opts.pagesType Whether the page is in the pages or app directory.\n */\nexport function absolutePathToPage(\n pagePath: string,\n options: {\n extensions: string[] | readonly string[]\n keepIndex: boolean\n dir: string\n pagesType: PAGE_TYPES\n }\n) {\n const isAppDir = options.pagesType === 'app'\n const page = removePagePathTail(\n normalizePathSep(ensureLeadingSlash(path.relative(options.dir, pagePath))),\n {\n extensions: options.extensions,\n keepIndex: options.keepIndex,\n }\n )\n return isAppDir ? normalizeMetadataRoute(page) : page\n}\n"],"names":["absolutePathToPage","pagePath","options","isAppDir","pagesType","page","removePagePathTail","normalizePathSep","ensureLeadingSlash","path","relative","dir","extensions","keepIndex","normalizeMetadataRoute"],"mappings":";;;;+BAsBgBA;;;eAAAA;;;;oCAtBmB;kCACF;+DAChB;oCACkB;kCACI;AAkBhC,SAASA,mBACdC,QAAgB,EAChBC,OAKC;IAED,MAAMC,WAAWD,QAAQE,SAAS,KAAK;IACvC,MAAMC,OAAOC,IAAAA,sCAAkB,EAC7BC,IAAAA,kCAAgB,EAACC,IAAAA,sCAAkB,EAACC,aAAI,CAACC,QAAQ,CAACR,QAAQS,GAAG,EAAEV,aAC/D;QACEW,YAAYV,QAAQU,UAAU;QAC9BC,WAAWX,QAAQW,SAAS;IAC9B;IAEF,OAAOV,WAAWW,IAAAA,wCAAsB,EAACT,QAAQA;AACnD","ignoreList":[0]}
|
||||
+1
@@ -0,0 +1 @@
|
||||
export declare function denormalizeAppPagePath(page: string): string;
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "denormalizeAppPagePath", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return denormalizeAppPagePath;
|
||||
}
|
||||
});
|
||||
function denormalizeAppPagePath(page) {
|
||||
// `/` is normalized to `/index`
|
||||
if (page === '/index') {
|
||||
return '/';
|
||||
}
|
||||
return page;
|
||||
}
|
||||
|
||||
//# sourceMappingURL=denormalize-app-path.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../../src/shared/lib/page-path/denormalize-app-path.ts"],"sourcesContent":["export function denormalizeAppPagePath(page: string): string {\n // `/` is normalized to `/index`\n if (page === '/index') {\n return '/'\n }\n\n return page\n}\n"],"names":["denormalizeAppPagePath","page"],"mappings":";;;;+BAAgBA;;;eAAAA;;;AAAT,SAASA,uBAAuBC,IAAY;IACjD,gCAAgC;IAChC,IAAIA,SAAS,UAAU;QACrB,OAAO;IACT;IAEA,OAAOA;AACT","ignoreList":[0]}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Performs the opposite transformation of `normalizePagePath`. Note that
|
||||
* this function is not idempotent either in cases where there are multiple
|
||||
* leading `/index` for the page. Examples:
|
||||
* - `/index` -> `/`
|
||||
* - `/index/foo` -> `/foo`
|
||||
* - `/index/index` -> `/index`
|
||||
*/
|
||||
export declare function denormalizePagePath(page: string): string;
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "denormalizePagePath", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return denormalizePagePath;
|
||||
}
|
||||
});
|
||||
const _utils = require("../router/utils");
|
||||
const _normalizepathsep = require("./normalize-path-sep");
|
||||
function denormalizePagePath(page) {
|
||||
let _page = (0, _normalizepathsep.normalizePathSep)(page);
|
||||
return _page.startsWith('/index/') && !(0, _utils.isDynamicRoute)(_page) ? _page.slice(6) : _page !== '/index' ? _page : '/';
|
||||
}
|
||||
|
||||
//# sourceMappingURL=denormalize-page-path.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../../src/shared/lib/page-path/denormalize-page-path.ts"],"sourcesContent":["import { isDynamicRoute } from '../router/utils'\nimport { normalizePathSep } from './normalize-path-sep'\n\n/**\n * Performs the opposite transformation of `normalizePagePath`. Note that\n * this function is not idempotent either in cases where there are multiple\n * leading `/index` for the page. Examples:\n * - `/index` -> `/`\n * - `/index/foo` -> `/foo`\n * - `/index/index` -> `/index`\n */\nexport function denormalizePagePath(page: string) {\n let _page = normalizePathSep(page)\n return _page.startsWith('/index/') && !isDynamicRoute(_page)\n ? _page.slice(6)\n : _page !== '/index'\n ? _page\n : '/'\n}\n"],"names":["denormalizePagePath","page","_page","normalizePathSep","startsWith","isDynamicRoute","slice"],"mappings":";;;;+BAWgBA;;;eAAAA;;;uBAXe;kCACE;AAU1B,SAASA,oBAAoBC,IAAY;IAC9C,IAAIC,QAAQC,IAAAA,kCAAgB,EAACF;IAC7B,OAAOC,MAAME,UAAU,CAAC,cAAc,CAACC,IAAAA,qBAAc,EAACH,SAClDA,MAAMI,KAAK,CAAC,KACZJ,UAAU,WACRA,QACA;AACR","ignoreList":[0]}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* For a given page path, this function ensures that there is a leading slash.
|
||||
* If there is not a leading slash, one is added, otherwise it is noop.
|
||||
*/
|
||||
export declare function ensureLeadingSlash(path: string): string;
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* For a given page path, this function ensures that there is a leading slash.
|
||||
* If there is not a leading slash, one is added, otherwise it is noop.
|
||||
*/ "use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "ensureLeadingSlash", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return ensureLeadingSlash;
|
||||
}
|
||||
});
|
||||
function ensureLeadingSlash(path) {
|
||||
return path.startsWith('/') ? path : `/${path}`;
|
||||
}
|
||||
|
||||
//# sourceMappingURL=ensure-leading-slash.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../../src/shared/lib/page-path/ensure-leading-slash.ts"],"sourcesContent":["/**\n * For a given page path, this function ensures that there is a leading slash.\n * If there is not a leading slash, one is added, otherwise it is noop.\n */\nexport function ensureLeadingSlash(path: string) {\n return path.startsWith('/') ? path : `/${path}`\n}\n"],"names":["ensureLeadingSlash","path","startsWith"],"mappings":"AAAA;;;CAGC;;;;+BACeA;;;eAAAA;;;AAAT,SAASA,mBAAmBC,IAAY;IAC7C,OAAOA,KAAKC,UAAU,CAAC,OAAOD,OAAO,CAAC,CAAC,EAAEA,MAAM;AACjD","ignoreList":[0]}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Calculate all possible pagePaths for a given normalized pagePath along with
|
||||
* allowed extensions. This can be used to check which one of the files exists
|
||||
* and to debug inspected locations.
|
||||
*
|
||||
* For pages, map `/route` to [`/route.[ext]`, `/route/index.[ext]`]
|
||||
* For app paths, map `/route/page` to [`/route/page.[ext]`] or `/route/route`
|
||||
* to [`/route/route.[ext]`]
|
||||
*
|
||||
* @param normalizedPagePath Normalized page path (it will denormalize).
|
||||
* @param extensions Allowed extensions.
|
||||
*/
|
||||
export declare function getPagePaths(normalizedPagePath: string, extensions: string[], isAppDir: boolean): string[];
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "getPagePaths", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return getPagePaths;
|
||||
}
|
||||
});
|
||||
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
||||
const _denormalizepagepath = require("./denormalize-page-path");
|
||||
const _path = /*#__PURE__*/ _interop_require_default._(require("../isomorphic/path"));
|
||||
function getPagePaths(normalizedPagePath, extensions, isAppDir) {
|
||||
const page = (0, _denormalizepagepath.denormalizePagePath)(normalizedPagePath);
|
||||
let prefixes;
|
||||
if (isAppDir) {
|
||||
prefixes = [
|
||||
page
|
||||
];
|
||||
} else if (normalizedPagePath.endsWith('/index')) {
|
||||
prefixes = [
|
||||
_path.default.join(page, 'index')
|
||||
];
|
||||
} else {
|
||||
prefixes = [
|
||||
page,
|
||||
_path.default.join(page, 'index')
|
||||
];
|
||||
}
|
||||
const paths = [];
|
||||
for (const extension of extensions){
|
||||
for (const prefix of prefixes){
|
||||
paths.push(`${prefix}.${extension}`);
|
||||
}
|
||||
}
|
||||
return paths;
|
||||
}
|
||||
|
||||
//# sourceMappingURL=get-page-paths.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../../src/shared/lib/page-path/get-page-paths.ts"],"sourcesContent":["import { denormalizePagePath } from './denormalize-page-path'\nimport path from '../isomorphic/path'\n\n/**\n * Calculate all possible pagePaths for a given normalized pagePath along with\n * allowed extensions. This can be used to check which one of the files exists\n * and to debug inspected locations.\n *\n * For pages, map `/route` to [`/route.[ext]`, `/route/index.[ext]`]\n * For app paths, map `/route/page` to [`/route/page.[ext]`] or `/route/route`\n * to [`/route/route.[ext]`]\n *\n * @param normalizedPagePath Normalized page path (it will denormalize).\n * @param extensions Allowed extensions.\n */\nexport function getPagePaths(\n normalizedPagePath: string,\n extensions: string[],\n isAppDir: boolean\n) {\n const page = denormalizePagePath(normalizedPagePath)\n\n let prefixes: string[]\n if (isAppDir) {\n prefixes = [page]\n } else if (normalizedPagePath.endsWith('/index')) {\n prefixes = [path.join(page, 'index')]\n } else {\n prefixes = [page, path.join(page, 'index')]\n }\n\n const paths: string[] = []\n for (const extension of extensions) {\n for (const prefix of prefixes) {\n paths.push(`${prefix}.${extension}`)\n }\n }\n\n return paths\n}\n"],"names":["getPagePaths","normalizedPagePath","extensions","isAppDir","page","denormalizePagePath","prefixes","endsWith","path","join","paths","extension","prefix","push"],"mappings":";;;;+BAegBA;;;eAAAA;;;;qCAfoB;+DACnB;AAcV,SAASA,aACdC,kBAA0B,EAC1BC,UAAoB,EACpBC,QAAiB;IAEjB,MAAMC,OAAOC,IAAAA,wCAAmB,EAACJ;IAEjC,IAAIK;IACJ,IAAIH,UAAU;QACZG,WAAW;YAACF;SAAK;IACnB,OAAO,IAAIH,mBAAmBM,QAAQ,CAAC,WAAW;QAChDD,WAAW;YAACE,aAAI,CAACC,IAAI,CAACL,MAAM;SAAS;IACvC,OAAO;QACLE,WAAW;YAACF;YAAMI,aAAI,CAACC,IAAI,CAACL,MAAM;SAAS;IAC7C;IAEA,MAAMM,QAAkB,EAAE;IAC1B,KAAK,MAAMC,aAAaT,WAAY;QAClC,KAAK,MAAMU,UAAUN,SAAU;YAC7BI,MAAMG,IAAI,CAAC,GAAGD,OAAO,CAAC,EAAED,WAAW;QACrC;IACF;IAEA,OAAOD;AACT","ignoreList":[0]}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* strip _next/data/<build-id>/ prefix and .json suffix
|
||||
*/
|
||||
export declare function normalizeDataPath(pathname: string): string;
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "normalizeDataPath", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return normalizeDataPath;
|
||||
}
|
||||
});
|
||||
const _pathhasprefix = require("../router/utils/path-has-prefix");
|
||||
function normalizeDataPath(pathname) {
|
||||
if (!(0, _pathhasprefix.pathHasPrefix)(pathname || '/', '/_next/data')) {
|
||||
return pathname;
|
||||
}
|
||||
pathname = pathname.replace(/\/_next\/data\/[^/]{1,}/, '').replace(/\.json$/, '');
|
||||
if (pathname === '/index') {
|
||||
return '/';
|
||||
}
|
||||
return pathname;
|
||||
}
|
||||
|
||||
//# sourceMappingURL=normalize-data-path.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../../src/shared/lib/page-path/normalize-data-path.ts"],"sourcesContent":["import { pathHasPrefix } from '../router/utils/path-has-prefix'\n\n/**\n * strip _next/data/<build-id>/ prefix and .json suffix\n */\nexport function normalizeDataPath(pathname: string) {\n if (!pathHasPrefix(pathname || '/', '/_next/data')) {\n return pathname\n }\n pathname = pathname\n .replace(/\\/_next\\/data\\/[^/]{1,}/, '')\n .replace(/\\.json$/, '')\n\n if (pathname === '/index') {\n return '/'\n }\n return pathname\n}\n"],"names":["normalizeDataPath","pathname","pathHasPrefix","replace"],"mappings":";;;;+BAKgBA;;;eAAAA;;;+BALc;AAKvB,SAASA,kBAAkBC,QAAgB;IAChD,IAAI,CAACC,IAAAA,4BAAa,EAACD,YAAY,KAAK,gBAAgB;QAClD,OAAOA;IACT;IACAA,WAAWA,SACRE,OAAO,CAAC,2BAA2B,IACnCA,OAAO,CAAC,WAAW;IAEtB,IAAIF,aAAa,UAAU;QACzB,OAAO;IACT;IACA,OAAOA;AACT","ignoreList":[0]}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* Takes a page and transforms it into its file counterpart ensuring that the
|
||||
* output is normalized. Note this function is not idempotent because a page
|
||||
* `/index` can be referencing `/index/index.js` and `/index/index` could be
|
||||
* referencing `/index/index/index.js`. Examples:
|
||||
* - `/` -> `/index`
|
||||
* - `/index/foo` -> `/index/index/foo`
|
||||
* - `/index` -> `/index/index`
|
||||
*/
|
||||
export declare function normalizePagePath(page: string): string;
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "normalizePagePath", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return normalizePagePath;
|
||||
}
|
||||
});
|
||||
const _ensureleadingslash = require("./ensure-leading-slash");
|
||||
const _utils = require("../router/utils");
|
||||
const _utils1 = require("../utils");
|
||||
function normalizePagePath(page) {
|
||||
const normalized = /^\/index(\/|$)/.test(page) && !(0, _utils.isDynamicRoute)(page) ? `/index${page}` : page === '/' ? '/index' : (0, _ensureleadingslash.ensureLeadingSlash)(page);
|
||||
if (process.env.NEXT_RUNTIME !== 'edge') {
|
||||
const { posix } = require('path');
|
||||
const resolvedPage = posix.normalize(normalized);
|
||||
if (resolvedPage !== normalized) {
|
||||
throw new _utils1.NormalizeError(`Requested and resolved page mismatch: ${normalized} ${resolvedPage}`);
|
||||
}
|
||||
}
|
||||
return normalized;
|
||||
}
|
||||
|
||||
//# sourceMappingURL=normalize-page-path.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../../src/shared/lib/page-path/normalize-page-path.ts"],"sourcesContent":["import { ensureLeadingSlash } from './ensure-leading-slash'\nimport { isDynamicRoute } from '../router/utils'\nimport { NormalizeError } from '../utils'\n\n/**\n * Takes a page and transforms it into its file counterpart ensuring that the\n * output is normalized. Note this function is not idempotent because a page\n * `/index` can be referencing `/index/index.js` and `/index/index` could be\n * referencing `/index/index/index.js`. Examples:\n * - `/` -> `/index`\n * - `/index/foo` -> `/index/index/foo`\n * - `/index` -> `/index/index`\n */\nexport function normalizePagePath(page: string): string {\n const normalized =\n /^\\/index(\\/|$)/.test(page) && !isDynamicRoute(page)\n ? `/index${page}`\n : page === '/'\n ? '/index'\n : ensureLeadingSlash(page)\n\n if (process.env.NEXT_RUNTIME !== 'edge') {\n const { posix } = require('path') as typeof import('path')\n const resolvedPage = posix.normalize(normalized)\n if (resolvedPage !== normalized) {\n throw new NormalizeError(\n `Requested and resolved page mismatch: ${normalized} ${resolvedPage}`\n )\n }\n }\n\n return normalized\n}\n"],"names":["normalizePagePath","page","normalized","test","isDynamicRoute","ensureLeadingSlash","process","env","NEXT_RUNTIME","posix","require","resolvedPage","normalize","NormalizeError"],"mappings":";;;;+BAagBA;;;eAAAA;;;oCAbmB;uBACJ;wBACA;AAWxB,SAASA,kBAAkBC,IAAY;IAC5C,MAAMC,aACJ,iBAAiBC,IAAI,CAACF,SAAS,CAACG,IAAAA,qBAAc,EAACH,QAC3C,CAAC,MAAM,EAAEA,MAAM,GACfA,SAAS,MACP,WACAI,IAAAA,sCAAkB,EAACJ;IAE3B,IAAIK,QAAQC,GAAG,CAACC,YAAY,KAAK,QAAQ;QACvC,MAAM,EAAEC,KAAK,EAAE,GAAGC,QAAQ;QAC1B,MAAMC,eAAeF,MAAMG,SAAS,CAACV;QACrC,IAAIS,iBAAiBT,YAAY;YAC/B,MAAM,IAAIW,sBAAc,CACtB,CAAC,sCAAsC,EAAEX,WAAW,CAAC,EAAES,cAAc;QAEzE;IACF;IAEA,OAAOT;AACT","ignoreList":[0]}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* For a given page path, this function ensures that there is no backslash
|
||||
* escaping slashes in the path. Example:
|
||||
* - `foo\/bar\/baz` -> `foo/bar/baz`
|
||||
*/
|
||||
export declare function normalizePathSep(path: string): string;
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* For a given page path, this function ensures that there is no backslash
|
||||
* escaping slashes in the path. Example:
|
||||
* - `foo\/bar\/baz` -> `foo/bar/baz`
|
||||
*/ "use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "normalizePathSep", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return normalizePathSep;
|
||||
}
|
||||
});
|
||||
function normalizePathSep(path) {
|
||||
return path.replace(/\\/g, '/');
|
||||
}
|
||||
|
||||
//# sourceMappingURL=normalize-path-sep.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../../src/shared/lib/page-path/normalize-path-sep.ts"],"sourcesContent":["/**\n * For a given page path, this function ensures that there is no backslash\n * escaping slashes in the path. Example:\n * - `foo\\/bar\\/baz` -> `foo/bar/baz`\n */\nexport function normalizePathSep(path: string): string {\n return path.replace(/\\\\/g, '/')\n}\n"],"names":["normalizePathSep","path","replace"],"mappings":"AAAA;;;;CAIC;;;;+BACeA;;;eAAAA;;;AAAT,SAASA,iBAAiBC,IAAY;IAC3C,OAAOA,KAAKC,OAAO,CAAC,OAAO;AAC7B","ignoreList":[0]}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Removes the file extension for a page and the trailing `index` if it exists
|
||||
* making sure to not return an empty string. The page head is not touched
|
||||
* and returned as it is passed. Examples:
|
||||
* - `/foo/bar/baz/index.js` -> `/foo/bar/baz`
|
||||
* - `/foo/bar/baz.js` -> `/foo/bar/baz`
|
||||
*
|
||||
* @param pagePath A page to a page file (absolute or relative)
|
||||
* @param options.extensions Extensions allowed for the page.
|
||||
* @param options.keepIndex When true the trailing `index` is _not_ removed.
|
||||
*/
|
||||
export declare function removePagePathTail(pagePath: string, options: {
|
||||
extensions: ReadonlyArray<string>;
|
||||
keepIndex?: boolean;
|
||||
}): string;
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "removePagePathTail", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return removePagePathTail;
|
||||
}
|
||||
});
|
||||
const _normalizepathsep = require("./normalize-path-sep");
|
||||
function removePagePathTail(pagePath, options) {
|
||||
pagePath = (0, _normalizepathsep.normalizePathSep)(pagePath).replace(new RegExp(`\\.+(?:${options.extensions.join('|')})$`), '');
|
||||
if (options.keepIndex !== true) {
|
||||
pagePath = pagePath.replace(/\/index$/, '') || '/';
|
||||
}
|
||||
return pagePath;
|
||||
}
|
||||
|
||||
//# sourceMappingURL=remove-page-path-tail.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../../src/shared/lib/page-path/remove-page-path-tail.ts"],"sourcesContent":["import { normalizePathSep } from './normalize-path-sep'\n\n/**\n * Removes the file extension for a page and the trailing `index` if it exists\n * making sure to not return an empty string. The page head is not touched\n * and returned as it is passed. Examples:\n * - `/foo/bar/baz/index.js` -> `/foo/bar/baz`\n * - `/foo/bar/baz.js` -> `/foo/bar/baz`\n *\n * @param pagePath A page to a page file (absolute or relative)\n * @param options.extensions Extensions allowed for the page.\n * @param options.keepIndex When true the trailing `index` is _not_ removed.\n */\nexport function removePagePathTail(\n pagePath: string,\n options: {\n extensions: ReadonlyArray<string>\n keepIndex?: boolean\n }\n) {\n pagePath = normalizePathSep(pagePath).replace(\n new RegExp(`\\\\.+(?:${options.extensions.join('|')})$`),\n ''\n )\n\n if (options.keepIndex !== true) {\n pagePath = pagePath.replace(/\\/index$/, '') || '/'\n }\n\n return pagePath\n}\n"],"names":["removePagePathTail","pagePath","options","normalizePathSep","replace","RegExp","extensions","join","keepIndex"],"mappings":";;;;+BAagBA;;;eAAAA;;;kCAbiB;AAa1B,SAASA,mBACdC,QAAgB,EAChBC,OAGC;IAEDD,WAAWE,IAAAA,kCAAgB,EAACF,UAAUG,OAAO,CAC3C,IAAIC,OAAO,CAAC,OAAO,EAAEH,QAAQI,UAAU,CAACC,IAAI,CAAC,KAAK,EAAE,CAAC,GACrD;IAGF,IAAIL,QAAQM,SAAS,KAAK,MAAM;QAC9BP,WAAWA,SAASG,OAAO,CAAC,YAAY,OAAO;IACjD;IAEA,OAAOH;AACT","ignoreList":[0]}
|
||||
Reference in New Issue
Block a user