Completed LinkBundleCreator
This commit is contained in:
parent
2100fec73f
commit
c8ccebfebc
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
use App\Classes\Bundle;
|
use App\Classes\Bundle;
|
||||||
use App\Exceptions\BundleAlreadyExists;
|
use App\Exceptions\BundleAlreadyExists;
|
||||||
|
use App\Services\Browser;
|
||||||
use Illuminate\Filesystem\FilesystemAdapter;
|
use Illuminate\Filesystem\FilesystemAdapter;
|
||||||
|
|
||||||
use function Laravel\Prompts\text;
|
use function Laravel\Prompts\text;
|
||||||
|
@ -22,11 +23,10 @@ public function __construct(protected ?array $data, protected FilesystemAdapter
|
||||||
*/
|
*/
|
||||||
public function createBundle(): string
|
public function createBundle(): string
|
||||||
{
|
{
|
||||||
$url = $this->data['url'];
|
$url = $this->data['url'];
|
||||||
$hash = md5($url);
|
$hash = md5($url);
|
||||||
$date = now();
|
$date = now();
|
||||||
$path = sprintf('%s/%s/%s', static::$section, $date->format('Y/m/d'), $hash);
|
$path = sprintf('%s/%s/%s', static::$section, $date->format('Y/m/d'), $hash);
|
||||||
|
|
||||||
$bundle = new Bundle($path, $this->disk);
|
$bundle = new Bundle($path, $this->disk);
|
||||||
|
|
||||||
if ($bundle->exists()) {
|
if ($bundle->exists()) {
|
||||||
|
@ -35,11 +35,26 @@ public function createBundle(): string
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$bundle->markdown()->set('');
|
$browser = new Browser($url);
|
||||||
// $bundle->metadata()->set([
|
|
||||||
// 'title' => $title,
|
$browser->go();
|
||||||
// 'date' => $date->toIso8601String(),
|
|
||||||
// ]);
|
$screenshot = $browser->getScreenshot();
|
||||||
|
$title = $browser->getTitle();
|
||||||
|
$description = $browser->getDescription();
|
||||||
|
|
||||||
|
$ref = $bundle->attachments('images')->addToHistory('screenshot', [
|
||||||
|
'contents' => $screenshot,
|
||||||
|
'filename' => 'screenshot.jpg',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$bundle->metadata()->set([
|
||||||
|
'title' => $title,
|
||||||
|
'date' => $date->toIso8601String(),
|
||||||
|
'cover' => $ref,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$bundle->markdown()->set('> ' . $description . "\n\n");
|
||||||
|
|
||||||
$bundle->save();
|
$bundle->save();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user