diff --git a/src/html/api.rs b/src/html/api.rs index dda7421..d9c0aca 100644 --- a/src/html/api.rs +++ b/src/html/api.rs @@ -1,9 +1,34 @@ -use axum::{routing::get, Router}; +use super::blog::get_articles_as_links_list; +use crate::html::AppState; +use axum::{response::IntoResponse, routing::get, Extension, Router}; pub fn get_router() -> Router { - Router::new().route("/hello", get(hello_from_the_server)) + Router::new() + .route("/hello", get(hello_from_the_server)) + .route("/articles", get(blogs)) + .route("/recentarticles", get(recent_blogs)) } async fn hello_from_the_server() -> &'static str { "Hello!" } + +async fn blogs(state: Extension) -> impl IntoResponse { + let db_pool = &state.db; + let article_list: Vec = get_articles_as_links_list(db_pool) + .await + .expect("couldn't get articles"); + + article_list.join("\n") +} + +async fn recent_blogs(state: Extension) -> impl IntoResponse { + let db_pool = &state.db; + let article_list: Vec = get_articles_as_links_list(db_pool) + .await + .expect("couldn't get articles"); + + let (article_head, _) = article_list.split_at(5); + + article_head.join("\n") +} diff --git a/src/html/blog.rs b/src/html/blog.rs index 35bd148..7d745b5 100644 --- a/src/html/blog.rs +++ b/src/html/blog.rs @@ -6,7 +6,7 @@ use axum::{ use sqlx::PgPool; use std::{collections::HashMap, error::Error}; -use super::{root::AppState, ArticleTemplate, HtmlTemplate}; +use super::{get_page, AppState, ArticleTemplate, HtmlTemplate}; pub fn get_router() -> Router { Router::new() @@ -14,21 +14,8 @@ pub fn get_router() -> Router { .route("/:article", get(article)) } -async fn blog(state: Extension) -> impl IntoResponse { - let db_pool = &state.db; - let list: Vec = get_articles_as_links_list(db_pool) - .await - .expect("couldn't get articles"); - let template = BlogTemplate { - article_list: list.join("\n"), - }; - HtmlTemplate(template) -} - -#[derive(Template)] -#[template(path = "blog.html")] -struct BlogTemplate { - article_list: String, +async fn blog(state: Extension) -> Result { + get_page(&state.db, "blog").await } #[derive(Template)] diff --git a/src/html/garden.rs b/src/html/garden.rs new file mode 100644 index 0000000..1617a3e --- /dev/null +++ b/src/html/garden.rs @@ -0,0 +1,24 @@ +use axum::{ + extract::{Extension, Path}, http::StatusCode, response::IntoResponse, routing::{get, Router} +}; +use std::collections::HashMap; + +use super::{get_page, AppState}; + +pub fn get_router() -> Router { + Router::new() + .route("/", get(garden)) + .route("/:page", get(page)) +} + +async fn garden(state: Extension) -> Result { + get_page(&state.db, "garden").await +} + +async fn page( + state: Extension, + Path(params): Path>, +) -> Result { + let page_id: &String = params.get("page").unwrap(); + get_page(&state.db, page_id).await +} diff --git a/src/html/mod.rs b/src/html/mod.rs index d65164a..e89e05c 100644 --- a/src/html/mod.rs +++ b/src/html/mod.rs @@ -1,12 +1,20 @@ use askama::Template; +use achubb_database::data::page::Page; use axum::{ http::StatusCode, response::{Html, IntoResponse, Response}, }; -pub mod root; -pub mod blog; -pub mod projects; +use sqlx::PgPool; + pub mod api; +pub mod blog; +pub mod garden; +pub mod root; + +#[derive(Clone)] +pub struct AppState { + pub db: PgPool, +} /// A wrapper type that we'll use to encapsulate HTML parsed by askama into valid HTML for axum to serve. pub struct HtmlTemplate(pub T); @@ -37,3 +45,23 @@ pub struct ArticleTemplate { footer: String, content: String, } + +#[derive(Template)] +#[template(path = "page.html")] +pub struct PageTemplate { + content: String, +} + +pub async fn get_page(db: &PgPool, path: &str) -> Result { + let reference: String = path.to_string(); + let page: Page = match Page::read_by_reference(db, &reference).await { + Ok(a) => *a, + Err(_) => return Err(StatusCode::NOT_FOUND), + }; + + let template = PageTemplate { + content: page.content, + }; + Ok(HtmlTemplate(template)) +} + diff --git a/src/html/root.rs b/src/html/root.rs index 662faaf..ac2437f 100644 --- a/src/html/root.rs +++ b/src/html/root.rs @@ -1,6 +1,6 @@ -use crate::html::{api, blog, projects, HtmlTemplate}; -use askama::Template; +use crate::html::{api, blog, AppState}; use axum::{ + http::StatusCode, response::{IntoResponse, Redirect}, routing::{get, Router}, Extension, @@ -8,12 +8,7 @@ use axum::{ use sqlx::PgPool; use tower_http::services::ServeDir; -use super::{blog::get_articles_as_links_list, projects::get_projects_as_links_list}; - -#[derive(Clone)] -pub struct AppState { - pub db: PgPool, -} +use super::{garden, get_page}; pub fn get_router(pool: PgPool) -> Router { let assets_path = std::env::current_dir().unwrap(); @@ -21,7 +16,7 @@ pub fn get_router(pool: PgPool) -> Router { Router::new() .nest("/api", api::get_router()) .nest("/blog", blog::get_router()) - .nest("/projects", projects::get_router()) + .nest("/garden", garden::get_router()) .nest_service( "/assets", ServeDir::new(format!("{}/assets", assets_path.to_str().unwrap())), @@ -38,66 +33,22 @@ pub fn get_router(pool: PgPool) -> Router { .layer(Extension(state)) } -async fn home(state: Extension) -> impl IntoResponse { - let db_pool = &state.db; - let article_list: Vec = get_articles_as_links_list(db_pool) - .await - .expect("couldn't get articles"); - - let (article_head, _) = article_list.split_at(5); - - let project_list: Vec = get_projects_as_links_list(db_pool) - .await - .expect("Couldn't get projects"); - - let (project_head, _) = project_list.split_at(5); - - let template = HomeTemplate { - recent_blogs: article_head.join("\n"), - recent_projects: project_head.join("\n"), - }; - HtmlTemplate(template) +async fn home(state: Extension) -> Result { + get_page(&state.db, "home").await } -#[derive(Template)] -#[template(path = "home.html")] -struct HomeTemplate { - recent_blogs: String, - recent_projects: String, +async fn now(state: Extension) -> Result { + get_page(&state.db, "now").await } -async fn now() -> impl IntoResponse { - let template = NowTemplate {}; - HtmlTemplate(template) +async fn about(state: Extension) -> Result { + get_page(&state.db, "about").await } -#[derive(Template)] -#[template(path = "now.html")] -struct NowTemplate {} - -async fn about() -> impl IntoResponse { - let template = AboutTemplate {}; - HtmlTemplate(template) +async fn contact(state: Extension) -> Result { + get_page(&state.db, "contact").await } -#[derive(Template)] -#[template(path = "about.html")] -struct AboutTemplate {} - -async fn contact() -> impl IntoResponse { - let template = ContactTemplate {}; - HtmlTemplate(template) +async fn uses(state: Extension) -> Result { + get_page(&state.db, "uses").await } - -#[derive(Template)] -#[template(path = "contact.html")] -struct ContactTemplate {} - -async fn uses() -> impl IntoResponse { - let template = UsesTemplate {}; - HtmlTemplate(template) -} - -#[derive(Template)] -#[template(path = "uses.html")] -struct UsesTemplate {} diff --git a/templates/about.html b/templates/about.html deleted file mode 100644 index 1686378..0000000 --- a/templates/about.html +++ /dev/null @@ -1,60 +0,0 @@ - -{% extends "base.html" %} - -{% block content %} -

General

-

- My greatest joy in life is learning new things. - Early on I leaned almost exclusively toward the sciences. - I still trend that way but my interests have broadened considerably in recent years. - Philosophy, science, business, programming, religion, psychology, anything that helps me understand the world better. - My specific fascination for the last four years has been computers. - They are an unbelievably amazing intersection of so many sciences both physically and in the logic of programming. - They also provide the perfect platform for learning and creating. -

-

- A close second is making things and tinkering. - There is a satisfaction that comes from making or changing something with your own hands that is unique. - That is part of the reason that I switched my website from WordPress to something written by hand. - Even if I can't make something as good as what I could purchase, it is still mine. - I know it intimately and can build or tweak whatever it is to fit my needs exactly. -

-

- I read extensively and while my reading list is only getting longer I am always looking for new book recommendations. - I listen to a lot of music, almost all styles these days. - With a preference for instumentally complex music. -

-

- I am quite introverted and enjoy interacting with others one on one. - I find that my focus on learning things deeply extends to how I interact. - One long deep conversation is more pleasant to me than a dozen short ones. - I am more interested in talking about each other and our own interests than current events. - It does make interactions more work but personally I find it very fulfilling. -

-

- I have recently discovered just how important independence is to me. - I think that removing the worry of money from day to day life has allowed me to focus on what is important to me in a broader sense. - I think that it is too easy to give up control of things that are important. - To rely on external things that I have no control over. -

