loader() — astro Function Reference
Architecture documentation for the loader() function in post-loader.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD f9ca6302_2b63_f984_687d_b039f0d829bf["loader()"] b4af2256_5c78_3627_f741_263a80576e37["post-loader.ts"] f9ca6302_2b63_f984_687d_b039f0d829bf -->|defined in| b4af2256_5c78_3627_f741_263a80576e37 style f9ca6302_2b63_f984_687d_b039f0d829bf fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/astro/e2e/fixtures/cloudflare/src/loaders/post-loader.ts lines 8–45
export function loader(config:PostLoaderConfig): Loader {
return {
name: "post-loader",
load: async ({
store, meta, logger
}) => {
logger.info('Loading posts');
const lastSynced = meta.get('lastSynced');
// Don't sync more than once a minute
if (lastSynced && (Date.now() - Number(lastSynced) < 1000 * 60)) {
logger.info('Skipping sync');
return;
}
const posts = await fetch(config.url)
.then((res) => res.json());
store.clear();
for (const data of posts) {
store.set({id: data.id, data});
}
meta.set('lastSynced', String(Date.now()));
},
schema: async () => {
// Simulate a delay
await new Promise((resolve) => setTimeout(resolve, 1000));
return z.object({
title: z.string(),
body: z.string(),
userId: z.number(),
id: z.number(),
});
}
};
}
Domain
Subdomains
Source
Frequently Asked Questions
What does loader() do?
loader() is a function in the astro codebase, defined in packages/astro/e2e/fixtures/cloudflare/src/loaders/post-loader.ts.
Where is loader() defined?
loader() is defined in packages/astro/e2e/fixtures/cloudflare/src/loaders/post-loader.ts at line 8.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free