Skip to content

Commit 4c7527b

Browse files
author
stlc-bot
committed
feat(sitemap): add subdomain discovery
Stainless-Generated-From: 46e084a
1 parent f6aae1d commit 4c7527b

5 files changed

Lines changed: 30 additions & 3 deletions

File tree

‎src/ServiceContracts/WebContract.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ public function webScrapeMd(
405405
*
406406
* @param string $domain Domain to build a sitemap for
407407
* @param array<string,string> $headers Optional outbound HTTP headers forwarded only to the target URL, sent as deep-object query params such as headers[X-Custom]=value. When provided, caching is bypassed: the result is neither read from nor written to cache.
408+
* @param bool $includeSubdomains When true, discover and include public pages and sitemaps on subdomains of the requested domain. Defaults to false.
408409
* @param int $maxLinks Maximum number of links to return from the sitemap crawl. Defaults to 10,000. Minimum is 1, maximum is 100,000.
409410
* @param string $search Optional search phrase. When provided, the crawled sitemap is filtered to the pages whose URLs are about that phrase, most relevant first, and the request costs 2 credits instead of 1.
410411
* @param string $sitemapURL Optional explicit sitemap URL. When provided, exactly this sitemap is crawled instead of discovering the domain's sitemaps.
@@ -419,6 +420,7 @@ public function webScrapeMd(
419420
public function webScrapeSitemap(
420421
string $domain,
421422
?array $headers = null,
423+
bool $includeSubdomains = false,
422424
int $maxLinks = 10000,
423425
?string $search = null,
424426
?string $sitemapURL = null,

‎src/Services/WebRawService.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,11 +532,12 @@ public function webScrapeMd(
532532
/**
533533
* @api
534534
*
535-
* Crawl an entire website's sitemap and return all discovered page URLs. Pass `search` to have the crawled sitemap filtered down to the pages about a phrase (for example `pricing and plans` or `api authentication docs`), most relevant first — a searched crawl scans the whole sitemap and costs 2 credits instead of 1.
535+
* Crawl an entire website's sitemap and return all discovered page URLs. Set `includeSubdomains=true` to also discover public pages and sitemaps on child hosts such as `docs.example.com` or `brand.example.com`. Pass `search` to have the discovered URLs filtered down to the pages about a phrase (for example `pricing and plans` or `api authentication docs`), most relevant first — a searched crawl scans the whole sitemap and costs 2 credits instead of 1.
536536
*
537537
* @param array{
538538
* domain: string,
539539
* headers?: array<string,string>,
540+
* includeSubdomains?: bool,
540541
* maxLinks?: int,
541542
* search?: string,
542543
* sitemapURL?: string,

‎src/Services/WebService.php‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,10 +677,11 @@ public function webScrapeMd(
677677
/**
678678
* @api
679679
*
680-
* Crawl an entire website's sitemap and return all discovered page URLs. Pass `search` to have the crawled sitemap filtered down to the pages about a phrase (for example `pricing and plans` or `api authentication docs`), most relevant first — a searched crawl scans the whole sitemap and costs 2 credits instead of 1.
680+
* Crawl an entire website's sitemap and return all discovered page URLs. Set `includeSubdomains=true` to also discover public pages and sitemaps on child hosts such as `docs.example.com` or `brand.example.com`. Pass `search` to have the discovered URLs filtered down to the pages about a phrase (for example `pricing and plans` or `api authentication docs`), most relevant first — a searched crawl scans the whole sitemap and costs 2 credits instead of 1.
681681
*
682682
* @param string $domain Domain to build a sitemap for
683683
* @param array<string,string> $headers Optional outbound HTTP headers forwarded only to the target URL, sent as deep-object query params such as headers[X-Custom]=value. When provided, caching is bypassed: the result is neither read from nor written to cache.
684+
* @param bool $includeSubdomains When true, discover and include public pages and sitemaps on subdomains of the requested domain. Defaults to false.
684685
* @param int $maxLinks Maximum number of links to return from the sitemap crawl. Defaults to 10,000. Minimum is 1, maximum is 100,000.
685686
* @param string $search Optional search phrase. When provided, the crawled sitemap is filtered to the pages whose URLs are about that phrase, most relevant first, and the request costs 2 credits instead of 1.
686687
* @param string $sitemapURL Optional explicit sitemap URL. When provided, exactly this sitemap is crawled instead of discovering the domain's sitemaps.
@@ -695,6 +696,7 @@ public function webScrapeMd(
695696
public function webScrapeSitemap(
696697
string $domain,
697698
?array $headers = null,
699+
bool $includeSubdomains = false,
698700
int $maxLinks = 10000,
699701
?string $search = null,
700702
?string $sitemapURL = null,
@@ -708,6 +710,7 @@ public function webScrapeSitemap(
708710
[
709711
'domain' => $domain,
710712
'headers' => $headers,
713+
'includeSubdomains' => $includeSubdomains,
711714
'maxLinks' => $maxLinks,
712715
'search' => $search,
713716
'sitemapURL' => $sitemapURL,

‎src/Web/WebWebScrapeSitemapParams.php‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
use ContextDev\Web\WebWebScrapeSitemapParams\Zdr;
1313

1414
/**
15-
* Crawl an entire website's sitemap and return all discovered page URLs. Pass `search` to have the crawled sitemap filtered down to the pages about a phrase (for example `pricing and plans` or `api authentication docs`), most relevant first — a searched crawl scans the whole sitemap and costs 2 credits instead of 1.
15+
* Crawl an entire website's sitemap and return all discovered page URLs. Set `includeSubdomains=true` to also discover public pages and sitemaps on child hosts such as `docs.example.com` or `brand.example.com`. Pass `search` to have the discovered URLs filtered down to the pages about a phrase (for example `pricing and plans` or `api authentication docs`), most relevant first — a searched crawl scans the whole sitemap and costs 2 credits instead of 1.
1616
*
1717
* @see ContextDev\Services\WebService::webScrapeSitemap()
1818
*
1919
* @phpstan-type WebWebScrapeSitemapParamsShape = array{
2020
* domain: string,
2121
* headers?: array<string,string>|null,
22+
* includeSubdomains?: bool|null,
2223
* maxLinks?: int|null,
2324
* search?: string|null,
2425
* sitemapURL?: string|null,
@@ -48,6 +49,12 @@ final class WebWebScrapeSitemapParams implements BaseModel
4849
#[Optional(map: 'string')]
4950
public ?array $headers;
5051

52+
/**
53+
* When true, discover and include public pages and sitemaps on subdomains of the requested domain. Defaults to false.
54+
*/
55+
#[Optional]
56+
public ?bool $includeSubdomains;
57+
5158
/**
5259
* Maximum number of links to return from the sitemap crawl. Defaults to 10,000. Minimum is 1, maximum is 100,000.
5360
*/
@@ -125,6 +132,7 @@ public function __construct()
125132
public static function with(
126133
string $domain,
127134
?array $headers = null,
135+
?bool $includeSubdomains = null,
128136
?int $maxLinks = null,
129137
?string $search = null,
130138
?string $sitemapURL = null,
@@ -138,6 +146,7 @@ public static function with(
138146
$self['domain'] = $domain;
139147

140148
null !== $headers && $self['headers'] = $headers;
149+
null !== $includeSubdomains && $self['includeSubdomains'] = $includeSubdomains;
141150
null !== $maxLinks && $self['maxLinks'] = $maxLinks;
142151
null !== $search && $self['search'] = $search;
143152
null !== $sitemapURL && $self['sitemapURL'] = $sitemapURL;
@@ -173,6 +182,17 @@ public function withHeaders(array $headers): self
173182
return $self;
174183
}
175184

185+
/**
186+
* When true, discover and include public pages and sitemaps on subdomains of the requested domain. Defaults to false.
187+
*/
188+
public function withIncludeSubdomains(bool $includeSubdomains): self
189+
{
190+
$self = clone $this;
191+
$self['includeSubdomains'] = $includeSubdomains;
192+
193+
return $self;
194+
}
195+
176196
/**
177197
* Maximum number of links to return from the sitemap crawl. Defaults to 10,000. Minimum is 1, maximum is 100,000.
178198
*/

‎tests/Services/WebTest.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ public function testWebScrapeSitemapWithOptionalParams(): void
412412
$result = $this->client->web->webScrapeSitemap(
413413
domain: 'xxx',
414414
headers: ['foo' => 'J!'],
415+
includeSubdomains: true,
415416
maxLinks: 1,
416417
search: 'help center and troubleshooting articles',
417418
sitemapURL: 'https://example.com',

0 commit comments

Comments
 (0)