glob() — astro Function Reference
Architecture documentation for the glob() function in glob.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD dad9d71c_4a14_b07e_4d93_8466d0ba52b2["glob()"] 6e7c310e_d293_0d26_5ed9_d09724209fd3["glob.ts"] dad9d71c_4a14_b07e_4d93_8466d0ba52b2 -->|defined in| 6e7c310e_d293_0d26_5ed9_d09724209fd3 d5a6d3a0_3ed6_da29_dad2_4da0193bd502["checkPrefix()"] dad9d71c_4a14_b07e_4d93_8466d0ba52b2 -->|calls| d5a6d3a0_3ed6_da29_dad2_4da0193bd502 dd677134_11b0_6bc3_acb9_69202bff1296["generateIdDefault()"] dad9d71c_4a14_b07e_4d93_8466d0ba52b2 -->|calls| dd677134_11b0_6bc3_acb9_69202bff1296 style dad9d71c_4a14_b07e_4d93_8466d0ba52b2 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/astro/src/content/loaders/glob.ts lines 77–372
export function glob(globOptions: GlobOptions & { [secretLegacyFlag]?: boolean }): Loader {
if (checkPrefix(globOptions.pattern, '../')) {
throw new Error(
'Glob patterns cannot start with `../`. Set the `base` option to a parent directory instead.',
);
}
if (checkPrefix(globOptions.pattern, '/')) {
throw new Error(
'Glob patterns cannot start with `/`. Set the `base` option to a parent directory or use a relative path instead.',
);
}
const isLegacy = !!globOptions[secretLegacyFlag];
const generateId =
globOptions?.generateId ?? ((opts: GenerateIdOptions) => generateIdDefault(opts, isLegacy));
const fileToIdMap = new Map<string, string>();
return {
name: 'glob-loader',
load: async ({
config,
collection,
logger,
watcher,
parseData,
store,
generateDigest,
entryTypes,
}) => {
const renderFunctionByContentType = new WeakMap<
ContentEntryType,
ContentEntryRenderFunction
>();
const untouchedEntries = new Set(store.keys());
async function syncData(
entry: string,
base: URL,
entryType?: ContentEntryType,
oldId?: string,
) {
if (!entryType) {
logger.warn(`No entry type found for ${entry}`);
return;
}
const fileUrl = new URL(encodeURI(entry), base);
const contents = await fs.readFile(fileUrl, 'utf-8').catch((err) => {
logger.error(`Error reading ${entry}: ${err.message}`);
return;
});
if (!contents && contents !== '') {
logger.warn(`No contents found for ${entry}`);
return;
}
const { body, data } = await entryType.getEntryInfo({
contents,
fileUrl,
});
const id = generateId({ entry, base, data });
if (oldId && oldId !== id) {
store.delete(oldId);
}
untouchedEntries.delete(id);
const existingEntry = store.get(id);
const digest = generateDigest(contents);
const filePath = fileURLToPath(fileUrl);
if (existingEntry && existingEntry.digest === digest && existingEntry.filePath) {
if (existingEntry.deferredRender) {
store.addModuleImport(existingEntry.filePath);
}
if (existingEntry.assetImports?.length) {
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does glob() do?
glob() is a function in the astro codebase, defined in packages/astro/src/content/loaders/glob.ts.
Where is glob() defined?
glob() is defined in packages/astro/src/content/loaders/glob.ts at line 77.
What does glob() call?
glob() calls 2 function(s): checkPrefix, generateIdDefault.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free