Skip to content

Commit e2b149e

Browse files
fix: sitemap/llms-txt recursive crawling, Next.js contentDir fallback & OG image
- Exclude public/, dist/, .next/, .nuxt/ etc from sitemap and llms-txt crawlers - Next.js contentDir no longer falls back to project root - Added OG social sharing image for aeojs.org Amp-Thread-ID: https://ampcode.com/threads/T-019ce8b2-11cf-7124-bb47-e6d2cfebdc7a Co-authored-by: Amp <amp@ampcode.com>
1 parent e8381fc commit e2b149e

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

src/core/llms-txt.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ function collectMarkdownFiles(dir: string, base: string = dir): MarkdownFile[] {
1313
const fullPath = join(dir, entry);
1414
const stat = statSync(fullPath);
1515

16-
if (stat.isDirectory() && !entry.startsWith('.') && entry !== 'node_modules') {
16+
const SKIP_DIRS = new Set(['node_modules', 'public', 'dist', '.next', '.nuxt', '.output', '.open-next', 'coverage', '__tests__', '__mocks__']);
17+
if (stat.isDirectory() && !entry.startsWith('.') && !SKIP_DIRS.has(entry)) {
1718
files.push(...collectMarkdownFiles(fullPath, base));
1819
} else if (stat.isFile() && (extname(entry) === '.md' || extname(entry) === '.mdx')) {
1920
const content = readFileSync(fullPath, 'utf-8');

src/core/sitemap.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ function collectUrls(dir: string, config: ResolvedAeoConfig, base: string = dir)
1212
const fullPath = join(dir, entry);
1313
const stat = statSync(fullPath);
1414

15-
if (stat.isDirectory() && !entry.startsWith('.') && entry !== 'node_modules') {
15+
const SKIP_DIRS = new Set(['node_modules', 'public', 'dist', '.next', '.nuxt', '.output', '.open-next', 'coverage', '__tests__', '__mocks__']);
16+
if (stat.isDirectory() && !entry.startsWith('.') && !SKIP_DIRS.has(entry)) {
1617
urls.push(...collectUrls(fullPath, config, base));
1718
} else if (stat.isFile() && (extname(entry) === '.md' || extname(entry) === '.mdx' || extname(entry) === '.html')) {
1819
const relativePath = relative(base, fullPath);

src/plugins/next.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,11 @@ export function withAeo(nextConfig: NextAeoConfig = {}): Record<string, any> {
9999
}
100100
}
101101

102-
// Resolve contentDir: prefer user-specified, then src/, then project root
102+
// Resolve contentDir: prefer user-specified, then known content dirs, then src/
103+
// Never fall back to project root — it causes recursive crawling of public/, .next/, etc.
103104
const contentDir = aeoOptions.contentDir
104-
|| (existsSync(join(projectRoot, 'src')) ? join(projectRoot, 'src') : projectRoot);
105+
|| [join(projectRoot, 'content'), join(projectRoot, 'docs'), join(projectRoot, 'src')].find(d => existsSync(d))
106+
|| join(projectRoot, 'content');
105107

106108
const resolvedConfig = resolveConfig({
107109
...aeoOptions,
@@ -247,7 +249,8 @@ export async function postBuild(config: AeoConfig = {}): Promise<void> {
247249
}
248250

249251
const contentDir = config.contentDir
250-
|| (existsSync(join(projectRoot, 'src')) ? join(projectRoot, 'src') : projectRoot);
252+
|| [join(projectRoot, 'content'), join(projectRoot, 'docs'), join(projectRoot, 'src')].find(d => existsSync(d))
253+
|| join(projectRoot, 'content');
251254

252255
const resolvedConfig = resolveConfig({
253256
...config,

website/public/og.png

41.7 KB
Loading

0 commit comments

Comments
 (0)