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

@ -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);
}