Skip to content

Commit

Permalink
Prettify generated route names from integrations (#9375)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy authored Dec 8, 2023
1 parent 85c9a61 commit 26f7023
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/swift-buttons-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Prettifies generated route names injected by integrations
18 changes: 13 additions & 5 deletions packages/astro/src/core/build/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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`.
*
Expand Down

0 comments on commit 26f7023

Please sign in to comment.