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>
44 lines
1.4 KiB
JavaScript
44 lines
1.4 KiB
JavaScript
import { isDynamicRoute } from '../../shared/lib/router/utils';
|
|
import { getRouteMatcher } from '../../shared/lib/router/utils/route-matcher';
|
|
import { getRouteRegex } from '../../shared/lib/router/utils/route-regex';
|
|
export class RouteMatcher {
|
|
constructor(definition){
|
|
this.definition = definition;
|
|
if (isDynamicRoute(definition.pathname)) {
|
|
this.dynamic = getRouteMatcher(getRouteRegex(definition.pathname));
|
|
}
|
|
}
|
|
/**
|
|
* Identity returns the identity part of the matcher. This is used to compare
|
|
* a unique matcher to another. This is also used when sorting dynamic routes,
|
|
* so it must contain the pathname part.
|
|
*/ get identity() {
|
|
return this.definition.pathname;
|
|
}
|
|
get isDynamic() {
|
|
return this.dynamic !== undefined;
|
|
}
|
|
match(pathname) {
|
|
const result = this.test(pathname);
|
|
if (!result) return null;
|
|
return {
|
|
definition: this.definition,
|
|
params: result.params
|
|
};
|
|
}
|
|
test(pathname) {
|
|
if (this.dynamic) {
|
|
const params = this.dynamic(pathname);
|
|
if (!params) return null;
|
|
return {
|
|
params
|
|
};
|
|
}
|
|
if (pathname === this.definition.pathname) {
|
|
return {};
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
//# sourceMappingURL=route-matcher.js.map
|