Better support for journal-like usage.

This commit is contained in:
Dawid Ciężarkiewicz 2020-05-14 18:29:40 -07:00
parent 46d80728c4
commit 6b0d80937a
5 changed files with 32 additions and 7 deletions

View File

@ -3,7 +3,7 @@ cache: cargo
env: env:
global: global:
- PROJECT_NAME=rust-bin-template # CHANGEME - PROJECT_NAME=tagwiki
matrix: matrix:
include: include:

View File

@ -1,6 +1,5 @@
<!--- <!---
tagwiki-page-id: b1d3dcafcdcd33e04641a64978c68c31 tagwiki-page-id: b1d3dcafcdcd33e04641a64978c68c31
--> -->
# #Tagwiki #shortcuts # #Tagwiki #shortcuts
@ -14,4 +13,6 @@ Available shortcuts:
* `alt+/` to jump to the search box, enter to * `alt+/` to jump to the search box, enter to
* `ESC` for "going up" / "cancel" * `ESC` for "going up" / "cancel"
* `j`, `k`, `h`, `l` to navigate links * `j`, `k`, `h`, `l` to navigate links
* `alt+enter` or `ctrl+enter` to save * `alt+enter` or `ctrl+enter` to save
#help

View File

@ -269,6 +269,7 @@ async fn handle_get(
} }
let tags = path_to_tags(&path); let tags = path_to_tags(&path);
let page_state = render::PageState { let page_state = render::PageState {
original_page_id: query.id.clone(),
page: None, page: None,
edit: query.edit.is_some(), edit: query.edit.is_some(),
path: path.as_str().to_string(), path: path.as_str().to_string(),
@ -302,7 +303,7 @@ async fn handle_get(
render::post_list( render::post_list(
page_state, page_state,
compact_results.tags.into_iter(), compact_results.tags.into_iter(),
compact_results.direct_hit_pages.into_iter(), results.matching_pages.into_iter(),
), ),
))); )));
} }

View File

@ -126,6 +126,20 @@ fn parse_title(body: &str) -> String {
.map(|m| m.get(1).expect("a value").as_str().trim().to_string()) .map(|m| m.get(1).expect("a value").as_str().trim().to_string())
.next() .next()
.unwrap_or_else(|| "".to_string()); .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 == "" { if title == "" {
"Untitled".to_string() "Untitled".to_string()
} else { } else {

View File

@ -11,6 +11,7 @@ pub struct PageState {
pub path: String, pub path: String,
pub edit: bool, pub edit: bool,
pub page: Option<Parsed>, pub page: Option<Parsed>,
pub original_page_id: Option<crate::page::Id>,
pub subtags: Vec<(String, usize)>, pub subtags: Vec<(String, usize)>,
} }
@ -37,7 +38,7 @@ pub fn page(page_state: PageState) -> Box<dyn RenderBox> {
let page_state_clone = page_state.clone(); let page_state_clone = page_state.clone();
let sub_pages = owned_html! { let sub_pages = owned_html! {
@ if !page_state_clone.subtags.is_empty() { @ if !page_state_clone.subtags.is_empty() {
h1 { : "Subpages" } h1 { : "Subtags" }
ul { ul {
@ for tag in &page_state_clone.subtags { @ for tag in &page_state_clone.subtags {
li { li {
@ -89,6 +90,7 @@ pub fn page_editing_view(page_state: PageState) -> impl RenderOnce {
pub fn menu(page_state: PageState, subform: Option<Box<dyn RenderBox>>) -> impl RenderOnce { pub fn menu(page_state: PageState, subform: Option<Box<dyn RenderBox>>) -> impl RenderOnce {
let id = page_state.page.map(|p| p.id().to_owned()); let id = page_state.page.map(|p| p.id().to_owned());
let edit = page_state.edit; let edit = page_state.edit;
let original_page_id = page_state.original_page_id;
let path_tags: String = page_state let path_tags: String = page_state
.path .path
.split("/") .split("/")
@ -119,7 +121,11 @@ pub fn menu(page_state: PageState, subform: Option<Box<dyn RenderBox>>) -> impl
: " "; : " ";
} }
} else { } 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 { @ if edit {
@ -179,13 +185,16 @@ pub fn post_list(
owned_html! { owned_html! {
: menu; : menu;
div(id="page-content") { div(id="page-content") {
h1 { : "Subpages" } h1 { : "Pages" }
ul(id="index") { ul(id="index") {
@ for post in posts { @ for post in posts {
li { li {
a(href=format!("./?id={}", post.id)) : post.title a(href=format!("./?id={}", post.id)) : post.title
} }
} }
}
h1 { : "Subtags" }
ul(id="index") {
@ for tag in unmatched_tags { @ for tag in unmatched_tags {
li { li {
a(href=format!("./{}/", tag.0)) : format!("{} ({})", tag.0, tag.1) a(href=format!("./{}/", tag.0)) : format!("{} ({})", tag.0, tag.1)