From 6b0d80937abfa58b7ae8fe023a3b12df63a491b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Ci=C4=99=C5=BCarkiewicz?= Date: Thu, 14 May 2020 18:29:40 -0700 Subject: [PATCH] Better support for journal-like usage. --- .travis.yml | 2 +- docs/tagwiki-shortcuts.md | 5 +++-- src/main.rs | 3 ++- src/page.rs | 14 ++++++++++++++ src/render.rs | 15 ++++++++++++--- 5 files changed, 32 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2931e4d..2a153a6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ cache: cargo env: global: - - PROJECT_NAME=rust-bin-template # CHANGEME + - PROJECT_NAME=tagwiki matrix: include: diff --git a/docs/tagwiki-shortcuts.md b/docs/tagwiki-shortcuts.md index a9b9e5a..2941081 100644 --- a/docs/tagwiki-shortcuts.md +++ b/docs/tagwiki-shortcuts.md @@ -1,6 +1,5 @@ # #Tagwiki #shortcuts @@ -14,4 +13,6 @@ Available shortcuts: * `alt+/` to jump to the search box, enter to * `ESC` for "going up" / "cancel" * `j`, `k`, `h`, `l` to navigate links -* `alt+enter` or `ctrl+enter` to save \ No newline at end of file +* `alt+enter` or `ctrl+enter` to save + +#help \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index cddd4a4..adcaf7f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -269,6 +269,7 @@ async fn handle_get( } let tags = path_to_tags(&path); let page_state = render::PageState { + original_page_id: query.id.clone(), page: None, edit: query.edit.is_some(), path: path.as_str().to_string(), @@ -302,7 +303,7 @@ async fn handle_get( render::post_list( page_state, compact_results.tags.into_iter(), - compact_results.direct_hit_pages.into_iter(), + results.matching_pages.into_iter(), ), ))); } diff --git a/src/page.rs b/src/page.rs index ab3264d..a906e83 100644 --- a/src/page.rs +++ b/src/page.rs @@ -126,6 +126,20 @@ fn parse_title(body: &str) -> String { .map(|m| m.get(1).expect("a value").as_str().trim().to_string()) .next() .unwrap_or_else(|| "".to_string()); + let title = if title == "" { + lazy_static! { + static ref RE: regex::Regex = + regex::Regex::new(r"[[:space:]]*(.*?)[\.\n]").expect("correct regex"); + } + + RE.captures_iter(&body) + .map(|m| m.get(1).expect("a value").as_str().trim().to_string()) + .next() + .unwrap_or_else(|| "".to_string()) + } else { + title + }; + if title == "" { "Untitled".to_string() } else { diff --git a/src/render.rs b/src/render.rs index d897763..f9365f5 100644 --- a/src/render.rs +++ b/src/render.rs @@ -11,6 +11,7 @@ pub struct PageState { pub path: String, pub edit: bool, pub page: Option, + pub original_page_id: Option, pub subtags: Vec<(String, usize)>, } @@ -37,7 +38,7 @@ pub fn page(page_state: PageState) -> Box { let page_state_clone = page_state.clone(); let sub_pages = owned_html! { @ if !page_state_clone.subtags.is_empty() { - h1 { : "Subpages" } + h1 { : "Subtags" } ul { @ for tag in &page_state_clone.subtags { li { @@ -89,6 +90,7 @@ pub fn page_editing_view(page_state: PageState) -> impl RenderOnce { pub fn menu(page_state: PageState, subform: Option>) -> impl RenderOnce { let id = page_state.page.map(|p| p.id().to_owned()); let edit = page_state.edit; + let original_page_id = page_state.original_page_id; let path_tags: String = page_state .path .split("/") @@ -119,7 +121,11 @@ pub fn menu(page_state: PageState, subform: Option>) -> impl : " "; } } else { - a(href="..",class="pure-button", id="up-button") { : "Up" } + @ if let Some(_id) = original_page_id { + a(href=".", class="pure-button", id="up-button") { : "Up" } + } else { + a(href="..", class="pure-button", id="up-button") { : "Up" } + } : " "; } @ if edit { @@ -179,13 +185,16 @@ pub fn post_list( owned_html! { : menu; div(id="page-content") { - h1 { : "Subpages" } + h1 { : "Pages" } ul(id="index") { @ for post in posts { li { a(href=format!("./?id={}", post.id)) : post.title } } + } + h1 { : "Subtags" } + ul(id="index") { @ for tag in unmatched_tags { li { a(href=format!("./{}/", tag.0)) : format!("{} ({})", tag.0, tag.1)