🏡 index : ~doyle/rgit.git

author Jordan Doyle <jordan@doyle.la> 2024-10-17 0:50:37.0 +01:00:00
committer Jordan Doyle <jordan@doyle.la> 2024-10-17 0:50:37.0 +01:00:00
commit
abe0c20a699b48e6bdcc2b437b59613d2e9e349b [patch]
tree
7947df0823c7ec4cf2b863e4ae0ee581c4fa5810
parent
98383dcf4591777e7cc14ce0685fb7d0195ca42c
download
abe0c20a699b48e6bdcc2b437b59613d2e9e349b.tar.gz

Add breadcrumbs to tree view



Diff

 templates/base.html                    |  4 ++++
 src/database/indexer.rs                |  1 -
 src/methods/filters.rs                 |  8 ++++++++
 statics/sass/style.scss                |  9 +++++++++
 templates/repo/file.html               |  5 +++++
 templates/repo/tree.html               |  5 +++++
 src/methods/repo/tree.rs               | 16 ++++++++++++----
 templates/repo/macros/breadcrumbs.html | 11 +++++++++++
 8 files changed, 52 insertions(+), 7 deletions(-)

diff --git a/templates/base.html b/templates/base.html
index 477cb47..cc8e66f 100644
--- a/templates/base.html
+++ a/templates/base.html
@@ -30,6 +30,10 @@
</nav>
{%- endblock -%}

<aside>
    {%- block subnav %}{% endblock %}
</aside>

<main>
    {%- block content %}{% endblock -%}
</main>
diff --git a/src/database/indexer.rs b/src/database/indexer.rs
index 549666d..4e9887e 100644
--- a/src/database/indexer.rs
+++ a/src/database/indexer.rs
@@ -1,5 +1,4 @@
use std::{
    borrow::Cow,
    collections::HashSet,
    ffi::OsStr,
    fmt::Debug,
diff --git a/src/methods/filters.rs b/src/methods/filters.rs
index 3f2093e..69c1e5c 100644
--- a/src/methods/filters.rs
+++ a/src/methods/filters.rs
@@ -24,6 +24,14 @@
        .map_err(askama::Error::Custom)
}

pub fn branch_query(branch: Option<&str>) -> String {
    if let Some(b) = branch {
        format!("?h={b}")
    } else {
        String::new()
    }
}

pub fn timeago(s: impl Into<Timestamp>) -> Result<String, askama::Error> {
    Ok(timeago::Formatter::new()
        .convert((OffsetDateTime::now_utc() - s.into().0).try_into().unwrap()))
diff --git a/statics/sass/style.scss b/statics/sass/style.scss
index 58012fe..b92d654 100644
--- a/statics/sass/style.scss
+++ a/statics/sass/style.scss
@@ -58,6 +58,15 @@
  }
}

aside {
  background: #f7f7f7;
  padding: 0.3rem 2rem;

  @media (prefers-color-scheme: dark) {
    background: #111;
  }
}

main {
  padding: 2rem;
  margin: 0;
diff --git a/templates/repo/file.html b/templates/repo/file.html
index 2d7a65e..7862a54 100644
--- a/templates/repo/file.html
+++ a/templates/repo/file.html
@@ -1,4 +1,5 @@
{% import "macros/link.html" as link %}
{% import "macros/breadcrumbs.html" as breadcrumbs %}
{% extends "repo/base.html" %}

{% block head %}
@@ -7,6 +8,10 @@
{%- endblock %}

{% block tree_nav_class %}active{% endblock %}

{% block subnav %}
    {% call breadcrumbs::breadcrumbs(repo_path, filters::branch_query(branch.as_deref())) %}
{% endblock %}

{% block extra_nav_links %}
    <a href="?raw=true{% call link::maybe_branch_suffix(branch) %}">plain</a>
diff --git a/templates/repo/tree.html b/templates/repo/tree.html
index fcad7db..1d87346 100644
--- a/templates/repo/tree.html
+++ a/templates/repo/tree.html
@@ -1,6 +1,11 @@
{% import "macros/breadcrumbs.html" as breadcrumbs %}
{% extends "repo/base.html" %}

{% block tree_nav_class %}active{% endblock %}

{% block subnav %}
    {% call breadcrumbs::breadcrumbs(repo_path, query) %}
{% endblock %}

{% block content %}
<div class="table-responsive">
diff --git a/src/methods/repo/tree.rs b/src/methods/repo/tree.rs
index b80f89d..2a90019 100644
--- a/src/methods/repo/tree.rs
+++ a/src/methods/repo/tree.rs
@@ -1,12 +1,12 @@
use std::{
    fmt::{Display, Formatter},
    sync::Arc,
};

use askama::Template;
use axum::{extract::Query, response::IntoResponse, Extension};
use itertools::Itertools;
use serde::Deserialize;
use std::path::PathBuf;
use std::{
    fmt::{Display, Formatter},
    sync::Arc,
};

use crate::{
    git::{FileWithContent, PathDestination, TreeItem},
@@ -51,6 +51,7 @@
    pub repo: Repository,
    pub items: Vec<TreeItem>,
    pub query: UriQuery,
    pub repo_path: PathBuf,
    pub branch: Option<Arc<str>>,
}

@@ -58,6 +59,7 @@
#[template(path = "repo/file.html")]
pub struct FileView {
    pub repo: Repository,
    pub repo_path: PathBuf,
    pub file: FileWithContent,
    pub branch: Option<Arc<str>>,
}
@@ -73,7 +75,7 @@

    Ok(
        match open_repo
            .path(child_path, query.id.as_deref(), !query.raw)
            .path(child_path.clone(), query.id.as_deref(), !query.raw)
            .await?
        {
            PathDestination::Tree(items) => {
@@ -82,6 +84,7 @@
                    items,
                    branch: query.branch.clone(),
                    query,
                    repo_path: child_path.unwrap_or_default(),
                })))
            }
            PathDestination::File(file) if query.raw => ResponseEither::Right(file.content),
@@ -90,6 +93,7 @@
                    repo,
                    file,
                    branch: query.branch,
                    repo_path: child_path.unwrap_or_default(),
                })))
            }
        },
diff --git a/templates/repo/macros/breadcrumbs.html b/templates/repo/macros/breadcrumbs.html
new file mode 100644
index 0000000..a5ecb22 100644
--- /dev/null
+++ a/templates/repo/macros/breadcrumbs.html
@@ -1,0 +1,11 @@
{%- macro breadcrumbs(repo_path, query) -%}
    path:&nbsp;
    <a href="/{{ repo.display() }}/tree/{{ query }}">{{ repo.display() }}</a>
    {%- for child in repo_path.ancestors().collect_vec().into_iter().rev() -%}
        {%- if let Some(file_name) = child.file_name() -%}
            /<a href="/{{ repo.display() }}/tree/{{ child.display() }}{{ query }}">
                {{- file_name.to_string_lossy() -}}
            </a>
        {%- endif -%}
    {%- endfor -%}
{%- endmacro -%}