Improved rendering and deploying times
This commit is contained in:
parent
a95c0900e7
commit
7726b3c3e0
|
@ -11,6 +11,7 @@
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Filesystem\FilesystemAdapter;
|
use Illuminate\Filesystem\FilesystemAdapter;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use League\Flysystem\StorageAttributes;
|
use League\Flysystem\StorageAttributes;
|
||||||
|
|
||||||
|
@ -176,9 +177,14 @@ public function load(): void
|
||||||
*/
|
*/
|
||||||
public function save(): void
|
public function save(): void
|
||||||
{
|
{
|
||||||
$this->saveAttachments();
|
if (
|
||||||
|
$this->saveAttachments()
|
||||||
|
|| $this->saveMetadata()
|
||||||
|
|| $this->saveMarkdown()
|
||||||
|
) {
|
||||||
|
$this->metadata()->set('lastModified', now()->toIso8601String());
|
||||||
$this->saveMetadata();
|
$this->saveMetadata();
|
||||||
$this->saveMarkdown();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -195,9 +201,23 @@ public function repair(): void
|
||||||
|
|
||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
$renderer = BundleRenderer::getBundleRendererFor($this);
|
$lastModified = Carbon::parse($this->metadata()->get('lastModified', '1970-01-02'));
|
||||||
|
$lastRendered = Carbon::parse($this->metadata()->get('lastRendered', '1970-01-01'));
|
||||||
|
$cacheKey = sprintf('render_%s', Str::slug($this->getPath()));
|
||||||
|
|
||||||
return $renderer->render();
|
if ($lastRendered->gt($lastModified) && Cache::has($cacheKey)) {
|
||||||
|
return Cache::get($cacheKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
$renderer = BundleRenderer::getBundleRendererFor($this);
|
||||||
|
$result = $renderer->render();
|
||||||
|
|
||||||
|
$this->metadata()->set('lastRendered', now()->toIso8601String());
|
||||||
|
$this->metadata()->save();
|
||||||
|
|
||||||
|
Cache::put($cacheKey, $result, now()->addMonth());
|
||||||
|
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function renderCard()
|
public function renderCard()
|
||||||
|
|
|
@ -54,13 +54,19 @@ private function loadAttachments()
|
||||||
/**
|
/**
|
||||||
* Save all attachments files that needs to be
|
* Save all attachments files that needs to be
|
||||||
*/
|
*/
|
||||||
private function saveAttachments()
|
private function saveAttachments(): bool
|
||||||
{
|
{
|
||||||
|
$allSaved = true;
|
||||||
|
|
||||||
foreach ($this->attachmentsManagers as $manager) {
|
foreach ($this->attachmentsManagers as $manager) {
|
||||||
$manager->save();
|
if (!$manager->save()) {
|
||||||
|
$allSaved = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $allSaved;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Repair all attachments files that needs to be
|
* Repair all attachments files that needs to be
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -45,11 +45,17 @@ private function loadMarkdown()
|
||||||
*/
|
*/
|
||||||
private function saveMarkdown()
|
private function saveMarkdown()
|
||||||
{
|
{
|
||||||
|
$allSaved = true;
|
||||||
|
|
||||||
foreach ($this->markdownManagers as $manager) {
|
foreach ($this->markdownManagers as $manager) {
|
||||||
$manager->save();
|
if (!$manager->save()) {
|
||||||
|
$allSaved = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $allSaved;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lint all markdowns in the bundle
|
* Lint all markdowns in the bundle
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -43,10 +43,16 @@ private function loadMetadata()
|
||||||
/**
|
/**
|
||||||
* Save all metadata files that needs to be
|
* Save all metadata files that needs to be
|
||||||
*/
|
*/
|
||||||
private function saveMetadata()
|
private function saveMetadata(): bool
|
||||||
{
|
{
|
||||||
|
$allSaved = true;
|
||||||
|
|
||||||
foreach ($this->metadataManagers as $manager) {
|
foreach ($this->metadataManagers as $manager) {
|
||||||
$manager->save();
|
if (!$manager->save()) {
|
||||||
|
$allSaved = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $allSaved;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ class Repair extends Command
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'bundle:repair { path? : Specific bundle to repair }';
|
protected $signature = 'bundle:repair { --r|recursive : Also repair sub-bundles } { path? : Specific bundle to repair }';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
|
@ -30,7 +30,12 @@ public function handle()
|
||||||
{
|
{
|
||||||
$disk = Storage::disk(env('CONTENT_DISK'));
|
$disk = Storage::disk(env('CONTENT_DISK'));
|
||||||
$path = $this->argument('path') ?? '/';
|
$path = $this->argument('path') ?? '/';
|
||||||
|
|
||||||
|
if ($this->option('recursive')) {
|
||||||
$bundles = Bundle::findBundles($disk, $path, true);
|
$bundles = Bundle::findBundles($disk, $path, true);
|
||||||
|
} else {
|
||||||
|
$bundles = [new Bundle($path, $disk)];
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($bundles as $bundle) {
|
foreach ($bundles as $bundle) {
|
||||||
$this->output->write(sprintf('Repairing %s... ', $bundle->getPath()));
|
$this->output->write(sprintf('Repairing %s... ', $bundle->getPath()));
|
||||||
|
|
|
@ -20,7 +20,7 @@ public function render()
|
||||||
data_set($this->viewData, 'showToc', true);
|
data_set($this->viewData, 'showToc', true);
|
||||||
data_set($this->viewData, 'dossier', $dossier);
|
data_set($this->viewData, 'dossier', $dossier);
|
||||||
|
|
||||||
return [$this->bundle->getPath() => view('article', $this->viewData)];
|
return [$this->bundle->getPath() => (string) view('article', $this->viewData)];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -27,7 +27,7 @@ public function render()
|
||||||
|
|
||||||
data_set($this->viewData, 'relations', $relations);
|
data_set($this->viewData, 'relations', $relations);
|
||||||
|
|
||||||
return [$this->bundle->getPath() => view('term', $this->viewData)];
|
return [$this->bundle->getPath() => (string) view('term', $this->viewData)];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue
Block a user