From 6a31a30b98f7febe9ac0db74211ef074aefc7ad3 Mon Sep 17 00:00:00 2001 From: "Gabriel A. Giovanini" Date: Sat, 11 Jun 2022 18:15:38 +0200 Subject: feat: Add project tab --- src/router.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/router.rs') diff --git a/src/router.rs b/src/router.rs index 3227d66..c5efd9c 100644 --- a/src/router.rs +++ b/src/router.rs @@ -1,11 +1,12 @@ use crate::assets::PostAsset; use regex::Regex; -const ACTION_REGEX: &str = r"/{0,1}(?P\w*)/(?P.+)"; +const ACTION_REGEX: &str = r"/{0,1}(?P\w*)/{0,1}(?P.*)"; pub enum Router { NotFound, Index, + Projects, Post { page: String }, } @@ -17,11 +18,14 @@ impl Router { pub fn new(path: &str) -> Router { let re = Regex::new(ACTION_REGEX).unwrap(); let caps = re.captures(path); - let action = match caps { + let mut action = match caps { Some(ref value) => &value["action"], None => "index", }; + if action == "" { + action = "index" + } // this 7 means the "/posts/" from the full path let trimmed_path: String = path.chars().skip(7).collect(); @@ -33,6 +37,7 @@ impl Router { "posts" => Router::Post { page: caps.unwrap()["id"].to_string(), }, + "projects" => Router::Projects, "index" => Router::Index, _ => Router::NotFound, } -- cgit v1.2.3