Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/commands/scrape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
} from '../types/scrape';
import { getClient } from '../utils/client';
import { handleScrapeOutput } from '../utils/output';
import { getOrigin } from '../utils/url';
import { executeMap } from './map';
import { getStatus } from './status';

Expand Down Expand Up @@ -400,10 +401,12 @@ export async function handleAllScrapeCommand(
const fs = await import('fs');
const path = await import('path');

process.stderr.write(`Mapping ${siteUrl}...\n`);
// Map from origin so non-root URLs (e.g. pasted subpage) work reliably
const mapUrl = getOrigin(siteUrl);
process.stderr.write(`Mapping ${mapUrl}...\n`);

const mapResult = await executeMap({
urlOrJobId: siteUrl,
urlOrJobId: mapUrl,
apiKey: options.apiKey,
apiUrl: options.apiUrl,
search,
Expand All @@ -423,7 +426,7 @@ export async function handleAllScrapeCommand(
process.exit(1);
}

process.stderr.write(`Found ${totalFound} pages on ${siteUrl}\n`);
process.stderr.write(`Found ${totalFound} pages on ${mapUrl}\n`);

// Detect if user passed any explicit flags (non-interactive mode)
const hasExplicitFlags =
Expand Down
13 changes: 13 additions & 0 deletions src/utils/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,16 @@ export function normalizeUrl(url: string): string {
}
return `https://${url}`;
}

/**
* Get the origin (scheme + host) from a URL.
* Use for map operations when a non-root URL is passed - mapping works best from the site root.
*/
export function getOrigin(url: string): string {
try {
const parsed = new URL(normalizeUrl(url));
return `${parsed.protocol}//${parsed.host}`;
} catch {
return url;
}
}