Skip to content

Commit abe0c20

Browse files
committed
Add breadcrumbs to tree view
1 parent 98383dc commit abe0c20

File tree

8 files changed

+52
-7
lines changed

8 files changed

+52
-7
lines changed

src/database/indexer.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::{
2-
borrow::Cow,
32
collections::HashSet,
43
ffi::OsStr,
54
fmt::Debug,

src/methods/filters.rs

+8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ pub fn format_time(s: impl Into<Timestamp>) -> Result<String, askama::Error> {
2424
.map_err(askama::Error::Custom)
2525
}
2626

27+
pub fn branch_query(branch: Option<&str>) -> String {
28+
if let Some(b) = branch {
29+
format!("?h={b}")
30+
} else {
31+
String::new()
32+
}
33+
}
34+
2735
pub fn timeago(s: impl Into<Timestamp>) -> Result<String, askama::Error> {
2836
Ok(timeago::Formatter::new()
2937
.convert((OffsetDateTime::now_utc() - s.into().0).try_into().unwrap()))

src/methods/repo/tree.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use std::{
2-
fmt::{Display, Formatter},
3-
sync::Arc,
4-
};
5-
61
use askama::Template;
72
use axum::{extract::Query, response::IntoResponse, Extension};
83
use itertools::Itertools;
94
use serde::Deserialize;
5+
use std::path::PathBuf;
6+
use std::{
7+
fmt::{Display, Formatter},
8+
sync::Arc,
9+
};
1010

1111
use crate::{
1212
git::{FileWithContent, PathDestination, TreeItem},
@@ -51,13 +51,15 @@ pub struct TreeView {
5151
pub repo: Repository,
5252
pub items: Vec<TreeItem>,
5353
pub query: UriQuery,
54+
pub repo_path: PathBuf,
5455
pub branch: Option<Arc<str>>,
5556
}
5657

5758
#[derive(Template)]
5859
#[template(path = "repo/file.html")]
5960
pub struct FileView {
6061
pub repo: Repository,
62+
pub repo_path: PathBuf,
6163
pub file: FileWithContent,
6264
pub branch: Option<Arc<str>>,
6365
}
@@ -73,7 +75,7 @@ pub async fn handle(
7375

7476
Ok(
7577
match open_repo
76-
.path(child_path, query.id.as_deref(), !query.raw)
78+
.path(child_path.clone(), query.id.as_deref(), !query.raw)
7779
.await?
7880
{
7981
PathDestination::Tree(items) => {
@@ -82,6 +84,7 @@ pub async fn handle(
8284
items,
8385
branch: query.branch.clone(),
8486
query,
87+
repo_path: child_path.unwrap_or_default(),
8588
})))
8689
}
8790
PathDestination::File(file) if query.raw => ResponseEither::Right(file.content),
@@ -90,6 +93,7 @@ pub async fn handle(
9093
repo,
9194
file,
9295
branch: query.branch,
96+
repo_path: child_path.unwrap_or_default(),
9397
})))
9498
}
9599
},

statics/sass/style.scss

+9
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ nav {
5858
}
5959
}
6060

61+
aside {
62+
background: #f7f7f7;
63+
padding: 0.3rem 2rem;
64+
65+
@media (prefers-color-scheme: dark) {
66+
background: #111;
67+
}
68+
}
69+
6170
main {
6271
padding: 2rem;
6372
margin: 0;

templates/base.html

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ <h1>
3030
</nav>
3131
{%- endblock -%}
3232

33+
<aside>
34+
{%- block subnav %}{% endblock %}
35+
</aside>
36+
3337
<main>
3438
{%- block content %}{% endblock -%}
3539
</main>

templates/repo/file.html

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{% import "macros/link.html" as link %}
2+
{% import "macros/breadcrumbs.html" as breadcrumbs %}
23
{% extends "repo/base.html" %}
34

45
{% block head %}
@@ -8,6 +9,10 @@
89

910
{% block tree_nav_class %}active{% endblock %}
1011

12+
{% block subnav %}
13+
{% call breadcrumbs::breadcrumbs(repo_path, filters::branch_query(branch.as_deref())) %}
14+
{% endblock %}
15+
1116
{% block extra_nav_links %}
1217
<a href="?raw=true{% call link::maybe_branch_suffix(branch) %}">plain</a>
1318
{% endblock %}
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{%- macro breadcrumbs(repo_path, query) -%}
2+
path:&nbsp;
3+
<a href="/{{ repo.display() }}/tree/{{ query }}">{{ repo.display() }}</a>
4+
{%- for child in repo_path.ancestors().collect_vec().into_iter().rev() -%}
5+
{%- if let Some(file_name) = child.file_name() -%}
6+
/<a href="/{{ repo.display() }}/tree/{{ child.display() }}{{ query }}">
7+
{{- file_name.to_string_lossy() -}}
8+
</a>
9+
{%- endif -%}
10+
{%- endfor -%}
11+
{%- endmacro -%}

templates/repo/tree.html

+5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
{% import "macros/breadcrumbs.html" as breadcrumbs %}
12
{% extends "repo/base.html" %}
23

34
{% block tree_nav_class %}active{% endblock %}
45

6+
{% block subnav %}
7+
{% call breadcrumbs::breadcrumbs(repo_path, query) %}
8+
{% endblock %}
9+
510
{% block content %}
611
<div class="table-responsive">
712
<table class="repositories">

0 commit comments

Comments
 (0)