Added a random poem button.
This commit is contained in:
parent
5490393678
commit
db2d86c5ee
2
public/styles/tailwind.min.css
vendored
2
public/styles/tailwind.min.css
vendored
File diff suppressed because one or more lines are too long
@ -17,6 +17,7 @@ console_error_panic_hook = "0.1.7"
|
|||||||
log = "0.4.17"
|
log = "0.4.17"
|
||||||
dioxus-helmet = "0.2.4"
|
dioxus-helmet = "0.2.4"
|
||||||
dioxus-use-storage = "0.3.0"
|
dioxus-use-storage = "0.3.0"
|
||||||
|
rand = "0.8.5"
|
||||||
|
|
||||||
[dependencies.serde]
|
[dependencies.serde]
|
||||||
version = "1.0.160"
|
version = "1.0.160"
|
||||||
|
@ -74,6 +74,7 @@ pub mod void_app {
|
|||||||
ButtonGroup {
|
ButtonGroup {
|
||||||
NavigationButton { title: "See Latest Entry".to_string(), slug: helpers::get_latest_entry("".to_string()), user_prefs: user_prefs.clone() }
|
NavigationButton { title: "See Latest Entry".to_string(), slug: helpers::get_latest_entry("".to_string()), user_prefs: user_prefs.clone() }
|
||||||
NavigationButton { title: "See Oldest Entry".to_string(), slug: helpers::get_oldest_entry("".to_string()), user_prefs: user_prefs.clone() }
|
NavigationButton { title: "See Oldest Entry".to_string(), slug: helpers::get_oldest_entry("".to_string()), user_prefs: user_prefs.clone() }
|
||||||
|
NavigationButton { title: "See A Random Entry".to_string(), slug: helpers::get_random_entry(), user_prefs: user_prefs.clone() }
|
||||||
NavigationButton { title: "See All Entries".to_string(), slug: "/poems".to_string(), user_prefs: user_prefs.clone() }
|
NavigationButton { title: "See All Entries".to_string(), slug: "/poems".to_string(), user_prefs: user_prefs.clone() }
|
||||||
}
|
}
|
||||||
Footer { theme: user_prefs.clone().get_theme(), font: user_prefs.get_font() }
|
Footer { theme: user_prefs.clone().get_theme(), font: user_prefs.get_font() }
|
||||||
@ -118,6 +119,7 @@ pub mod void_app {
|
|||||||
ButtonGroup {
|
ButtonGroup {
|
||||||
NavigationButton { title: "Oldest".to_string(), slug: helpers::get_oldest_entry(slug.clone()), user_prefs: user_prefs.clone() }
|
NavigationButton { title: "Oldest".to_string(), slug: helpers::get_oldest_entry(slug.clone()), user_prefs: user_prefs.clone() }
|
||||||
NavigationButton { title: "Previous".to_string(), slug: helpers::get_previous_entry(slug.clone()), user_prefs: user_prefs.clone() }
|
NavigationButton { title: "Previous".to_string(), slug: helpers::get_previous_entry(slug.clone()), user_prefs: user_prefs.clone() }
|
||||||
|
NavigationButton { title: "Random".to_string(), slug: helpers::get_random_entry(), user_prefs: user_prefs.clone() }
|
||||||
NavigationButton { title: "Next".to_string(), slug: helpers::get_next_entry(slug.clone()), user_prefs: user_prefs.clone() }
|
NavigationButton { title: "Next".to_string(), slug: helpers::get_next_entry(slug.clone()), user_prefs: user_prefs.clone() }
|
||||||
NavigationButton { title: "Latest".to_string(), slug: helpers::get_latest_entry(slug.clone()), user_prefs: user_prefs.clone() }
|
NavigationButton { title: "Latest".to_string(), slug: helpers::get_latest_entry(slug.clone()), user_prefs: user_prefs.clone() }
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use rust_embed::RustEmbed;
|
|
||||||
use markdown::Options;
|
use markdown::Options;
|
||||||
|
use rand::seq::SliceRandom;
|
||||||
|
use rust_embed::RustEmbed;
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
|
|
||||||
#[derive(RustEmbed)]
|
#[derive(RustEmbed)]
|
||||||
@ -11,9 +12,13 @@ struct OtherData;
|
|||||||
struct Poems;
|
struct Poems;
|
||||||
|
|
||||||
pub fn get_homepage_paragraph() -> String {
|
pub fn get_homepage_paragraph() -> String {
|
||||||
let homepage_paragraph_content = OtherData::get("homepage.md").expect("Found homepage paragraph.");
|
let homepage_paragraph_content =
|
||||||
let homepage_paragraph_to_string = std::str::from_utf8(homepage_paragraph_content.data.as_ref()).expect("Homepage file is valid UTF-8");
|
OtherData::get("homepage.md").expect("Found homepage paragraph.");
|
||||||
let test = markdown::to_html_with_options(homepage_paragraph_to_string, &Options::gfm()).unwrap();
|
let homepage_paragraph_to_string =
|
||||||
|
std::str::from_utf8(homepage_paragraph_content.data.as_ref())
|
||||||
|
.expect("Homepage file is valid UTF-8");
|
||||||
|
let test =
|
||||||
|
markdown::to_html_with_options(homepage_paragraph_to_string, &Options::gfm()).unwrap();
|
||||||
test
|
test
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,3 +119,14 @@ pub fn get_next_entry(current: String) -> String {
|
|||||||
None => format!("/poems/{current}"),
|
None => format!("/poems/{current}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_random_entry() -> String {
|
||||||
|
let poem_list = get_poem_list();
|
||||||
|
let mut rng = rand::thread_rng();
|
||||||
|
let random_entry = poem_list
|
||||||
|
.choose(&mut rng)
|
||||||
|
.expect("Got a valid entry")
|
||||||
|
.1
|
||||||
|
.clone();
|
||||||
|
format!("/poems/{random_entry}")
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user