From d5fed52363dbc30e702ba60e57acb2d6155826db Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Wed, 25 Sep 2024 12:02:27 -0400 Subject: ie6 blog post, click on blog images, prims.js syntax highlighting --- src/web/_model/blog.php | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'src/web/_model/blog.php') 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 = '/(.*)/'; + $base = $this->get_url(''); + + $replace = ""; + $replace .= "\"\\2\""; + $replace .= ""; + + $md = preg_replace($pattern, $replace, $md); + return $md; + } + /** * @param mixed $name * @return bool| */ - 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; } -- cgit v1.2.3-freya