remark-collect-images.ts — astro Source File
Architecture documentation for remark-collect-images.ts, a typescript file in the astro codebase. 6 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 4b71d521_90eb_5c80_622a_45eb4293c988["remark-collect-images.ts"] 2ebb1f90_a903_fafc_eb9b_ce29b5c61608["./types.js"] 4b71d521_90eb_5c80_622a_45eb4293c988 --> 2ebb1f90_a903_fafc_eb9b_ce29b5c61608 21f9daf1_9979_0313_afee_bbb8465c9f69["remote"] 4b71d521_90eb_5c80_622a_45eb4293c988 --> 21f9daf1_9979_0313_afee_bbb8465c9f69 422b029d_9a4f_c23d_7f7e_340358545db4["mdast"] 4b71d521_90eb_5c80_622a_45eb4293c988 --> 422b029d_9a4f_c23d_7f7e_340358545db4 5fe5de9f_89e1_7568_3154_1c0b094aa597["mdast-util-definitions"] 4b71d521_90eb_5c80_622a_45eb4293c988 --> 5fe5de9f_89e1_7568_3154_1c0b094aa597 d7b51bf7_4a46_1479_0cea_09e174fc7c48["unist-util-visit"] 4b71d521_90eb_5c80_622a_45eb4293c988 --> d7b51bf7_4a46_1479_0cea_09e174fc7c48 b909a1d2_5b96_acd8_d198_1f106f44e2c3["vfile"] 4b71d521_90eb_5c80_622a_45eb4293c988 --> b909a1d2_5b96_acd8_d198_1f106f44e2c3 style 4b71d521_90eb_5c80_622a_45eb4293c988 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import { isRemoteAllowed } from '@astrojs/internal-helpers/remote';
import type { Root } from 'mdast';
import { definitions } from 'mdast-util-definitions';
import { visit } from 'unist-util-visit';
import type { VFile } from 'vfile';
import type { AstroMarkdownProcessorOptions } from './types.js';
export function remarkCollectImages(opts: AstroMarkdownProcessorOptions['image']) {
const domains = opts?.domains ?? [];
const remotePatterns = opts?.remotePatterns ?? [];
return function (tree: Root, vfile: VFile) {
if (typeof vfile?.path !== 'string') return;
const definition = definitions(tree);
const localImagePaths = new Set<string>();
const remoteImagePaths = new Set<string>();
visit(tree, (node) => {
let url: string | undefined;
if (node.type === 'image') {
url = decodeURI(node.url);
} else if (node.type === 'imageReference') {
const imageDefinition = definition(node.identifier);
if (imageDefinition) {
url = decodeURI(imageDefinition.url);
}
}
if (!url) return;
if (URL.canParse(url)) {
if (isRemoteAllowed(url, { domains, remotePatterns })) {
remoteImagePaths.add(url);
}
} else if (!url.startsWith('/')) {
// If:
// + not a valid URL
// + AND not an absolute path
// Then it's a local image.
localImagePaths.add(url);
}
});
vfile.data.astro ??= {};
vfile.data.astro.localImagePaths = Array.from(localImagePaths);
vfile.data.astro.remoteImagePaths = Array.from(remoteImagePaths);
};
}
Domain
Subdomains
Functions
Dependencies
- ./types.js
- mdast
- mdast-util-definitions
- remote
- unist-util-visit
- vfile
Source
Frequently Asked Questions
What does remark-collect-images.ts do?
remark-collect-images.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, RenderingEngine subdomain.
What functions are defined in remark-collect-images.ts?
remark-collect-images.ts defines 1 function(s): remarkCollectImages.
What does remark-collect-images.ts depend on?
remark-collect-images.ts imports 6 module(s): ./types.js, mdast, mdast-util-definitions, remote, unist-util-visit, vfile.
Where is remark-collect-images.ts in the architecture?
remark-collect-images.ts is located at packages/markdown/remark/src/remark-collect-images.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/markdown/remark/src).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free