0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-04-14 23:51:49 -05:00

Prettify generated route names from integrations ()

This commit is contained in:
Bjorn Lu 2023-12-08 23:38:19 +08:00 committed by GitHub
parent 85c9a61216
commit 26f7023d69
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 5 deletions
.changeset
packages/astro/src/core/build

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Prettifies generated route names injected by integrations

View file

@ -296,11 +296,7 @@ async function generatePage(
route.type === 'page' || route.type === 'redirect' || route.type === 'fallback'
? green('▶')
: magenta('λ');
if (isRelativePath(route.component)) {
logger.info(null, `${icon} ${route.route}`);
} else {
logger.info(null, `${icon} ${route.component}`);
}
logger.info(null, `${icon} ${getPrettyRouteName(route)}`);
// Get paths for the route, calling getStaticPaths if needed.
const paths = await getPathsForRoute(route, pageModule, pipeline, builtPaths);
let timeStart = performance.now();
@ -612,6 +608,18 @@ async function generatePath(
await fs.promises.writeFile(outFile, body);
}
function getPrettyRouteName(route: RouteData): string {
if (isRelativePath(route.component)) {
return route.route;
} else if (route.component.includes('node_modules/')) {
// For routes from node_modules (usually injected by integrations),
// prettify it by only grabbing the part after the last `node_modules/`
return route.component.match(/.*node_modules\/(.+)/)?.[1] ?? route.component;
} else {
return route.component;
}
}
/**
* It creates a `SSRManifest` from the `AstroSettings`.
*