Skip to content

Commit

Permalink
Make Overview button view the current directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
AustinWise committed Apr 8, 2023
1 parent a2bcbb3 commit 76d8431
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
18 changes: 17 additions & 1 deletion src/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ impl<'r> WikiPagePath<'r> {
}
}

fn directory(&self) -> Option<Self> {
let (_, dirs) = self.segments.split_last()?;
Some(WikiPagePath {
segments: dirs.to_owned(),
})
}

fn file_name(&self) -> Option<&str> {
let (file_name, _) = self.segments.split_last()?;
Some(file_name)
Expand Down Expand Up @@ -245,7 +252,14 @@ fn page_response(
path: &WikiPagePath,
) -> Result<(ContentType, String), MyError> {
let edit_url = uri!(edit_view(path)).to_string();
let html = render_page(&page.title, &edit_url, &page.body, path.page_breadcrumbs())?;
let overview_url = uri!(overview(path.directory().unwrap())).to_string();
let html = render_page(
&page.title,
&edit_url,
&overview_url,
&page.body,
path.page_breadcrumbs(),
)?;
Ok((ContentType::HTML, html))
}

Expand Down Expand Up @@ -285,13 +299,15 @@ fn page_inner(path: WikiPagePath, w: Wiki) -> Result<WikiPageResponder, MyError>
match path.file_stem_and_extension() {
Some((file_stem, "md")) => {
let create_url = uri!(edit_view(&path));
let overview_url = uri!(overview(path.directory().unwrap())).to_string();
Ok(WikiPageResponder::PagePlaceholder(
response::status::NotFound((
ContentType::HTML,
render_page_placeholder(
file_stem,
&path.to_string(),
&create_url.to_string(),
&overview_url,
path.page_breadcrumbs(),
)
.unwrap(),
Expand Down
12 changes: 12 additions & 0 deletions src/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ struct ViewPageTemplate<'a> {
favicon_png_uri: &'a str,
title: &'a str,
edit_url: &'a str,
overview_url: &'a str,
content: &'a str,
breadcrumbs: Vec<Breadcrumb<'a>>,
}

pub fn render_page(
title: &str,
edit_url: &str,
overview_url: &str,
content: &str,
breadcrumbs: Vec<Breadcrumb<'_>>,
) -> askama::Result<String> {
Expand All @@ -39,6 +41,7 @@ pub fn render_page(
favicon_png_uri,
title,
edit_url,
overview_url,
content,
breadcrumbs,
};
Expand All @@ -54,13 +57,15 @@ struct PagePlaceholderTemplate<'a> {
title: &'a str,
file_path: &'a str,
create_url: &'a str,
overview_url: &'a str,
breadcrumbs: Vec<Breadcrumb<'a>>,
}

pub fn render_page_placeholder(
title: &str,
file_path: &str,
create_url: &str,
overview_url: &str,
breadcrumbs: Vec<Breadcrumb<'_>>,
) -> askama::Result<String> {
let primer_css_uri = &primer_css_uri();
Expand All @@ -71,6 +76,7 @@ pub fn render_page_placeholder(
title,
file_path,
create_url,
overview_url,
breadcrumbs,
};
template.render()
Expand All @@ -86,6 +92,7 @@ struct EditTemplate<'a> {
post_url: &'a str,
view_url: &'a str,
preview_url: &'a str,
overview_url: &'a str,
message_placeholder: Option<String>,
content: &'a str,
breadcrumbs: Vec<Breadcrumb<'a>>,
Expand All @@ -112,6 +119,7 @@ pub fn render_edit_page(
post_url,
view_url,
preview_url,
overview_url: "/overview",
message_placeholder,
content,
breadcrumbs,
Expand Down Expand Up @@ -142,6 +150,7 @@ struct OverviewTemplate<'a> {
breadcrumbs: Vec<Breadcrumb<'a>>,
directories: Vec<DirectoryEntry<'a>>,
files: Vec<DirectoryEntry<'a>>,
overview_url: &'a str,
}

pub fn render_overview(
Expand All @@ -163,6 +172,7 @@ pub fn render_overview(
breadcrumbs,
directories,
files,
overview_url: "/overview",
};
template.render()
}
Expand All @@ -178,6 +188,7 @@ struct SearchResultsTemplate<'a> {
breadcrumbs: Vec<Breadcrumb<'a>>,
prev_url: Option<String>,
next_url: Option<String>,
overview_url: &'a str,
}

pub fn render_search_results(
Expand All @@ -198,6 +209,7 @@ pub fn render_search_results(
documents,
prev_url,
next_url,
overview_url: "/overview",
};
template.render()
}
2 changes: 1 addition & 1 deletion templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<div class="TableObject-item px-2">
<div class="BtnGroup d-flex">
<a class="btn BtnGroup-item btn-sm hide-sm hide-md
minibutton-rename-page" href="/overview">
minibutton-rename-page" href="{{overview_url}}">
Overview
</a>
</div>
Expand Down

0 comments on commit 76d8431

Please sign in to comment.