Skip to content

Commit

Permalink
Create accessor to get live edit resources
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Nov 13, 2023
1 parent bfd3d3a commit 083dd8d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/realtime-compiler/src/Http/LiveEditController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Hyde\Hyde;
use Hyde\Markdown\Models\Markdown;
use Desilva\Microserve\JsonResponse;
use Illuminate\Support\Facades\Blade;
use Hyde\Pages\Concerns\BaseMarkdownPage;
use Symfony\Component\HttpKernel\Exception\HttpException;

Expand Down Expand Up @@ -56,4 +57,13 @@ public static function enabled(): bool
{
return config('hyde.server.live_edit', true);
}

public static function injectLiveEditScript(string $html): string
{
return str_replace('</body>', sprintf('%s</body>', Blade::render(file_get_contents(__DIR__.'/../../resources/live-edit.blade.php'), [
'styles' => file_get_contents(__DIR__.'/../../resources/live-edit.css'),
'scripts' => file_get_contents(__DIR__.'/../../resources/live-edit.js'),
'csrfToken' => self::generateCSRFToken(),
])), $html);
}
}

0 comments on commit 083dd8d

Please sign in to comment.