-

- I have been working lately to slowly move my digital life away from cloud services. - Hosting my own calendar, contacts, email, backups. - There is a sense of peace with that. - Knowing that I have control over things that are important to me. - It a stress that I had gotten used to and barely noticed. - Like not sleeping quite enough for a long time. - Didn't notice the effect until it was gone. -

-

- I would like to do the same with more of life eventually. - Work, food, electricity. - Try to make and fix things instead of buying or replacing them. - That thought feels right. -

-

- It and other feelings about the best way for me to live are things that I am constantly exploring. - Trying to live more in line with what feels right internally. - A wonderful exploration and adventure. -

-{% endblock %} diff --git a/templates/base.html b/templates/base.html index 8c5eec9..309a27b 100644 --- a/templates/base.html +++ b/templates/base.html @@ -4,6 +4,7 @@ + Awstin {% block head %}{% endblock %} @@ -35,13 +36,13 @@ -
  • - - Projects +
  • + + Garden - + diff --git a/templates/contact.html b/templates/contact.html deleted file mode 100644 index 1fc8190..0000000 --- a/templates/contact.html +++ /dev/null @@ -1,9 +0,0 @@ - -{% extends "base.html" %} - -{% block content %} -

    - I am always happy to meet new people. - I can be contacted by email at awstin@achubb.com. -

    -{% endblock %} diff --git a/templates/home.html b/templates/home.html deleted file mode 100644 index 6048f7b..0000000 --- a/templates/home.html +++ /dev/null @@ -1,71 +0,0 @@ - -{% extends "base.html" %} - -{% block content %} -
    -

    Awstin Chubb

    -

    About me

    -

    Short version

    -

    - I have been a gymnastics coach, hot tub technician, carpenter (saunas), chemist, and now software developer work wise. - I am an athlete, tinkerer, and lifelong student of all things. -

    -

    - I have a deep and abiding interest in how the world works and how best I can live within it. - Over the last year I have really discovered the importance of independence to me. - Of having minimal reliance on external systems that I don't have any control over. - Much of my time is slowly working to bring more of this into my life. -

    -

    - Born in Ottawa and living in Toronto, Canada. -

    -

    - If you are interested in reading more see my about page. -

    -

    - -
    - -

    What am I up to?

    -
    -

    - -
    -

    Blog

    -

    Most Recent

    -
      - {{recent_blogs|safe}} -
    - -

    - For the full list see my Blog. -

    - -

    - -
    -

    Projects

    -

    Recent

    -
      - {{recent_projects|safe}} -
    - -

    - See my projects page for all my projects. -

    -

    - -
    -

    Uses

    -

    - Some things that I use on a regular basis if not daily. -

    -

    - -
    -

    Contact Me

    -

    - Here is my contact information. -

    -

    -{% endblock %} diff --git a/templates/now.html b/templates/now.html deleted file mode 100644 index 025618b..0000000 --- a/templates/now.html +++ /dev/null @@ -1,82 +0,0 @@ - -{% extends "base.html" %} - -{% block content %} -

    - Last updated: 2024-07-11 -

    -

    Work

    -

    - Still in Toronto, still working in software at Amazon. - My team writes tools to help automate and test new machine setups. - Just got a promotion from L4 (entry level software engineer) to L5 (regular software engineer). - Was not something that I chased but there is an "up or out" when in the L4 position so it is really nice to have that worry off my mind. -

    -

    Life

    -

    - I am engaged and living with the most wonderful woman I have ever met. - Planning our wedding (slowly bit by bit) for next spring. -

    -

    - My brother is getting married soon, so we are preparing to travel back to my hometown for that in a week. - He is the happiest I have ever seen him and I am so grateful for that. -

    -

    - Actually planning for the long term financially now that I am lucky enough to have a job that leaves me with money to save and invest after the bills are payed. - It still feels new to have that cushion and to plan long term, definitely enjoying it. -

    -

    Brazilian Jiu-Jitsu

    -

    - Got my blue belt just before the new year. - Still training as much as I can. - The team here at GB Toronto has become an external family. - I am so grateful for the community. -

    -

    - Competiton is this Saturday. - I have made the weight, however they opened the weigh in on Friday evening which is unusual. - Means that I can cut water weight aggressively and re-hydrate before the first match so I don't feel terrible. - So putting a little of it back on. -

    -

    - We have a lot of people from the school going. - It is going to be a very fun day. -

    -

    Learning

    -

    - I am working to learn Japanese and Portuguese on Duolingo. - I love the program and it is 100% worth paying for, but the fact that even when paying it keeps asking for ratings, putting widgets on my home screen, or turning on notifications bothers me. - You already have my money now please don't bother me. - Finding the lessons really helpful. -

    -

    - I started studying for the CompTIA ITF+ certification test but that has fallen off in the last little bit. - I have been learning hardware and networking playing with my home network and a small homelab consisting of my NAS and a few raspberry pis. - Just not very stoked on going for certifications and much prefer to learn this stuff by just playing around with it than reading textbooks and doing practice questions. -

    -

    Tinkering

    -

    - Have just finished setting up some self hosted software. - Firefly for budgeting and personal finance. - Pihole for local network addblocking and as a DNS server. - Syncthing to keep all my devices synchronized. - Slowly working to have more and more of my digital life hosted myself, and it feels good to have control over these things even though it is more work. -

    -

    - This website is the main thing that I have been working with. - I rebuilt it using HTMX and a Rust backend. - Added a uses page recently with just a list of the common things that I use every day. - Going to add links and other curated stuff next. - I love these pages on other personal websites and want to contribute to that. -

    -

    - I am looking at restructuring the site into more of a garden than a stream. - It is a structure that I find much more interesting and fits with how I want to build much more. - Treating most things as timeless and growing as opposed to a strict timeline. - It is how I keep most of my personal notes, dates more of as reference than things needing to be in order. - Will see how that works. -

    -

    - Awstin -

    -{% endblock %} diff --git a/templates/projects.html b/templates/page.html similarity index 57% rename from templates/projects.html rename to templates/page.html index e74a50d..7b23ea9 100644 --- a/templates/projects.html +++ b/templates/page.html @@ -2,7 +2,5 @@ {% extends "base.html" %} {% block content %} -
      - {{project_list|safe}} -
    + {{content|safe}} {% endblock %} diff --git a/templates/uses.html b/templates/uses.html deleted file mode 100644 index ae0313e..0000000 --- a/templates/uses.html +++ /dev/null @@ -1,164 +0,0 @@ - -{% extends "base.html" %} - -{% block content %} -

    Things I use

    -

    Analog stuff

    -
      -
    • - Bike: Trek... something. Hybrid. I have had it for almost 15 years and it shows no signs of slowing down as long as I periodically replace some parts. -
    • -
    • - Bag: Kifaru Checkpoint. Never thought that an expensive backpack was worth the investment. I was so wrong. I tend to fill my bag pretty full for daily use and the fitted backplate makes it so that I notice almost no difference carrying it no matter what I have packed. -
    • -
    • - Chair: ErgoCentric t-centric hybrid. Canadian ergonomic chair company. Was able to go and try it out in the showroom and get fitted for the chair. Fantastic and fully worth the price, especially with how much time I spend sitting in it. -
    • -
    • - Home Fitness: Extreme Monkey Kettlebells, yoga mat blocks and straps, Captains of crush grippers, various therabands and other elastics. -
    • -
    -

    Hardware

    -
      -
    • - Desktop: My desktop is one that I built myself quite a while ago. AMD RX580 GPU and recently upgraded the cpu and memory to Ryzen 5 4500 and 32G of Crucial DDR4. 2.5Gb network card -
    • -
    • - Network Attached Storage: Built it myself with a Jonsbo N1 mini ITX case, 32G RAM and a Ryzen 3 4100 cpu. 2 12TB Seagate Ironwolf Hard drives and a 500Gb NVME SSD. 2.5Gb network card -
    • -
    • - Laptop: 2018 Asus Zenbook 3, have replaced the battery in it so is still going strong. If I was to buy a laptop today I would certianly go for a Framework. Really believe in their mission and value being able to fix and upgrade my stuff. -
    • -
    • - Phone: Samsung Galaxy A20, got it used. Gets the job done. -
    • -
    • - Keyboard: Built a Ferriss Sweep, looking at building another so that I can keep one at work and one at home. Has made such a difference to my comfort when typing. Kalih Choc blue switches. -
    • -
    • - Mouse: SteelSeries something, currently using a wired mouse, have a logitech MxMaster and logitech MxAnywhere but the logitech univesal receiver dongle does not work through the KVM so don't use them at home. On my list to see if I can figure that out but not a high priority as I don't use my mouse all that much. -
    • -
    • - Raspberry Pis: I have 2 raspberry pis in use at the moment and 1 more that I have yet to decide what to do with. -
        -
      • - 2GB Pi4 runs my vpn, dns, network wide ad blocking -
      • -
      • - 8GB Pi4 runs some of my own scripts and programs, will also be hosting a home website when I get around to writing that -
      • -
      • - 8GB Pi5 still unused until I both decide what to use it for and take the time to get it set up -
      • -
      -
    • -
    • - General gadgets: -
        -
      • - KVM to switch between desktop and work computer when I am working from home -
      • -
      • - 5 port 2.5Gb switch, and 5 port 1Gb switch so that all of my devices that can be hard wired are. The 2.5Gb switch is to have that bandwidth between my desktop and NAS for fast file transfer. -
      • -
      -
    • -
    • - E-reader: Kobo touch 2.0, reliable, though the screen has taken some damage over the years, might be time to replace. I like the Kobo because of they support epub format which is open and I think should be the default for all ebooks. -
    • -
    -

    Software

    -
      -
    • - Writing/Programming: Neovim with a fair few plugins. Telescope and Harpoon for file navigation, lsp and Treesitter for coding, Zenmode for minimal distraction writing. -
    • -
    • - Finance: Firefly hosted on my NAS to budget and track my finances. Abacus on my phone to interact with Firefly on the go. -
    • -
    • - Media: -
        -
      • - Jellyfin hosted on my NAS for movies, shows, and music/audiobooks -
      • -
      • - Finamp on my phone to stream music/audiobooks from Jellyfin -
      • -
      • - Calibre for managing my ebook library -
      • -
      • - Liferea RSS feed reader for blogs and webcomics that I follow -
      • -
      • - Freetube for watching Youtube without sign in, tracking etc. -
      • -
      -
    • -
    • - Synchronization: SyncThing hosted on my NAS to keep files synced on my laptop, desktop, and phone. Lets my laptop and desktop function as essentially one computer -
    • -
    • - Browser: Firefox browser with Ublock Origin, Privacy Badger, and Link hints, plugins -
    • -
    • - Operating Systems: - -
    • -
    • - Window Manager: i3 tiling window manager -
    • -
    • - Terminal: Alacritty -
    • -
    • - Shell: Fish -
    • -
    • - Terminal Multiplexer: Zellij -
    • -
    • - Programming Languages: Rust -
    • -
    • - Memory: Anki flashcard app -
    • -
    -

    Services

    -

    - I try to pay for the services that I use. I find that "free" services don't often respect the user very much and have been getting worse pretty quickly lately. -

    -
      -
    • - Password Manager: 1Password -
    • -
    • - Music: Spotify -
    • -
    • - Server: Vultr minimal size instance -
    • -
    • - Domain Registrar: PorkBun -
    • -
    • - Backups: Backblaze, encrypted locally before uploading, periodic backup from my NAS. -
    • -
    • - Email: FastMail -
    • -
    • - Search: Kagi payed alternative to Google. So much different, any time that I use Google on another device I am reminded how bad the search has gotten -
    • -
    • - Language Learning: Duolingo -
    • -
    -{% endblock %}