From 93573799be98dea8c8445a56635a2db2bf117192 Mon Sep 17 00:00:00 2001 From: Erin Nova Date: Sun, 23 Jan 2022 18:54:18 -0500 Subject: [PATCH] Use better(?) way of generating main page --- src/main.rs | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5afa2b6..fabac6c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,15 +6,6 @@ mod io; mod tests; fn construct_main_page() { - // Specify info to go onto the base page - let base_page = build_html::HtmlPage::new() - .with_head_link("favicon.ico", "icon") // Favicon - .with_stylesheet("style.css") // Link stylesheet - .with_meta(vec![("charset", "UTF-8")]) - .with_meta(vec![("name", "viewport"), ("content", "width=device-width, initial-scale=1")]) // Display stuff - .with_meta(vec![("name", "description"), ("content", structures::DESCRIPTION)]) // Add the description - .with_title(structures::TITLE); - // Create the footer let footer = Container::new(ContainerType::Footer) .with_raw(r#"
"#) // Line seperator @@ -24,29 +15,19 @@ fn construct_main_page() { .with_paragraph("Software licensed under the CNPLv7+") .with_paragraph("Recipes under Public Domain"); - // Create the home page - let mut home_page = base_page - .with_header(1, structures::HEADER) - .with_raw(r#"
"#) - .with_paragraph(structures::DESCRIPTION) - .with_paragraph(structures::DETAILS); - // Create (test) lists of tags & recipes let tags: Vec<&str> = vec!["breakfast", "apples", "cheese", "vegan", "vegetarian"]; let recipes = io::db_get_all_recipes(); - home_page.add_raw(r#""#); // Tags in italics + // Create HTML string of tags let mut tags_html = String::new(); // Create custom html string for tags tags_html.push_str(r#"

Tags: "#); // Begin paragraph element for x in tags { // Go through the list of tags tags_html.push_str(format!("{},", x, x).as_str()); // Append the tags as a link } tags_html.push_str(r#"

"#); // End the paragraph - home_page.add_raw(tags_html); // Add the string as html to the page - home_page.add_raw(r#"
"#); // End the italics - // Append recipes - home_page.add_header(2, "Recipes:"); + // Recipes let mut recipes_container = Container::new(ContainerType::UnorderedList); for i in recipes { let mut link = String::new(); @@ -55,8 +36,24 @@ fn construct_main_page() { recipes_container.add_link(link, &i.name); } - home_page.add_container(recipes_container); - home_page.add_container(footer); + // Create home page + let home_page = build_html::HtmlPage::new() + .with_head_link("favicon.ico", "icon") // Favicon + .with_stylesheet("style.css") // Link stylesheet + .with_meta(vec![("charset", "UTF-8")]) + .with_meta(vec![("name", "viewport"), ("content", "width=device-width, initial-scale=1")]) // Display stuff + .with_meta(vec![("name", "description"), ("content", structures::DESCRIPTION)]) // Add the description + .with_title(structures::TITLE) + .with_header(1, structures::HEADER) + .with_raw(r#"
"#) + .with_paragraph(structures::DESCRIPTION) + .with_paragraph(structures::DETAILS) + .with_raw(r#""#) + .with_raw(tags_html) + .with_raw(r#""#) // End the italics + .with_header(2, "Recipes:") + .with_container(recipes_container) + .with_container(footer); // Create the main page file io::write_html(home_page.to_html_string(), "en", None);