Home / File/ post-loader.ts — astro Source File

post-loader.ts — astro Source File

Architecture documentation for post-loader.ts, a typescript file in the astro codebase. 2 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  b4af2256_5c78_3627_f741_263a80576e37["post-loader.ts"]
  48f80d01_e646_3924_78f6_a9d836644746["astro:content"]
  b4af2256_5c78_3627_f741_263a80576e37 --> 48f80d01_e646_3924_78f6_a9d836644746
  d47373dc_6761_5858_3027_a4a6472dd795["loaders"]
  b4af2256_5c78_3627_f741_263a80576e37 --> d47373dc_6761_5858_3027_a4a6472dd795
  style b4af2256_5c78_3627_f741_263a80576e37 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { z } from 'astro:content';
import type { Loader } from "astro/loaders"

export interface PostLoaderConfig {
	url: string;
}

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(),
			});
		}
	};
}

Subdomains

Functions

Dependencies

  • astro:content
  • loaders

Frequently Asked Questions

What does post-loader.ts do?
post-loader.ts is a source file in the astro codebase, written in typescript. It belongs to the ContentCollections domain, DataLoaders subdomain.
What functions are defined in post-loader.ts?
post-loader.ts defines 1 function(s): loader.
What does post-loader.ts depend on?
post-loader.ts imports 2 module(s): astro:content, loaders.
Where is post-loader.ts in the architecture?
post-loader.ts is located at packages/astro/e2e/fixtures/cloudflare/src/loaders/post-loader.ts (domain: ContentCollections, subdomain: DataLoaders, directory: packages/astro/e2e/fixtures/cloudflare/src/loaders).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free