generated from vormkracht10/laravel-package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve TooLongSentenceCheck and make Action trait
- Loading branch information
Showing
3 changed files
with
58 additions
and
72 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,32 @@ | ||
<?php | ||
|
||
namespace Vormkracht10\Seo\Traits; | ||
|
||
use Closure; | ||
use Readability\Readability; | ||
use Illuminate\Http\Client\Response; | ||
use Symfony\Component\DomCrawler\Crawler; | ||
|
||
trait Actions | ||
{ | ||
private function getTextContent(Response $response, Crawler $crawler): string | ||
{ | ||
$body = $response->body(); | ||
|
||
if ($this->useJavascript) { | ||
$body = $crawler->filter('body')->html(); | ||
} | ||
|
||
$readability = new Readability($body); | ||
|
||
$readability->init(); | ||
|
||
return $readability->getContent()->textContent; | ||
} | ||
|
||
private function extractPhrases(string $content): array | ||
{ | ||
// Get phrases seperate by new line, dot, exclamation mark or question mark | ||
return preg_split('/\n|\.|\!|\?/', $content); | ||
} | ||
} |