-
Notifications
You must be signed in to change notification settings - Fork 27.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c595a2c
commit 60e92c9
Showing
31 changed files
with
166 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
packages/next/shared/lib/page-path/absolute-path-to-page.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { ensureLeadingSlash } from './ensure-leading-slash' | ||
import { normalizePathSep } from './normalize-path-sep' | ||
import { relative } from '../isomorphic/path' | ||
import { removePagePathTail } from './remove-page-path-tail' | ||
|
||
/** | ||
* 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` | ||
* | ||
* @param pagesDir Absolute path to the pages folder. | ||
* @param filepath Absolute path to the page. | ||
* @param extensions Extensions allowed for the page. | ||
*/ | ||
export function absolutePathToPage( | ||
pagesDir: string, | ||
pagePath: string, | ||
extensions: string[] | ||
) { | ||
return removePagePathTail( | ||
normalizePathSep(ensureLeadingSlash(relative(pagesDir, pagePath))), | ||
extensions | ||
) | ||
} |
19 changes: 19 additions & 0 deletions
19
packages/next/shared/lib/page-path/denormalize-page-path.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { isDynamicRoute } from '../router/utils' | ||
import { normalizePathSep } from './normalize-path-sep' | ||
|
||
/** | ||
* 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 function denormalizePagePath(page: string) { | ||
let _page = normalizePathSep(page) | ||
return _page.startsWith('/index/') && !isDynamicRoute(_page) | ||
? _page.slice(6) | ||
: _page !== '/index' | ||
? _page | ||
: '/' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* 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 function ensureLeadingSlash(path: string) { | ||
return path.startsWith('/') ? path : `/${path}` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { denormalizePagePath } from './denormalize-page-path' | ||
import { flatten } from '../flatten' | ||
import { join } from '../isomorphic/path' | ||
|
||
/** | ||
* 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. | ||
* | ||
* @param normalizedPagePath Normalized page path (it will denormalize). | ||
* @param extensions Allowed extensions. | ||
*/ | ||
export function getPagePaths(normalizedPagePath: string, extensions: string[]) { | ||
const page = denormalizePagePath(normalizedPagePath) | ||
return flatten( | ||
extensions.map((extension) => { | ||
return !normalizedPagePath.endsWith('/index') | ||
? [`${page}.${extension}`, join(page, `index.${extension}`)] | ||
: [join(page, `index.${extension}`)] | ||
}) | ||
) | ||
} |
Oops, something went wrong.