generated from vormkracht10/laravel-package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dc04970
commit dfb57b2
Showing
9 changed files
with
190 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace Vormkracht10\LaravelStatic\Commands; | ||
|
||
use GuzzleHttp\RequestOptions; | ||
use Illuminate\Config\Repository; | ||
use Illuminate\Console\Command; | ||
use Spatie\Crawler\Crawler; | ||
use Spatie\Crawler\CrawlProfiles\CrawlInternalUrls; | ||
use Vormkracht10\LaravelStatic\Crawler\StaticCrawlObserver; | ||
use Vormkracht10\LaravelStatic\LaravelStatic; | ||
|
||
class StaticBuildCommand extends Command | ||
{ | ||
public $signature = 'static:build'; | ||
|
||
public $description = 'Build Static version'; | ||
|
||
protected Repository $config; | ||
|
||
protected LaravelStatic $static; | ||
|
||
public function __construct(Repository $config, LaravelStatic $static) | ||
{ | ||
parent::__construct(); | ||
|
||
$this->config = $config; | ||
$this->static = $static; | ||
} | ||
|
||
public function handle(): void | ||
{ | ||
if ($this->config->get('static.build.clear_before_start')) { | ||
$this->call(StaticClearCommand::class); | ||
} | ||
|
||
$bypassHeader = $this->config->get('static.build.bypass_header'); | ||
|
||
Crawler::create([ | ||
RequestOptions::VERIFY => ! app()->environment('local'), | ||
RequestOptions::ALLOW_REDIRECTS => true, | ||
RequestOptions::HEADERS => [ | ||
array_key_first($bypassHeader) => array_shift($bypassHeader), | ||
'User-Agent' => 'LaravelStatic/1.0', | ||
], | ||
]) | ||
->setCrawlObserver(new StaticCrawlObserver) | ||
->setCrawlProfile(new CrawlInternalUrls($this->config->get('app.url'))) | ||
->acceptNofollowLinks() | ||
->setConcurrency($this->config->get('static.build.concurrency')) | ||
->setDefaultScheme('https') | ||
// ->setParseableMimeTypes(['text/html', 'text/plain']) | ||
->startCrawling($this->config->get('app.url')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Vormkracht10\LaravelStatic\Console; | ||
|
||
use Illuminate\Console\Command; | ||
|
||
class Terminal extends Command | ||
{ | ||
protected $name = 'NONEXISTENT'; | ||
|
||
protected $hidden = true; | ||
|
||
public $outputSymfony; | ||
|
||
public $outputStyle; | ||
|
||
public function __construct($argInput = '') | ||
{ | ||
parent::__construct(); | ||
|
||
$this->input = new \Symfony\Component\Console\Input\StringInput($argInput); | ||
|
||
$this->outputSymfony = new \Symfony\Component\Console\Output\ConsoleOutput(); | ||
$this->outputStyle = new \Illuminate\Console\OutputStyle($this->input, $this->outputSymfony); | ||
|
||
$this->output = $this->outputStyle; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace Vormkracht10\LaravelStatic\Crawler; | ||
|
||
use GuzzleHttp\Exception\RequestException; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\UriInterface; | ||
use Spatie\Crawler\CrawlObservers\CrawlObserver; | ||
|
||
class StaticCrawlObserver extends CrawlObserver | ||
{ | ||
/** | ||
* Called when the crawler will crawl the url. | ||
* | ||
* @param \Psr\Http\Message\UriInterface $url | ||
*/ | ||
public function willCrawl(UriInterface $url): void | ||
{ | ||
// ... | ||
} | ||
|
||
/** | ||
* Called when the crawler has crawled the given url successfully. | ||
* | ||
* @param \Psr\Http\Message\UriInterface $url | ||
* @param \Psr\Http\Message\ResponseInterface $response | ||
* @param \Psr\Http\Message\UriInterface|null $foundOnUrl | ||
*/ | ||
public function crawled( | ||
UriInterface $url, | ||
ResponseInterface $response, | ||
?UriInterface $foundOnUrl = null | ||
): void { | ||
console()->info('✔ '.$url); | ||
} | ||
|
||
/** | ||
* Called when the crawler had a problem crawling the given url. | ||
* | ||
* @param \Psr\Http\Message\UriInterface $url | ||
* @param \GuzzleHttp\Exception\RequestException $requestException | ||
* @param \Psr\Http\Message\UriInterface|null $foundOnUrl | ||
*/ | ||
public function crawlFailed( | ||
UriInterface $url, | ||
RequestException $requestException, | ||
?UriInterface $foundOnUrl = null | ||
): void { | ||
console()->error('✘ '.$url); | ||
} | ||
|
||
/** | ||
* Called when the crawl has ended. | ||
*/ | ||
public function finishedCrawling(): void | ||
{ | ||
console()->info('✔ Static build completed'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters