diff options
author | Freya Murphy <freya@freyacat.org> | 2024-09-25 12:02:27 -0400 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2024-09-25 12:02:27 -0400 |
commit | d5fed52363dbc30e702ba60e57acb2d6155826db (patch) | |
tree | bb67a9c752110f28ac611f532e09f21dd4e5c263 /src/web/_model | |
parent | fix ie6 support (diff) | |
download | website-d5fed52363dbc30e702ba60e57acb2d6155826db.tar.gz website-d5fed52363dbc30e702ba60e57acb2d6155826db.tar.bz2 website-d5fed52363dbc30e702ba60e57acb2d6155826db.zip |
ie6 blog post, click on blog images, prims.js syntax highlighting
Diffstat (limited to 'src/web/_model')
-rw-r--r-- | src/web/_model/blog.php | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/src/web/_model/blog.php b/src/web/_model/blog.php index 2890263..18a9e0e 100644 --- a/src/web/_model/blog.php +++ b/src/web/_model/blog.php @@ -36,17 +36,31 @@ class Blog_model extends Model { $data['desc'] = lang('blog_short_desc'); return $data; } + + private function update_images(string $md): string { + $pattern = '/<img src="(.*)" alt="(.*)".*>/'; + $base = $this->get_url(''); + + $replace = "<a href=\"{$base}\\1\">"; + $replace .= "<img src=\"{$base}\\1\" title=\"\\2\" alt=\"\\2\">"; + $replace .= "</a>"; + + $md = preg_replace($pattern, $replace, $md); + return $md; + } + /** * @param mixed $name * @return bool|<missing> */ - private function load_post($name): ?array { + private function render_post($name): ?array { $dir = ASSET_ROOT . '/blog'; $path = $dir . '/' . $name . '.md'; if(!file_exists($path)) { return NULL; } $md = $this->markdown->parse($path); + $md['content'] = $this->update_images($md['content']); return $md; } /** @@ -55,7 +69,7 @@ class Blog_model extends Model { */ public function get_post($name): ?array { $data = parent::get_base_data(); - $post = $this->load_post($name); + $post = $this->render_post($name); if (!$post) { return NULL; } @@ -64,16 +78,18 @@ class Blog_model extends Model { $data['post'] = $post; return $data; } + /** * @param mixed $name */ - private function load_writeup($name): ?array { + private function render_writeup($name): ?array { $dir = ASSET_ROOT . '/writeup'; $path = $dir . '/' . $name . '.md'; if(!file_exists($path)) { return NULL; } $md = $this->markdown->parse($path); + $md['content'] = $this->update_images($md['content']); return $md; } /** @@ -82,7 +98,7 @@ class Blog_model extends Model { */ public function get_writeup($name): ?array { $data = parent::get_base_data(); - $writeup = $this->load_writeup($name); + $writeup = $this->render_writeup($name); if (!$writeup) { return NULL; } |