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 ++++++++++++++++++++---- src/web/_views/head.php | 3 +++ src/web/config/style.php | 6 +++++- src/web/core/core.php | 11 +++++++++++ src/web/core/model.php | 11 +++++++++-- 5 files changed, 48 insertions(+), 7 deletions(-) (limited to 'src/web') 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; } diff --git a/src/web/_views/head.php b/src/web/_views/head.php index 27613ff..100e4a0 100644 --- a/src/web/_views/head.php +++ b/src/web/_views/head.php @@ -27,3 +27,6 @@ embed_css($file); ?> + link_js($file); + ?> diff --git a/src/web/config/style.php b/src/web/config/style.php index 10b2ba1..33a0f8b 100644 --- a/src/web/config/style.php +++ b/src/web/config/style.php @@ -1,5 +1,9 @@ '; + } + /** * Loads a css html link * @param string $path - the path to the css file diff --git a/src/web/core/model.php b/src/web/core/model.php index 8e105da..c57fd5c 100644 --- a/src/web/core/model.php +++ b/src/web/core/model.php @@ -8,8 +8,10 @@ abstract class Model extends Component { $data['title'] = lang('first_name'); $data['desc'] = lang('default_short_desc'); $data['css'] = array(); + $data['js'] = array(); $style = $GLOBALS['style']; + $js = $GLOBALS['js']; if (!$app) $app = CONTEXT['app']; @@ -18,11 +20,16 @@ abstract class Model extends Component { $css = $style[$app]; if (!is_array($css)) $css = array($css); - else - $css = $style['app']; $data['css'] = $css; } + if (isset($js[$app])) { + $js = $js[$app]; + if (!is_array($js)) + $js = array($js); + $data['js'] = $js; + } + return $data; } -- cgit v1.2.3-freya