feat: 🎨 clean up function naming a little
This commit is contained in:
parent
22c953793c
commit
bf2486caa4
1 changed files with 29 additions and 12 deletions
|
@ -27,7 +27,7 @@ class Post implements ArrayAccess {
|
||||||
return $post_data;
|
return $post_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function _deduce_type($path) {
|
public static function deduce_type($path) {
|
||||||
$ext = pathinfo($path, PATHINFO_EXTENSION);
|
$ext = pathinfo($path, PATHINFO_EXTENSION);
|
||||||
|
|
||||||
if(preg_match("/\.(\w+)\.md$/", $path, $ext_match)) {
|
if(preg_match("/\.(\w+)\.md$/", $path, $ext_match)) {
|
||||||
|
@ -45,7 +45,15 @@ class Post implements ArrayAccess {
|
||||||
return $ext_mapping[$ext] ?? '?';
|
return $ext_mapping[$ext] ?? '?';
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function _deduce_icon($type) {
|
public static function deduce_media_url($path) {
|
||||||
|
if(preg_match("/^(.*\.\w+)\.md$/", $path, $ext_match)) {
|
||||||
|
return $ext_match[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function deduce_icon($type) {
|
||||||
$icon_mapping = [
|
$icon_mapping = [
|
||||||
'' => 'question',
|
'' => 'question',
|
||||||
'text/markdown' => 'markdown',
|
'text/markdown' => 'markdown',
|
||||||
|
@ -60,9 +68,11 @@ class Post implements ArrayAccess {
|
||||||
return $icon_mapping[$type] ?? 'unknown';
|
return $icon_mapping[$type] ?? 'unknown';
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function _deduce_template($type) {
|
public static function deduce_template($type) {
|
||||||
$template_mapping = [
|
$template_mapping = [
|
||||||
'directory' => 'directory'
|
'directory' => 'directory',
|
||||||
|
'gallery' => 'gallery',
|
||||||
|
'image' => 'image'
|
||||||
];
|
];
|
||||||
|
|
||||||
return $template_mapping[$type] ?? 'vanilla';
|
return $template_mapping[$type] ?? 'vanilla';
|
||||||
|
@ -91,24 +101,31 @@ class Post implements ArrayAccess {
|
||||||
$data['url'] ??= 'http://' . $post_data['host'] . $post_data['path'];
|
$data['url'] ??= 'http://' . $post_data['host'] . $post_data['path'];
|
||||||
|
|
||||||
$data['basename'] ??= basename($data['path']);
|
$data['basename'] ??= basename($data['path']);
|
||||||
|
|
||||||
$data['title'] ??= basename($data['path']);
|
$data['title'] ??= basename($data['path']);
|
||||||
|
|
||||||
$data['tags'] ??= [];
|
$data['tags'] ??= [];
|
||||||
|
|
||||||
$data['type'] ??= self::_deduce_type($post_data['path']);
|
$data['type'] ??= self::deduce_type($post_data['path']);
|
||||||
|
|
||||||
$data['icon'] ??= self::_deduce_icon($data['type']);
|
$data['icon'] ??= self::deduce_icon($data['type']);
|
||||||
$data['template'] ??= self::_deduce_template($data['type']);
|
$data['template'] ??= self::deduce_template($data['type']);
|
||||||
|
|
||||||
if(isset($sql_meta['media_url'])) {
|
$data['media_url'] ??= self::deduce_media_url($data['path']);
|
||||||
$data['thumb_url'] ??= $data['media_url'];
|
$data['media_preview_url'] ??= $data['media_url'];
|
||||||
}
|
|
||||||
|
|
||||||
$data['preview_image'] ??= $data['banners'][0]['src'] ?? null;
|
// TODO: Try to check for thumb image automatically here
|
||||||
|
$data['preview_image'] ??= $data['media_preview_url'] ??
|
||||||
|
$data['banners'][0]['src'] ?? null;
|
||||||
|
|
||||||
$data['brief'] ??= $data['title'];
|
$data['brief'] ??= $data['title'];
|
||||||
|
|
||||||
|
if($data['type'] == 'gallery') {
|
||||||
|
$data['search'] ??= [
|
||||||
|
'+path:' . $data['path'] . '/*',
|
||||||
|
'+type:image'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
$this->data = $data;
|
$this->data = $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue