feat: add home page

This commit is contained in:
Price Hiller 2023-08-29 15:12:04 -05:00
parent 7b1dfb2b56
commit 41962672c5
Signed by: Price
SSH Key Fingerprint: SHA256:Y4S9ZzYphRn1W1kbJerJFO6GGsfu9O70VaBSxJO7dF8
5 changed files with 65 additions and 16 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 424 KiB

View File

@ -0,0 +1,26 @@
<!doctype html>
<html lang="en">
<head>
<title>Home</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="/style/style.css" rel="stylesheet" />
</head>
{% include "nav.html" %}
<body>
<p>Hello! I'm Price, a Linux user and Neovim addict. This necessarily means I am either bald or balding. Oh, also I
sometimes write Rust. This page is generated from a Rust static site generator I wrote, it's not very good but it
makes me happy. I'm a big fan of reproducible systems and infrastructure, though I'm not sure if I'm sold on NixOS
just yet. I hold it as a dumb source of pride that I can wipe my laptop and have everything back to normal within 20
minutes depending on how nice Github's rate limit wants to play. Hit me up at my <a
href="mailto:price@orion-technologies.io">email</a> if you want to get in contact.</p>
<p>Maggie and Ellie say hi: <img src="/assets/static/maggie-ellie-comfy.jpeg" alt="Black labrador and yellow
labrador dogs sleeping on bed with blankets over them" width="700"></p>
</body>
{% include "footer.html" %}
</html>

View File

@ -1,14 +1,14 @@
use anyhow::{Context, Ok};
use clap::Parser;
use blog::{
markdown::article::{Article, FrontMatter},
page_gen::{
articles::Articles,
tags::{TagArticles, Tags},
tags::{TagArticles, Tags}, home::Home,
},
TemplateRenderer,
};
use std::{collections::HashMap, path::PathBuf};
use clap::Parser;
use std::{collections::HashMap, fs::copy, path::PathBuf};
use tera::Tera;
#[derive(Parser, Debug)]
@ -30,8 +30,8 @@ struct Args {
fn main() -> anyhow::Result<()> {
let comrak_settings = blog::markdown::MDComrakSettings::default().unwrap();
let posts_dir = PathBuf::from(concat!(env!("CARGO_MANIFEST_DIR"), "/posts/"));
let posts_walkable = std::fs::read_dir(&posts_dir)
.context("Unable to read posts directory!")?;
let posts_walkable =
std::fs::read_dir(&posts_dir).context("Unable to read posts directory!")?;
let out_path = PathBuf::from(concat!(env!("CARGO_MANIFEST_DIR"), "/out"));
std::fs::create_dir_all(&out_path)
.context(format!("Unable to create out directory at '{out_path:?}'"))?;
@ -78,6 +78,14 @@ fn main() -> anyhow::Result<()> {
}
println!("Finished rendering Article templates");
println!("Rendering Articles Page");
let articles_page = Articles::new(&article_links)
.render_template(&tera)
.context("Main Articles Page Rendering Error")?;
let articles_write_path = &out_path.join("articles.html");
write_file(&articles_write_path, articles_page.as_bytes())?;
println!("Finished Rendering Articles Page");
println!("Rendering Tags Page");
let tags_page = Tags::new(&detected_tags_article.keys().collect::<Vec<&String>>())
.render_template(&tera)
@ -87,14 +95,6 @@ fn main() -> anyhow::Result<()> {
write_file(&tags_write_path, tags_page.as_bytes())?;
println!("Finished Rendering Tags Page");
println!("Rendering Articles Page");
let articles_page = Articles::new(&article_links)
.render_template(&tera)
.context("Main Articles Page Rendering Error")?;
let articles_write_path = &out_path.join("articles.html");
write_file(&articles_write_path, articles_page.as_bytes())?;
println!("Finished Rendering Articles Page");
println!("Rendering Individual Tag Pages");
for (tag, article_link) in detected_tags_article.iter() {
println!("Rendering Tag Page: {}", &tag);
@ -106,9 +106,21 @@ fn main() -> anyhow::Result<()> {
}
println!("Finished rendering Individual Tag Pages");
println!("Rendering Home Page");
let home_page = Home::render_template(&Home { }, &tera)?;
write_file(&out_path.join("home.html"), home_page.as_bytes())?;
println!("Finished rendering Home Page");
let base_asset_dir = PathBuf::from(concat!(env!("CARGO_MANIFEST_DIR"), "/assets/"));
copy_recursive(&base_asset_dir.join("style/"), &out_path.join("style"))?;
copy_recursive(&posts_dir.join("assets/"), &out_path.join("articles/assets"))?;
copy_recursive(
&base_asset_dir.join("static/"),
&out_path.join("assets/static/"),
)?;
copy_recursive(
&posts_dir.join("assets/"),
&out_path.join("articles/assets"),
)?;
Ok(())
}
@ -139,4 +151,4 @@ fn write_file(file_path: &PathBuf, contents: &[u8]) -> anyhow::Result<()> {
}
std::fs::write(file_path, contents).context(format!("Failed to write to {file_path:?}"))
}
}

10
src/page_gen/home.rs Normal file
View File

@ -0,0 +1,10 @@
use crate::TemplateRenderer;
pub struct Home {}
impl TemplateRenderer for Home {
fn render_template(&self, tera: &tera::Tera) -> anyhow::Result<String> {
let empty_context = tera::Context::new();
Ok(tera.render("home.html", &empty_context)?)
}
}

View File

@ -3,9 +3,10 @@ use serde::Serialize;
pub mod articles;
pub mod tags;
pub mod home;
#[derive(Serialize)]
pub struct ArticleLink<'a> {
frontmatter: &'a FrontMatter,
link: &'a String,
}
}