feat: add FontAwesome symbols for directories

This commit is contained in:
David Bailey 2024-01-04 16:05:16 +01:00
parent 87a14e0624
commit 62089b9ee2
5 changed files with 46 additions and 6 deletions

10
www/fontawesome.php Normal file
View file

@ -0,0 +1,10 @@
<?php
$FONT_AWESOME_ARRAY=[
'markdown' => '<svg xmlns="http://www.w3.org/2000/svg" height="16" width="20" viewBox="0 0 640 512"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2023 Fonticons, Inc.--><path d="M593.8 59.1H46.2C20.7 59.1 0 79.8 0 105.2v301.5c0 25.5 20.7 46.2 46.2 46.2h547.7c25.5 0 46.2-20.7 46.1-46.1V105.2c0-25.4-20.7-46.1-46.2-46.1zM338.5 360.6H277v-120l-61.5 76.9-61.5-76.9v120H92.3V151.4h61.5l61.5 76.9 61.5-76.9h61.5v209.2zm135.3 3.1L381.5 256H443V151.4h61.5V256H566z"/></svg>',
'image' => '<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16" viewBox="0 0 512 512"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2023 Fonticons, Inc.--><path d="M0 96C0 60.7 28.7 32 64 32H448c35.3 0 64 28.7 64 64V416c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64V96zM323.8 202.5c-4.5-6.6-11.9-10.5-19.8-10.5s-15.4 3.9-19.8 10.5l-87 127.6L170.7 297c-4.6-5.7-11.5-9-18.7-9s-14.2 3.3-18.7 9l-64 80c-5.8 7.2-6.9 17.1-2.9 25.4s12.4 13.6 21.6 13.6h96 32H424c8.9 0 17.1-4.9 21.2-12.8s3.6-17.4-1.4-24.7l-120-176zM112 192a48 48 0 1 0 0-96 48 48 0 1 0 0 96z"/></svg>',
'folder' => '<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16" viewBox="0 0 512 512"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2023 Fonticons, Inc.--><path d="M64 480H448c35.3 0 64-28.7 64-64V160c0-35.3-28.7-64-64-64H288c-10.1 0-19.6-4.7-25.6-12.8L243.2 57.6C231.1 41.5 212.1 32 192 32H64C28.7 32 0 60.7 0 96V416c0 35.3 28.7 64 64 64z"/></svg>',
'rss' => '<svg xmlns="http://www.w3.org/2000/svg" height="16" width="14" viewBox="0 0 448 512"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2023 Fonticons, Inc.--><path d="M64 32C28.7 32 0 60.7 0 96V416c0 35.3 28.7 64 64 64H384c35.3 0 64-28.7 64-64V96c0-35.3-28.7-64-64-64H64zM96 136c0-13.3 10.7-24 24-24c137 0 248 111 248 248c0 13.3-10.7 24-24 24s-24-10.7-24-24c0-110.5-89.5-200-200-200c-13.3 0-24-10.7-24-24zm0 96c0-13.3 10.7-24 24-24c83.9 0 152 68.1 152 152c0 13.3-10.7 24-24 24s-24-10.7-24-24c0-57.4-46.6-104-104-104c-13.3 0-24-10.7-24-24zm0 120a32 32 0 1 1 64 0 32 32 0 1 1 -64 0z"/></svg>'
];
?>

View file

@ -26,7 +26,10 @@ class PostHandler extends MySQLAdapter {
$post_meta = $post_data['post_metadata'];
$post_meta["title"] ??= basename($post_data["post_path"]);
if($post_meta["title"] == "") {
$post_meta["title"] = "root";
}
if(!isset($post_meta['type'])) {
$type = null;
@ -36,13 +39,29 @@ class PostHandler extends MySQLAdapter {
'' => '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'
];
$post_meta['icon'] = $icon_mapping[$post_meta['type']] ?? 'question';
}
$post_data["post_file_dir"] = '/' . $this->data_directory . $post_data["post_path"];
$post_data['post_metadata'] = $post_meta;

View file

@ -3,9 +3,11 @@
$data_time_start = microtime(true);
require_once 'vendor/autoload.php';
require_once 'post_adapter.php';
require_once 'post_adapter.php';
require_once 'fontawesome.php';
$adapter = new PostHandler();
$loader = new \Twig\Loader\FilesystemLoader(['./templates', './user_content']);
@ -64,6 +66,7 @@ $twig->addRuntimeLoader(new class implements RuntimeLoaderInterface {
function generate_website($SURI) {
global $twig;
global $adapter;
global $FONT_AWESOME_ARRAY;
if(preg_match('/^\/api\/admin/', $SURI)) {
header('Content-Type: application/json');
@ -146,17 +149,20 @@ function generate_website($SURI) {
echo $twig->render('post_types/directory.html', [
"post" => $post,
"subposts" => $adapter->get_subposts_by_path($SURI)
"subposts" => $adapter->get_subposts_by_path($SURI),
"fa" => $FONT_AWESOME_ARRAY
]);
}
elseif($post['post_metadata']['type'] == 'text/markdown') {
echo $twig->render('post_types/markdown.html', [
"post" => $post
"post" => $post,
"fa" => $FONT_AWESOME_ARRAY
]);
}
elseif($post['post_metadata']['type'] == 'image') {
echo $twig->render('post_types/image.html', [
"post" => $post
"post" => $post,
"fa" => $FONT_AWESOME_ARRAY
]);
}

View file

@ -6,6 +6,11 @@
padding: 0;
}
svg {
fill: var(--text_1);
padding-top: 0.1rem;
}
body {
--bg_1: #0e0a2a;
--bg_2: #2c2943;

View file

@ -19,7 +19,7 @@
{% for subpost in subposts %}
<tr class="entry">
<td>
ICN
{{ fa[subpost.post_metadata.icon] | raw }}
</td>
<td>
<a href={{subpost.post_path}}>{{subpost.post_basename}}</a>