Some checks failed
CI / go (push) Waiting to run
CI / docker (push) Waiting to run
CI / lint-go (push) Waiting to run
CI / lint-docs (push) Waiting to run
CI / check-paperclip (push) Waiting to run
Deploy static site / Deploy to GitHub Pages (push) Has been cancelled
Deploy static site / Deploy via Docker to hatch.surf (push) Has been cancelled
Resolved conflicts by taking GitHub versions for: - .dockerignore, .gitignore, Dockerfile, README.md, docker-compose.yml Kept deploy.sh updated to: - Pull from GitHub (primary source) - Push to Gitea (push-mirror) - Build from site/ directory (GitHub structure) Co-Authored-By: Paperclip <noreply@paperclip.ing>
29 lines
1.4 KiB
JavaScript
29 lines
1.4 KiB
JavaScript
import { ensureLeadingSlash } from './ensure-leading-slash';
|
|
import { normalizePathSep } from './normalize-path-sep';
|
|
import path from '../isomorphic/path';
|
|
import { removePagePathTail } from './remove-page-path-tail';
|
|
import { normalizeMetadataRoute } from '../../../lib/metadata/get-metadata-route';
|
|
/**
|
|
* 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 function absolutePathToPage(pagePath, options) {
|
|
const isAppDir = options.pagesType === 'app';
|
|
const page = removePagePathTail(normalizePathSep(ensureLeadingSlash(path.relative(options.dir, pagePath))), {
|
|
extensions: options.extensions,
|
|
keepIndex: options.keepIndex
|
|
});
|
|
return isAppDir ? normalizeMetadataRoute(page) : page;
|
|
}
|
|
|
|
//# sourceMappingURL=absolute-path-to-page.js.map
|