diff --git a/www/.htaccess b/www/.htaccess index d624f34..20c4100 100644 --- a/www/.htaccess +++ b/www/.htaccess @@ -3,12 +3,17 @@ AddType text/plain .md AddType text/plain .atom AddType text/plain .rss -php_value upload_max_filesize 40M -php_value post_max_size 42M +# php_value upload_max_filesize 40M +# php_value post_max_size 42M RewriteEngine On RewriteBase / +RewriteCond %{REQUEST_URI} !^/raw/ +RewriteRule ^.*\.(flv|gif|ico|jpg|jpeg|mp4|mpeg|png|svg|swf|webp)$ raw/%{HTTP_HOST}%{REQUEST_URI} [L,END] + +RewriteRule ^/?raw/(.*)$ raw/%{HTTP_HOST}/$1 [L,END] + RewriteCond %{REQUEST_URI} !^/?(static|raw|robots\.txt).* RewriteRule (.*) router.php diff --git a/www/post_adapter.php b/www/post_adapter.php index 0e96552..6553995 100644 --- a/www/post_adapter.php +++ b/www/post_adapter.php @@ -30,41 +30,42 @@ class PostHandler extends MySQLAdapter { $post_meta["title"] = "root"; } - if(!isset($post_meta['type'])) { - $type = null; - $ext = pathinfo($post_data['post_basename'], PATHINFO_EXTENSION); + $ext = pathinfo($post_data['post_basename'], PATHINFO_EXTENSION); - $ext_mapping = [ - '' => 'directory', - 'md' => 'text/markdown', - 'png' => 'image', - 'jpg' => 'image', - 'jpeg' => 'image' - ]; - - if(isset($ext_mapping[$ext])) { - $post_meta['type'] = $ext_mapping[$ext]; - } - else { - $post_meta['type'] = '?'; - } + if(preg_match("/\.(\w+)\.md$/", $post_data['post_basename'], $ext_match)) { + $ext = $ext_match[1]; + + $post_meta['media_file'] ??= "https://" . $this->SITE_CONFIG['HTTP_HOST'] . chop($post_data['post_path'], ".md"); + } + + $ext_mapping = [ + '' => 'directory', + 'md' => 'text/markdown', + 'png' => 'image', + 'jpg' => 'image', + 'jpeg' => 'image' + ]; + + if(isset($ext_mapping[$ext])) { + $post_meta['type'] ??= $ext_mapping[$ext]; + } + else { + $post_meta['type'] ??= '?'; } - if(!isset($post_meta['icon'])) { - $icon_mapping = [ - '' => 'question', - 'text/markdown' => 'markdown', - 'directory' => 'folder', - 'image' => 'image' - ]; + $icon_mapping = [ + '' => 'question', + 'text/markdown' => 'markdown', + 'directory' => 'folder', + 'image' => 'image' + ]; - $post_meta['icon'] = $icon_mapping[$post_meta['type']] ?? 'question'; - } + $post_meta['icon'] ??= $icon_mapping[$post_meta['type']] ?? 'question'; $post_data['post_metadata'] = $post_meta; - $post_data["post_file_dir"] = '/' . $this->data_directory . $post_data["post_path"]; + $post_data["post_file_dir"] = '/raw' . $post_data["post_path"]; return $post_data; } @@ -83,7 +84,6 @@ class PostHandler extends MySQLAdapter { } function save_file($post_path, $file_path) { - $this->bump_post($post_path); move_uploaded_file($file_path, $this->data_directory . $post_path); } diff --git a/www/templates/post_types/image.html b/www/templates/post_types/image.html index 00ea107..6c386e9 100644 --- a/www/templates/post_types/image.html +++ b/www/templates/post_types/image.html @@ -16,8 +16,8 @@ {%block content_article%}
- - + +