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

View File

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