diff options
author | Gabriel A. Giovanini <mail@gabrielgio.me> | 2022-06-11 18:15:38 +0200 |
---|---|---|
committer | Gabriel A. Giovanini <mail@gabrielgio.me> | 2022-06-11 18:15:38 +0200 |
commit | 6a31a30b98f7febe9ac0db74211ef074aefc7ad3 (patch) | |
tree | 9ce8694f0f37efcc5b1eb72d9e2d26731ad7ec6a /src/router.rs | |
parent | 96c2cbe1850f95806cccb6f47a7739eb9c2ac860 (diff) | |
download | macroblog.rs-6a31a30b98f7febe9ac0db74211ef074aefc7ad3.tar.gz macroblog.rs-6a31a30b98f7febe9ac0db74211ef074aefc7ad3.tar.bz2 macroblog.rs-6a31a30b98f7febe9ac0db74211ef074aefc7ad3.zip |
feat: Add project tab
Diffstat (limited to 'src/router.rs')
-rw-r--r-- | src/router.rs | 9 |
1 files changed, 7 insertions, 2 deletions
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<action>\w*)/(?P<id>.+)"; +const ACTION_REGEX: &str = r"/{0,1}(?P<action>\w*)/{0,1}(?P<id>.*)"; 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, } |