83 lines
3.0 KiB
Rust
83 lines
3.0 KiB
Rust
use build_html::{self, Html, HtmlContainer, ContainerType, Container};
|
|
use uuid::Uuid;
|
|
|
|
mod structures;
|
|
mod io;
|
|
mod tests;
|
|
|
|
fn construct_main_page() {
|
|
// Create the footer
|
|
let footer = Container::new(ContainerType::Footer)
|
|
.with_raw(r#"<hr>"#) // Line seperator
|
|
.with_link("/", "home") // Link to the root page
|
|
.with_link("/rss.xml", "rss") // Link the the Atom feed
|
|
// License info
|
|
.with_paragraph("Software licensed under the CNPLv7+")
|
|
.with_paragraph("Recipes under Public Domain");
|
|
|
|
// Create (test) lists of tags & recipes
|
|
let tags: Vec<&str> = vec!["breakfast", "apples", "cheese", "vegan", "vegetarian"];
|
|
let recipes = io::db_get_all_recipes();
|
|
|
|
// Create HTML string of tags
|
|
let mut tags_html = String::new(); // Create custom html string for tags
|
|
tags_html.push_str(r#"<p>Tags: "#); // Begin paragraph element
|
|
for x in tags { // Go through the list of tags
|
|
tags_html.push_str(format!("<a href='{}'>{}</a>,", x, x).as_str()); // Append the tags as a link
|
|
}
|
|
tags_html.push_str(r#"</p>"#); // End the paragraph
|
|
|
|
// Recipes
|
|
let mut recipes_container = Container::new(ContainerType::UnorderedList);
|
|
for i in recipes {
|
|
let mut link = String::new();
|
|
link.push_str("/");
|
|
link.push_str(&i.shortcode);
|
|
recipes_container.add_link(link, &i.name);
|
|
}
|
|
|
|
// 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#"<hr>"#)
|
|
.with_paragraph(structures::DESCRIPTION)
|
|
.with_paragraph(structures::DETAILS)
|
|
.with_raw(r#"<i>"#)
|
|
.with_raw(tags_html)
|
|
.with_raw(r#"</i>"#) // 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);
|
|
}
|
|
|
|
fn rebuild() {
|
|
construct_main_page();
|
|
for i in io::db_get_all_recipes() {
|
|
i.construct_page();
|
|
}
|
|
io::write_feed("en");
|
|
}
|
|
|
|
fn main() {
|
|
/*
|
|
let full_recipe = Recipe::new(
|
|
"Full Recipe".to_string(),
|
|
(3, Minutes),
|
|
(4, Hours),
|
|
7,
|
|
vec![(3, Cups, "flour".to_string()), (4, Tablespoons, "sugar".to_string()), (1, Cups, "water".to_string())],
|
|
vec!["Mix flour and sugar in a bowl".to_string(), "Slowly add water".to_string(), "Bake in the oven for 4 hours".to_string()],
|
|
"Erin Nova".to_string(),
|
|
Some(vec![Tag('#', "meow".to_string()), Tag('#', "gay".to_string())]));*/
|
|
rebuild();
|
|
}
|