feat: ✨ add new file metadata handling (.ext.md instead of .mddesc)
This commit is contained in:
parent
d39595d577
commit
c202b778e0
3 changed files with 37 additions and 32 deletions
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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',
|
$post_meta['media_file'] ??= "https://" . $this->SITE_CONFIG['HTTP_HOST'] . chop($post_data['post_path'], ".md");
|
||||||
'jpg' => 'image',
|
}
|
||||||
'jpeg' => 'image'
|
|
||||||
];
|
$ext_mapping = [
|
||||||
|
'' => 'directory',
|
||||||
if(isset($ext_mapping[$ext])) {
|
'md' => 'text/markdown',
|
||||||
$post_meta['type'] = $ext_mapping[$ext];
|
'png' => 'image',
|
||||||
}
|
'jpg' => 'image',
|
||||||
else {
|
'jpeg' => 'image'
|
||||||
$post_meta['type'] = '?';
|
];
|
||||||
}
|
|
||||||
|
if(isset($ext_mapping[$ext])) {
|
||||||
|
$post_meta['type'] ??= $ext_mapping[$ext];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$post_meta['type'] ??= '?';
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!isset($post_meta['icon'])) {
|
$icon_mapping = [
|
||||||
$icon_mapping = [
|
'' => 'question',
|
||||||
'' => 'question',
|
'text/markdown' => 'markdown',
|
||||||
'text/markdown' => 'markdown',
|
'directory' => 'folder',
|
||||||
'directory' => 'folder',
|
'image' => 'image'
|
||||||
'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_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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue