astro.ts — astro Source File
Architecture documentation for astro.ts, a typescript file in the astro codebase. 3 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 3303a596_77e9_a4f6_1515_7ec93bef6e53["astro.ts"] bf9f5367_fd3b_919a_78d3_86893e42ad6d["./host-route.js"] 3303a596_77e9_a4f6_1515_7ec93bef6e53 --> bf9f5367_fd3b_919a_78d3_86893e42ad6d c52a5f83_66e3_37d7_9ebb_767f7129bc62["node:path"] 3303a596_77e9_a4f6_1515_7ec93bef6e53 --> c52a5f83_66e3_37d7_9ebb_767f7129bc62 f16d8c76_2866_6150_bd14_0347b59abfe9["astro"] 3303a596_77e9_a4f6_1515_7ec93bef6e53 --> f16d8c76_2866_6150_bd14_0347b59abfe9 style 3303a596_77e9_a4f6_1515_7ec93bef6e53 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import { posix } from 'node:path';
import type {
AstroConfig,
HookParameters,
IntegrationResolvedRoute,
ValidRedirectStatus,
} from 'astro';
import { type HostRouteDefinition, HostRoutes } from './host-route.js';
const pathJoin = posix.join;
function getRedirectStatus(route: IntegrationResolvedRoute): ValidRedirectStatus {
if (typeof route.redirect === 'object') {
return route.redirect.status;
}
return 301;
}
interface CreateRedirectsFromAstroRoutesParams {
config: Pick<AstroConfig, 'build' | 'output' | 'base'>;
/**
* Maps a `RouteData` to a dynamic target
*/
routeToDynamicTargetMap: Map<IntegrationResolvedRoute, string>;
dir: URL;
buildOutput: 'static' | 'server';
assets: HookParameters<'astro:build:done'>['assets'];
}
/**
* Takes a set of routes and creates a Redirects object from them.
*/
export function createRedirectsFromAstroRoutes({
config,
routeToDynamicTargetMap,
dir,
buildOutput,
assets,
}: CreateRedirectsFromAstroRoutesParams): HostRoutes {
const base =
config.base && config.base !== '/'
? config.base.endsWith('/')
? config.base.slice(0, -1)
: config.base
: '';
const redirects = new HostRoutes();
for (const [route, dynamicTarget = ''] of routeToDynamicTargetMap) {
const distURL = assets?.get(route.pattern);
// A route with a `pathname` is as static route.
if (route.pathname) {
if (route.redirect) {
// A redirect route without dynamic parts. Get the redirect status
// from the user if provided.
redirects.add({
dynamic: false,
input: `${base}${route.pathname}`,
target: typeof route.redirect === 'object' ? route.redirect.destination : route.redirect,
status: getRedirectStatus(route),
weight: 2,
// ... (143 more lines)
Domain
Subdomains
Functions
Dependencies
- ./host-route.js
- astro
- node:path
Source
Frequently Asked Questions
What does astro.ts do?
astro.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, RenderingEngine subdomain.
What functions are defined in astro.ts?
astro.ts defines 5 function(s): createHostedRouteDefinition, createRedirectsFromAstroRoutes, generateDynamicPattern, getRedirectStatus, prependForwardSlash.
What does astro.ts depend on?
astro.ts imports 3 module(s): ./host-route.js, astro, node:path.
Where is astro.ts in the architecture?
astro.ts is located at packages/underscore-redirects/src/astro.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/underscore-redirects/src).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free