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;
|
||||
}
|
||||
|
||||
public static function _deduce_type($path) {
|
||||
public static function deduce_type($path) {
|
||||
$ext = pathinfo($path, PATHINFO_EXTENSION);
|
||||
|
||||
if(preg_match("/\.(\w+)\.md$/", $path, $ext_match)) {
|
||||
|
@ -45,7 +45,15 @@ class Post implements ArrayAccess {
|
|||
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 = [
|
||||
'' => 'question',
|
||||
'text/markdown' => 'markdown',
|
||||
|
@ -60,9 +68,11 @@ class Post implements ArrayAccess {
|
|||
return $icon_mapping[$type] ?? 'unknown';
|
||||
}
|
||||
|
||||
public static function _deduce_template($type) {
|
||||
public static function deduce_template($type) {
|
||||
$template_mapping = [
|
||||
'directory' => 'directory'
|
||||
'directory' => 'directory',
|
||||
'gallery' => 'gallery',
|
||||
'image' => 'image'
|
||||
];
|
||||
|
||||
return $template_mapping[$type] ?? 'vanilla';
|
||||
|
@ -91,24 +101,31 @@ class Post implements ArrayAccess {
|
|||
$data['url'] ??= 'http://' . $post_data['host'] . $post_data['path'];
|
||||
|
||||
$data['basename'] ??= basename($data['path']);
|
||||
|
||||
$data['title'] ??= basename($data['path']);
|
||||
|
||||
$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['template'] ??= self::_deduce_template($data['type']);
|
||||
$data['icon'] ??= self::deduce_icon($data['type']);
|
||||
$data['template'] ??= self::deduce_template($data['type']);
|
||||
|
||||
if(isset($sql_meta['media_url'])) {
|
||||
$data['thumb_url'] ??= $data['media_url'];
|
||||
}
|
||||
$data['media_url'] ??= self::deduce_media_url($data['path']);
|
||||
$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'];
|
||||
|
||||
if($data['type'] == 'gallery') {
|
||||
$data['search'] ??= [
|
||||
'+path:' . $data['path'] . '/*',
|
||||
'+type:image'
|
||||
];
|
||||
}
|
||||
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue