mirror of
https://github.com/dpc/tagwiki
synced 2025-02-21 03:10:01 +00:00
Better support for journal-like usage.
This commit is contained in:
parent
46d80728c4
commit
6b0d80937a
@ -3,7 +3,7 @@ cache: cargo
|
||||
|
||||
env:
|
||||
global:
|
||||
- PROJECT_NAME=rust-bin-template # CHANGEME
|
||||
- PROJECT_NAME=tagwiki
|
||||
|
||||
matrix:
|
||||
include:
|
||||
|
@ -1,6 +1,5 @@
|
||||
<!---
|
||||
tagwiki-page-id: b1d3dcafcdcd33e04641a64978c68c31
|
||||
|
||||
-->
|
||||
# #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
|
||||
* `alt+enter` or `ctrl+enter` to save
|
||||
|
||||
#help
|
@ -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(),
|
||||
),
|
||||
)));
|
||||
}
|
||||
|
14
src/page.rs
14
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 {
|
||||
|
@ -11,6 +11,7 @@ pub struct PageState {
|
||||
pub path: String,
|
||||
pub edit: bool,
|
||||
pub page: Option<Parsed>,
|
||||
pub original_page_id: Option<crate::page::Id>,
|
||||
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 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<Box<dyn RenderBox>>) -> 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<Box<dyn RenderBox>>) -> 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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user