normalizePathname() — astro Function Reference
Architecture documentation for the normalizePathname() function in path.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD 47733095_809d_0265_dd85_38a757ede8e7["normalizePathname()"] f5377c99_3ce3_1abd_148f_93394ff5efe2["path.ts"] 47733095_809d_0265_dd85_38a757ede8e7 -->|defined in| f5377c99_3ce3_1abd_148f_93394ff5efe2 style 47733095_809d_0265_dd85_38a757ede8e7 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/internal-helpers/src/path.ts lines 258–284
export function normalizePathname(
pathname: string,
buildFormat: 'file' | 'directory' | 'preserve',
trailingSlash: 'always' | 'never' | 'ignore',
): string {
if (buildFormat === 'file') {
// Strip .html extension (but not for root like /.html)
if (pathname.endsWith('.html') && pathname !== '/.html') {
return pathname.slice(0, -5);
}
// Handle edge case: index page with base gets mangled by removeBase
// e.g., /blog.html with base /blog → removeBase gives /html (missing the dot)
// In file format, all non-index paths should end with .html, so if it doesn't
// and it's not root, it's likely a mangled index pathname
if (pathname !== '/' && !pathname.endsWith('.html')) {
return '/';
}
} else {
// directory or preserve format
// Strip trailing slash when trailingSlash is 'ignore'
// (because getUrlForPath adds it, but getRouteGenerator doesn't)
if (trailingSlash === 'ignore' && pathname.endsWith('/') && pathname !== '/') {
return pathname.slice(0, -1);
}
}
return pathname;
}
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does normalizePathname() do?
normalizePathname() is a function in the astro codebase, defined in packages/internal-helpers/src/path.ts.
Where is normalizePathname() defined?
normalizePathname() is defined in packages/internal-helpers/src/path.ts at line 258.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free