Skip to content

Commit

Permalink
Update GenerateToc.php
Browse files Browse the repository at this point in the history
  • Loading branch information
phpsa committed Sep 15, 2020
1 parent bc302bf commit eaba82c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Listeners/GenerateToc.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Njed\Toc\Listeners;

use Njed\Toc\Extensions\CommonMark\GenerateTocExtension;
use Statamic\Events\Data\EntrySaving;
use Statamic\Events\EntrySaving;
use Statamic\Facades\Markdown;

class GenerateToc
Expand All @@ -16,8 +16,8 @@ class GenerateToc
*/
public function handle(EntrySaving $event)
{
if (collect(config('toc.collections'))->keys()->contains($event->data->collectionHandle())) {
$content = $event->data->value(config("toc.collections.{$event->data->collectionHandle()}", 'content'));
if (collect(config('toc.collections'))->keys()->contains($event->entry->collectionHandle())) {
$content = $event->entry->value(config("toc.collections.{$event->entry->collectionHandle()}", 'content'));

Markdown::extend('default', function ($parser) {
return $parser
Expand All @@ -26,7 +26,7 @@ public function handle(EntrySaving $event)

$headings = Markdown::parse($content);

$event->data->set('table_of_contents', trim($headings));
$event->entry->set('table_of_contents', trim($headings));
}
}
}

0 comments on commit eaba82c

Please sign in to comment.