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 | |
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')
-rw-r--r-- | src/web/_model/blog.php | 24 | ||||
-rw-r--r-- | src/web/_views/head.php | 3 | ||||
-rw-r--r-- | src/web/config/style.php | 6 | ||||
-rw-r--r-- | src/web/core/core.php | 11 | ||||
-rw-r--r-- | src/web/core/model.php | 11 |
5 files changed, 48 insertions, 7 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; } 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 @@ <?php foreach($css as $file) echo $this->embed_css($file); ?> + <?php foreach($js as $file) + echo $this->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 @@ <?php /* Copyright (c) 2024 Freya Murphy */ $style = array(); $style['home'] = 'css/home.css'; -$style['blog'] = 'css/blog.css'; +$style['blog'] = ['css/blog.css', 'css/prism.css']; $style['error'] = 'css/error.css'; +$style['prism'] = 'css/prism.css'; + +$js = array(); +$js['blog'] = 'js/prism.js'; diff --git a/src/web/core/core.php b/src/web/core/core.php index d15436a..cfeeea9 100644 --- a/src/web/core/core.php +++ b/src/web/core/core.php @@ -51,6 +51,17 @@ abstract class Core { } /** + * Loads a js html link + * @param string $path - the path to the js file + */ + public static function link_js(string $path): string + { + $stamp = Core::asset_stamp($path); + $href = Core::get_url("public/{$path}?stamp={$stamp}"); + return '<script src="'. $href .'"></script>'; + } + + /** * 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; } |