Skip to content

Commit

Permalink
add setMaximumCrawlCount
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Nov 3, 2017
1 parent c3dfe80 commit 698260a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

All notable changes to `laravel-sitemap` will be documented in this file

## 3.3.0 - 2017-11-03
- add `setMaximumCrawlCount`

## 3.2.2 - 2017-10-19
- fix custom profiles

Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,19 @@ SitemapGenerator::create('https://example.com')
->writeToFile($sitemapPath);
```

#### Limiting the amount of pages crawled

You can limit the amount of pages crawled by calling `setMaximumCrawlCount`

```php
use Spatie\Sitemap\SitemapGenerator;
use Spatie\Crawler\Url;

SitemapGenerator::create('https://example.com')
->setMaximumCrawlCount(500) // only the 500 first pages will be crawled
...
```

#### Executing Javascript


Expand Down
13 changes: 13 additions & 0 deletions src/SitemapGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class SitemapGenerator
/** @var int */
protected $concurrency = 10;

/** @var int|null */
protected $maximumCrawlCount = null;

/**
* @param string $urlToBeCrawled
*
Expand All @@ -56,6 +59,11 @@ public function setConcurrency(int $concurrency)
$this->concurrency = $concurrency;
}

public function setMaximumCrawlCount(int $maximumCrawlCount)
{
$this->maximumCrawlCount = $maximumCrawlCount;
}

public function setUrl(string $urlToBeCrawled)
{
$this->urlToBeCrawled = $urlToBeCrawled;
Expand Down Expand Up @@ -83,10 +91,15 @@ public function getSitemap(): Sitemap
$this->crawler->executeJavaScript(config('sitemap.chrome_binary_path'));
}

if (! is_null($this->maximumCrawlCount)) {
$this->crawler->setMaximumCrawlCount($this->maximumCrawlCount);
}

$this->crawler
->setCrawlProfile($this->getCrawlProfile())
->setCrawlObserver($this->getCrawlObserver())
->setConcurrency($this->concurrency)

->startCrawling($this->urlToBeCrawled);

return $this->sitemap;
Expand Down

0 comments on commit 698260a

Please sign in to comment.