feat: add new file metadata handling (.ext.md instead of .mddesc)

This commit is contained in:
David Bailey 2024-01-11 14:37:06 +01:00
parent d39595d577
commit c202b778e0
3 changed files with 37 additions and 32 deletions

View file

@ -3,12 +3,17 @@ AddType text/plain .md
AddType text/plain .atom AddType text/plain .atom
AddType text/plain .rss AddType text/plain .rss
php_value upload_max_filesize 40M # php_value upload_max_filesize 40M
php_value post_max_size 42M # php_value post_max_size 42M
RewriteEngine On RewriteEngine On
RewriteBase / 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).* RewriteCond %{REQUEST_URI} !^/?(static|raw|robots\.txt).*
RewriteRule (.*) router.php RewriteRule (.*) router.php

View file

@ -30,41 +30,42 @@ class PostHandler extends MySQLAdapter {
$post_meta["title"] = "root"; $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 = [ if(preg_match("/\.(\w+)\.md$/", $post_data['post_basename'], $ext_match)) {
'' => 'directory', $ext = $ext_match[1];
'md' => 'text/markdown',
'png' => 'image',
'jpg' => 'image',
'jpeg' => 'image'
];
if(isset($ext_mapping[$ext])) { $post_meta['media_file'] ??= "https://" . $this->SITE_CONFIG['HTTP_HOST'] . chop($post_data['post_path'], ".md");
$post_meta['type'] = $ext_mapping[$ext];
}
else {
$post_meta['type'] = '?';
}
} }
if(!isset($post_meta['icon'])) { $ext_mapping = [
$icon_mapping = [ '' => 'directory',
'' => 'question', 'md' => 'text/markdown',
'text/markdown' => 'markdown', 'png' => 'image',
'directory' => 'folder', 'jpg' => 'image',
'image' => 'image' 'jpeg' => 'image'
]; ];
$post_meta['icon'] = $icon_mapping[$post_meta['type']] ?? 'question'; if(isset($ext_mapping[$ext])) {
$post_meta['type'] ??= $ext_mapping[$ext];
} }
else {
$post_meta['type'] ??= '?';
}
$icon_mapping = [
'' => 'question',
'text/markdown' => 'markdown',
'directory' => 'folder',
'image' => 'image'
];
$post_meta['icon'] ??= $icon_mapping[$post_meta['type']] ?? 'question';
$post_data['post_metadata'] = $post_meta; $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; return $post_data;
} }
@ -83,7 +84,6 @@ class PostHandler extends MySQLAdapter {
} }
function save_file($post_path, $file_path) { function save_file($post_path, $file_path) {
$this->bump_post($post_path);
move_uploaded_file($file_path, $this->data_directory . $post_path); move_uploaded_file($file_path, $this->data_directory . $post_path);
} }

View file

@ -16,8 +16,8 @@
{%block content_article%} {%block content_article%}
<figure> <figure>
<a target="_blank" href="{{post['post_file_dir']}}"> <a target="_blank" href="{{post.post_metadata.media_file}}">
<img id="gallery_image" src="{{post['post_file_dir']}}"></img> <img id="gallery_image" src="{{post.post_metadata.media_file}}"></img>
</a> </a>
<figcaption> <figcaption>