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
15 changes: 15 additions & 0 deletions src/__tests__/commands/scrape.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,21 @@ describe('executeScrape', () => {
excludeTags: ['nav'],
});
});

it('should include maxAge parameter when provided', async () => {
const mockResponse = { markdown: '# Test' };
mockClient.scrape.mockResolvedValue(mockResponse);

await executeScrape({
url: 'https://example.com',
maxAge: 3600,
});

expect(mockClient.scrape).toHaveBeenCalledWith('https://example.com', {
formats: ['markdown'],
maxAge: 3600,
});
});
});

describe('Response handling', () => {
Expand Down
5 changes: 5 additions & 0 deletions src/commands/scrape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export async function executeScrape(
waitFor?: number;
includeTags?: string[];
excludeTags?: string[];
maxAge?: number;
} = {
formats,
};
Expand All @@ -96,6 +97,10 @@ export async function executeScrape(
scrapeParams.excludeTags = options.excludeTags;
}

if (options.maxAge !== undefined) {
scrapeParams.maxAge = options.maxAge;
}

// Execute scrape with timing - only wrap the scrape call in try-catch
const requestStartTime = Date.now();

Expand Down
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ function createScrapeCommand(): Command {
'Show request timing and other useful information',
false
)
.option(
'--max-age <milliseconds>',
'Maximum age of cached content in milliseconds',
parseInt
)
.action(async (positionalUrl, positionalFormats, options) => {
// Use positional URL if provided, otherwise use --url option
const url = positionalUrl || options.url;
Expand Down
2 changes: 2 additions & 0 deletions src/types/scrape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export interface ScrapeOptions {
json?: boolean;
/** Show request timing and other useful information */
timing?: boolean;
/** Maximum age of cached content in milliseconds (API-level caching) */
maxAge?: number;
}

export interface ScrapeResult {
Expand Down
1 change: 1 addition & 0 deletions src/utils/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,6 @@ export function parseScrapeOptions(options: any): ScrapeOptions {
pretty: options.pretty,
json: options.json,
timing: options.timing,
maxAge: options.maxAge,
};
}