Home / Function/ loader() — astro Function Reference

loader() — astro Function Reference

Architecture documentation for the loader() function in post-loader.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  2874d1b7_43d7_4a64_14e2_154eadd4cb15["loader()"]
  2d34d070_3638_0582_69ab_6b29151c3933["post-loader.ts"]
  2874d1b7_43d7_4a64_14e2_154eadd4cb15 -->|defined in| 2d34d070_3638_0582_69ab_6b29151c3933
  style 2874d1b7_43d7_4a64_14e2_154eadd4cb15 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/integrations/cloudflare/test/fixtures/vite-plugin/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

Frequently Asked Questions

What does loader() do?
loader() is a function in the astro codebase, defined in packages/integrations/cloudflare/test/fixtures/vite-plugin/src/loaders/post-loader.ts.
Where is loader() defined?
loader() is defined in packages/integrations/cloudflare/test/fixtures/vite-plugin/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