Pass full node struct to node handler

This commit is contained in:
Juno Takano 2025-12-20 21:26:36 -03:00
commit 77d08036c6
2 changed files with 19 additions and 18 deletions

View file

@ -9,15 +9,11 @@ pub async fn node(Path(id): Path<String>) -> Response<Body> {
let node: &Node = graph.nodes.get(&id).unwrap_or(&empty_node);
let mut context = tera::Context::new();
context.insert("id", &id);
context.insert("title", &node.title);
context.insert("connections", &node.connections.clone());
context.insert("node", &node);
context.insert("text", &content::parse(&node.text));
context.insert("incoming", &graph.incoming.get(&id));
context.insert("config", &graph.meta.config.parse_text());
let out_text = content::parse(&node.text);
context.insert("text", &out_text);
let not_found = *node == empty_node;
let template_name = "node.html".to_string();

View file

@ -1,30 +1,35 @@
{% extends "base.html" %}
{% block title %}{{ title }}{% endblock title %}
{% block title %}{{ node.title }}{% endblock title %}
{%- block body %}
<section>
<h1>{{ title }}</h1>
<code style="display: inline;">ID: {{ id }}</code>
<div class="header-row">
<h1 class="node-title">{{ node.title }}</h1>
<div class="labels">
<span class="label id-label">ID: {{ node.id }}</span>
{% if node.hidden %}<span class="label hidden-label">Hidden</span>{% endif %}
</div>
</div>
{{ text | safe }}
</section>
{% if connections or incoming %}
{% if node.connections or incoming %}
<aside>
<hr>
<h2>Connections</h2>
{% if connections %}
{% if node.connections %}
<ul>
{% for connection in connections | filter(attribute="detached", value=false) %}
{% for connection in node.connections | filter(attribute="detached", value=false) %}
<li>
<strong>{{id}}</strong>
&#x1f86a;
<strong>{{node.id}}</strong>
&raquo;
<a href="/node/{{connection.to}}">{{connection.to}}</a>
</li>
{% endfor %}
{% for connection in connections | filter(attribute="detached", value=true) %}
{% for connection in node.connections | filter(attribute="detached", value=true) %}
<li>
<strong>{{id}}</strong>
&#x1f86a;
<strong>{{node.id}}</strong>
&raquo;
<span style="filter: opacity(70%);">{{connection.to}}</span>
</li>
{% endfor %}
@ -38,7 +43,7 @@
{% for connection in incoming %}
<li>
<strong>{{connection.to}}</strong>
&#x1F868;
&laquo;
<a href="/node/{{connection.from}}">{{connection.from}}</a>
</li>
{% endfor %}