Skip to content

Commit

Permalink
Discard changes to packages/astro/src/content/utils.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
florian-lefebvre authored Sep 26, 2024
1 parent e598f36 commit affa84c
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 additions & 2 deletions packages/astro/src/content/utils.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { parseFrontmatter } from '@astrojs/markdown-remark';
import { slug as githubSlug } from 'github-slugger';
import fsMod from 'node:fs';
import path from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
import { parseFrontmatter } from '@astrojs/markdown-remark';
import { slug as githubSlug } from 'github-slugger';
import type { PluginContext } from 'rollup';
import type { ViteDevServer } from 'vite';
import xxhash from 'xxhash-wasm';
import { z } from 'zod';
import { AstroError, AstroErrorData, MarkdownError, errorMap } from '../core/errors/index.js';
import { isYAMLException } from '../core/errors/utils.js';
import type { Logger } from '../core/logger/core.js';
import { normalizePath } from '../core/viteUtils.js';
import type { AstroSettings } from '../types/astro.js';
import type { AstroConfig } from '../types/public/config.js';
Expand Down Expand Up @@ -281,6 +282,44 @@ export function getEntryConfigByExtMap<TEntryType extends ContentEntryType | Dat
return map;
}

export async function getSymlinkedContentCollections({
contentDir,
logger,
fs,
}: {
contentDir: URL;
logger: Logger;
fs: typeof fsMod;
}): Promise<Map<string, string>> {
const contentPaths = new Map<string, string>();
const contentDirPath = fileURLToPath(contentDir);
try {
if (!fs.existsSync(contentDirPath) || !fs.lstatSync(contentDirPath).isDirectory()) {
return contentPaths;
}
} catch {
// Ignore if there isn't a valid content directory
return contentPaths;
}
try {
const contentDirEntries = await fs.promises.readdir(contentDir, { withFileTypes: true });
for (const entry of contentDirEntries) {
if (entry.isSymbolicLink()) {
const entryPath = path.join(contentDirPath, entry.name);
const realPath = await fs.promises.realpath(entryPath);
contentPaths.set(normalizePath(realPath), entry.name);
}
}
} catch (e) {
logger.warn('content', `Error when reading content directory "${contentDir}"`);
logger.debug('content', e);
// If there's an error, return an empty map
return new Map<string, string>();
}

return contentPaths;
}

export function reverseSymlink({
entry,
symlinks,
Expand Down

0 comments on commit affa84c

Please sign in to comment.