From eeb84c5be16ecca239adae9c851bc0f7db0875a1 Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Sat, 4 Mar 2023 01:46:45 +0300 Subject: blog: support ToC --- model/Post.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'model') diff --git a/model/Post.php b/model/Post.php index b0360ac..6f3f1ab 100644 --- a/model/Post.php +++ b/model/Post.php @@ -8,10 +8,12 @@ class Post extends Model { public string $title; public string $md; public string $html; + public string $tocHtml; public string $text; public int $ts; public int $updateTs; public bool $visible; + public bool $toc; public string $shortName; public function edit(array $data) { @@ -26,6 +28,10 @@ class Post extends Model { $data['text'] = markup::htmlToText($data['html']); } + if ((isset($data['toc']) && $data['toc']) || $this->toc) { + $data['toc_html'] = markup::toc($data['md']); + } + parent::edit($data); $this->updateImagePreviews(); } @@ -87,6 +93,10 @@ class Post extends Model { return $html; } + public function getToc(): ?string { + return $this->toc ? $this->tocHtml : null; + } + public function isUpdated(): bool { return $this->updateTs && $this->updateTs != $this->ts; } -- cgit v1.2.3