website

#astro#js#html#css

git clone https://git.pyrossh.dev/website

木 Personal website of pyrossh. Built with astrojs, shiki, vite.


src/_includes/file-tree.njk
3c79a68 1
{% macro renderNodes(nodes, repoId, activePath) %}
3c79a68 2
<ul>
3c79a68 3
  {% for node in nodes %}
3c79a68 4
    {% if node.isDirectory %}
3c79a68 5
    <li>
3c79a68 6
      <details {% if node.path | isAncestorDir(activePath) %}open{% endif %}>
3c79a68 7
        <summary>{{ node.name | folderIcon | safe }}{{ node.name }}/</summary>
3c79a68 8
        {{ renderNodes(node.children, repoId, activePath) }}
3c79a68 9
      </details>
3c79a68 10
    </li>
3c79a68 11
    {% else %}
3c79a68 12
    {% set href = "/repos/" + repoId + "/files/" + node.path + "/" %}
3c79a68 13
    <li>
3c79a68 14
      <a
3c79a68 15
        href="{{ href }}"
3c79a68 16
        hx-get="{{ href }}"
3c79a68 17
        hx-select="#file-pane"
3c79a68 18
        hx-target="#file-pane"
3c79a68 19
        hx-swap="outerHTML"
3c79a68 20
        hx-push-url="true"
3c79a68 21
        class="{% if node.path == activePath %}active-file{% endif %}"
3c79a68 22
      >{{ node.name | fileIcon(node.ext) | safe }}{{ node.name }}<span class="file-size">{{ node.size | formatBytes }}</span></a>
3c79a68 23
    </li>
3c79a68 24
    {% endif %}
3c79a68 25
  {% endfor %}
3c79a68 26
</ul>
3c79a68 27
{% endmacro %}