Repository: withastro/astro
File: packages/astro/src/content/content-layer.ts (TypeScript)

Code before:
		collectionName: string;
		loaderName: string;
		parseData: LoaderContext['parseData'];
		refreshContextData?: Record<string, unknown>;
	}): Promise<LoaderContext> {
		return {
			collection: collectionName,
			store: this.#store.scopedStore(collectionName),
			meta: this.#store.metaStore(collectionName),
			logger: this.#logger.forkIntegrationLogger(loaderName),
			config: this.#settings.config,
			parseData,
			renderMarkdown: this.#processMarkdown.bind(this),
			generateDigest: await this.#getGenerateDigest(),
			watcher: this.#watcher,
			refreshContextData,
			entryTypes: getEntryConfigByExtMap([
				...this.#settings.contentEntryTypes,
				...this.#settings.dataEntryTypes,
			] as Array<ContentEntryType>),
		};
	}

	async #processMarkdown(
		content: string,
		options?: MarkdownProcessorRenderOptions,
	): Promise<RenderedContent> {
		this.#markdownProcessor ??= await createMarkdownProcessor(this.#settings.config.markdown);
		const { code, metadata } = await this.#markdownProcessor.render(content, options);
		return {
			html: code,
			metadata,
		};
	}

	/**
	 * Enqueues a sync job that runs the `load()` method of each collection's loader, which will load the data and save it in the data store.
	 * The loader itself is responsible for deciding whether this will clear and reload the full collection, or
	 * perform an incremental update. After the data is loaded, the data store is written to disk. Jobs are queued,
	 * so that only one sync can run at a time. The function returns a promise that resolves when this sync job is complete.
	 */

	sync(options: RefreshContentOptions = {}): Promise<void> {
		return this.#queue.add(() => this.#doSync(options));
	}

	async #doSync(options: RefreshContentOptions) {
		let contentConfig = globalContentConfigObserver.get();
		const logger = this.#logger.forkIntegrationLogger('content');

		if (contentConfig?.status === 'loading') {

Review comment (suggestion):
I'm not sure we should expose the [options](https://github.com/withastro/astro/blob/f5f33f3db51c5c8e66b0edb267353326d7f59e00/packages/markdown/remark/src/types.ts#L82)? `fileURL` is internal and i'm not sure `frontmatter` is relevant here. Maybe it makes more sense to omit it and add it if people request it

Code after:
	}): Promise<LoaderContext> {
		return {
			collection: collectionName,
			store: this.#store.scopedStore(collectionName),
			meta: this.#store.metaStore(collectionName),
			logger: this.#logger.forkIntegrationLogger(loaderName),
			config: this.#settings.config,
			parseData,
			renderMarkdown: this.#processMarkdown.bind(this),
			generateDigest: await this.#getGenerateDigest(),
			watcher: this.#watcher,
			refreshContextData,
			entryTypes: getEntryConfigByExtMap([
				...this.#settings.contentEntryTypes,
				...this.#settings.dataEntryTypes,
			] as Array<ContentEntryType>),
		};
	}

	async #processMarkdown(content: string): Promise<RenderedContent> {
		this.#markdownProcessor ??= await createMarkdownProcessor(this.#settings.config.markdown);
		const { code, metadata } = await this.#markdownProcessor.render(content);
		return {
			html: code,
			metadata,
		};
	}

	/**
	 * Enqueues a sync job that runs the `load()` method of each collection's loader, which will load the data and save it in the data store.
	 * The loader itself is responsible for deciding whether this will clear and reload the full collection, or
	 * perform an incremental update. After the data is loaded, the data store is written to disk. Jobs are queued,
	 * so that only one sync can run at a time. The function returns a promise that resolves when this sync job is complete.
	 */

	sync(options: RefreshContentOptions = {}): Promise<void> {
		return this.#queue.add(() => this.#doSync(options));
	}

	async #doSync(options: RefreshContentOptions) {
		let contentConfig = globalContentConfigObserver.get();
		const logger = this.#logger.forkIntegrationLogger('content');

		if (contentConfig?.status === 'loading') {
			contentConfig = await Promise.race<ReturnType<ContentObservable['get']>>([
				new Promise((resolve) => {
					const unsub = globalContentConfigObserver.subscribe((ctx) => {
						unsub();
						resolve(ctx);
					});
				}),