Saltar al contenido principal

Function: useAstroPathsFrom()

useAstroPathsFrom<T, TParam, TProps>(items, options?): AstroPath<TParam, TProps>[]

Defined in: src/adapters/astro/astro.service.ts:28

Convert a collection into Astro-compatible static paths.

Type Parameters

T

T

TParam

TParam extends string = "slug"

TProps

TProps = T

Parameters

items

T[]

Collection items to convert

options?

PathsOptions<T, TParam, TProps> = {}

Configuration for param name, value extraction and props

Returns

AstroPath<TParam, TProps>[]

Array of Astro paths with params and props

Example

// In Astro's getStaticPaths()
const posts = await getCollection("blog");
const paths = useAstroPathsFrom(posts, {
param: "slug",
valueFrom: (post) => post.slug,
propsFrom: (post) => ({ title: post.data.title }),
});
// [{ params: { slug: "hello-world" }, props: { title: "Hello World" } }]