Skip to content
This repository has been archived by the owner on Jun 9, 2024. It is now read-only.

Commit

Permalink
Improve things
Browse files Browse the repository at this point in the history
  • Loading branch information
ingalless committed May 2, 2024
1 parent bf0335f commit 7aaaa87
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
.DS_Store
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ comrak = "0.21.0"
maud = { version = "0.26.0", features = ["rocket"] }
serde = { version = "1.0.198", features = ["std", "derive"] }
serde_yaml = "0.9.34"
itertools = "0.12.1"

[dev-dependencies]
tempdir = "0.3.7"
8 changes: 7 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extern crate rocket;
mod compiler;
mod views;

#[derive(Clone)]
#[derive(Clone, PartialEq, PartialOrd)]
pub struct Recipe {
_path: PathBuf,
title: String,
Expand All @@ -27,6 +27,12 @@ impl Recipe {
markdown_to_html(&self.content, &options)
}
}
impl Eq for Recipe {}
impl Ord for Recipe {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.title.cmp(&other.title)
}
}

fn get_recipes(path: String) -> Result<Vec<Recipe>, String> {
let dir = fs::read_dir(path);
Expand Down
57 changes: 39 additions & 18 deletions src/views.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
use std::collections::HashMap;

use itertools::sorted;
use maud::{html, Markup};
use std::collections::HashMap;

use crate::Recipe;

fn nav_link(text: &str, href: &str) -> Markup {
html! {
a href=(href) class="text-teal-600 tracking-tight font-sm" { (text) }
}
}

fn layout(rest: Markup) -> Markup {
html! {
(head())
body class="m-8" {
nav class="my-4 space-x-3 w-full border-b print:hidden" {
a href="/" class="text-blue-500" { "Home" }
a href="/tags" class="text-blue-500" { "Browse by tags" }
body {
nav class="my-4 px-8 w-full flex justify-between items-center print:hidden" {
a href="/" class="text-teal-700 text-lg" { "What's for dinner?" }
div class="space-x-4" {
(nav_link("Browse by tags", "/tags"))
}
}
main {
(rest)
}

footer class="w-full my-12 text-xs text-center" {
code { "</> by Jonny" }
}
}
}
}
Expand All @@ -30,27 +42,36 @@ fn head() -> Markup {

pub fn index(recipes: Vec<Recipe>) -> Markup {
layout(html! {
section class="prose" {
h1 { "No Nonsense Recipes" }
p { "Recipes, without the ads and newsletter popups." }
p { em { "Print friendly too!" } }
ul {
@for recipe in recipes {
li { a href=(format!("/recipes/{}", recipe.title)) { (recipe.title) } }
section class="mt-24 mx-8" {
p class="text-2xl max-w-lg" { "Recipes, without the ads and newsletter popups." }

div class="mt-24" {
h2 class="text-xl mb-2 text-teal-900 font-bold" { "Our Recipes." }
ul class="ml-1" {
@for recipe in sorted(recipes) {
li { a class="text-teal-600 font-bold" href=(format!("/recipes/{}", recipe.title)) { (recipe.title) } }
}
}
}
}

section class="mt-24 p-24 w-full bg-teal-900" {
div class="mx-8 text-teal-50" {
h2 class="text-teal-50 text-xl" { "Why?" }
p class="max-w-xl text-sm" { "Each week I'm asked \"What should we have for dinner this week?\". This question stumps me. \"But it's okay\" I think to myself, \"I can Google it!\" But doing so only results in disappointment as I fight ads, popups and woefully slow websites. This website is an attempt to capture the recipes we enjoy and share them without any of the nonsense that comes with mainstream recipe websites." }
}
}
})
}

pub fn tags(tags: &HashMap<String, Vec<String>>) -> Markup {
layout(html! {
section class="prose-sm" {
section class="prose-sm mx-8" {
@for (tag, recipes) in tags {
h2 { (tag) }
h2 class="text-teal-900 font-bold" { (tag) }
ul {
@for recipe in recipes {
li { a class="text-blue-500" href=(format!("/recipes/{}", recipe)) { (recipe) } }
@for recipe in sorted(recipes) {
li { a class="text-teal-600" href=(format!("/recipes/{}", recipe)) { (recipe) } }
}
}
}
Expand All @@ -60,7 +81,7 @@ pub fn tags(tags: &HashMap<String, Vec<String>>) -> Markup {

pub fn recipe(recipe: &Recipe) -> Markup {
layout(html! {
article class="prose-sm" {
article class="prose-sm mx-8" {
(maud::PreEscaped(recipe.to_html()))
}
})
Expand Down

0 comments on commit 7aaaa87

Please sign in to comment.