feat: Render tree without .md and everything as links

This commit is contained in:
Dendy 2025-04-14 02:41:57 +02:00
parent 6bb37a4741
commit 2d48a4c1a7
2 changed files with 12 additions and 20 deletions

View File

@ -52,8 +52,6 @@ final class MainController extends AbstractController
// Convert flat list into a nested tree // Convert flat list into a nested tree
$tree = []; $tree = [];
foreach ($finder as $file) { foreach ($finder as $file) {
/** @var SplFileInfo $file */
$current = &$tree; $current = &$tree;
// Dunno why it is undefined, it works // Dunno why it is undefined, it works
@ -66,9 +64,7 @@ final class MainController extends AbstractController
$current = &$current[$part]; $current = &$current[$part];
} }
$current[] = $file; $current[$file->getFilenameWithoutExtension()] = [];
//usort($current, fn($a, $b) => strcmp(implode('/', $a), implode('/', $b)));
} }
return $this->render('main/index.html.twig', [ return $this->render('main/index.html.twig', [

View File

@ -2,20 +2,16 @@
{% block title %}{{ path }} | Gaisen{% endblock %} {% block title %}{{ path }} | Gaisen{% endblock %}
{% macro render_tree(tree) %} {% macro render_tree(tree, prefix = '') %}
<ul> <ul>
{% for key, value in tree %} {% for name, subtree in tree %}
<li> <li>
{% if value is iterable and value|length > 0 %}
{{ key }}
{{ _self.render_tree(value) }} {# Recursive call #}
{% else %}
<a href="{{ path('app_index', { <a href="{{ path('app_index', {
path: value.relativePathname path: prefix ~ name
}) }}"> }) }}">
{{ value.filename }} {{ name }}
</a> </a>
{% endif %} {{ _self.render_tree(subtree, name ~ '/') }}
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>