summaryrefslogtreecommitdiff
path: root/model/Post.php
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2023-03-04 01:46:45 +0300
committerEvgeny Zinoviev <me@ch1p.io>2023-03-04 01:46:45 +0300
commiteeb84c5be16ecca239adae9c851bc0f7db0875a1 (patch)
tree9aa1056e643212e4c6133d90f38a1966f0fa35ca /model/Post.php
parent917d2622aa5fe748c1cda914eae94c12be743c42 (diff)
blog: support ToC
Diffstat (limited to 'model/Post.php')
-rw-r--r--model/Post.php10
1 files changed, 10 insertions, 0 deletions
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;
}