aboutsummaryrefslogtreecommitdiff
path: root/src/router.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/router.rs')
-rw-r--r--src/router.rs9
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,
}