diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0d2f56f3..cc5fcfdd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,7 @@
- Sort individual tag/category pages by date
- Add extra builtin shortcode for Streamable videos
+- `path` and `permalink` now end with a `/`
## 0.0.6 (2017-05-24)
diff --git a/src/config.rs b/src/config.rs
index ec73d168..6f7fd1f5 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -90,12 +90,20 @@ impl Config {
/// Makes a url, taking into account that the base url might have a trailing slash
pub fn make_permalink(&self, path: &str) -> String {
- if self.base_url.ends_with('/') && path.starts_with('/') {
- format!("{}{}", self.base_url, &path[1..])
+ let trailing_bit = if path.ends_with('/') { "" } else { "/" };
+
+ // Index section with a base url that has a trailing slash
+ if self.base_url.ends_with('/') && path == "/" {
+ self.base_url.clone()
+ } else if path == "/" {
+ // index section with a base url that doesn't have a trailing slash
+ format!("{}/", self.base_url)
+ } else if self.base_url.ends_with('/') && path.starts_with('/') {
+ format!("{}{}{}", self.base_url, &path[1..], trailing_bit)
} else if self.base_url.ends_with('/') {
- format!("{}{}", self.base_url, path)
+ format!("{}{}{}", self.base_url, path, trailing_bit)
} else {
- format!("{}/{}", self.base_url, path)
+ format!("{}/{}{}", self.base_url, path, trailing_bit)
}
}
}
@@ -192,13 +200,13 @@ hello = "world"
fn can_make_url_with_non_trailing_slash_base_url() {
let mut config = Config::default();
config.base_url = "http://vincent.is".to_string();
- assert_eq!(config.make_permalink("hello"), "http://vincent.is/hello");
+ assert_eq!(config.make_permalink("hello"), "http://vincent.is/hello/");
}
#[test]
fn can_make_url_with_trailing_slash_path() {
let mut config = Config::default();
config.base_url = "http://vincent.is/".to_string();
- assert_eq!(config.make_permalink("/hello"), "http://vincent.is/hello");
+ assert_eq!(config.make_permalink("/hello"), "http://vincent.is/hello/");
}
}
diff --git a/src/content/page.rs b/src/content/page.rs
index 667b88cf..ad389178 100644
--- a/src/content/page.rs
+++ b/src/content/page.rs
@@ -91,6 +91,9 @@ impl Page {
format!("{}/{}", page.file.components.join("/"), page.slug)
};
}
+ if !page.path.ends_with('/') {
+ page.path = format!("{}/", page.path);
+ }
page.permalink = config.make_permalink(&page.path);
Ok(page)
@@ -231,8 +234,8 @@ Hello world"#;
let res = Page::parse(Path::new("content/posts/intro/start.md"), content, &conf);
assert!(res.is_ok());
let page = res.unwrap();
- assert_eq!(page.path, "posts/intro/hello-world");
- assert_eq!(page.permalink, "http://hello.com/posts/intro/hello-world");
+ assert_eq!(page.path, "posts/intro/hello-world/");
+ assert_eq!(page.permalink, "http://hello.com/posts/intro/hello-world/");
}
#[test]
@@ -246,7 +249,7 @@ Hello world"#;
let res = Page::parse(Path::new("start.md"), content, &config);
assert!(res.is_ok());
let page = res.unwrap();
- assert_eq!(page.path, "hello-world");
+ assert_eq!(page.path, "hello-world/");
assert_eq!(page.permalink, config.make_permalink("hello-world"));
}
diff --git a/src/content/pagination.rs b/src/content/pagination.rs
index 12701750..a94f7311 100644
--- a/src/content/pagination.rs
+++ b/src/content/pagination.rs
@@ -74,17 +74,18 @@ impl<'a> Paginator<'a> {
continue;
}
- let page_path = format!("{}/{}", paginate_path, index + 1);
- let permalink = if section.permalink.ends_with('/') {
- format!("{}{}", section.permalink, page_path)
+ let page_path = format!("{}/{}/", paginate_path, index + 1);
+ let permalink = format!("{}{}", section.permalink, page_path);
+ let pager_path = if section.is_index() {
+ page_path
} else {
- format!("{}/{}", section.permalink, page_path)
+ format!("{}{}", section.path, page_path)
};
pagers.push(Pager::new(
index + 1,
page.clone(),
permalink,
- if section.is_index() { page_path } else { format!("{}/{}", section.path, page_path) }
+ pager_path,
));
}
@@ -164,11 +165,11 @@ mod tests {
f.paginate_path = Some("page".to_string());
let mut s = Section::new("content/_index.md", f);
if !is_index {
- s.path = "posts".to_string();
- s.permalink = "https://vincent.is/posts".to_string();
+ s.path = "posts/".to_string();
+ s.permalink = "https://vincent.is/posts/".to_string();
s.file.components = vec!["posts".to_string()];
} else {
- s.permalink = "https://vincent.is".to_string();
+ s.permalink = "https://vincent.is/".to_string();
}
s
}
@@ -186,13 +187,13 @@ mod tests {
assert_eq!(paginator.pagers[0].index, 1);
assert_eq!(paginator.pagers[0].pages.len(), 2);
- assert_eq!(paginator.pagers[0].permalink, "https://vincent.is/posts");
- assert_eq!(paginator.pagers[0].path, "posts");
+ assert_eq!(paginator.pagers[0].permalink, "https://vincent.is/posts/");
+ assert_eq!(paginator.pagers[0].path, "posts/");
assert_eq!(paginator.pagers[1].index, 2);
assert_eq!(paginator.pagers[1].pages.len(), 1);
- assert_eq!(paginator.pagers[1].permalink, "https://vincent.is/posts/page/2");
- assert_eq!(paginator.pagers[1].path, "posts/page/2");
+ assert_eq!(paginator.pagers[1].permalink, "https://vincent.is/posts/page/2/");
+ assert_eq!(paginator.pagers[1].path, "posts/page/2/");
}
#[test]
@@ -208,13 +209,13 @@ mod tests {
assert_eq!(paginator.pagers[0].index, 1);
assert_eq!(paginator.pagers[0].pages.len(), 2);
- assert_eq!(paginator.pagers[0].permalink, "https://vincent.is");
+ assert_eq!(paginator.pagers[0].permalink, "https://vincent.is/");
assert_eq!(paginator.pagers[0].path, "");
assert_eq!(paginator.pagers[1].index, 2);
assert_eq!(paginator.pagers[1].pages.len(), 1);
- assert_eq!(paginator.pagers[1].permalink, "https://vincent.is/page/2");
- assert_eq!(paginator.pagers[1].path, "page/2");
+ assert_eq!(paginator.pagers[1].permalink, "https://vincent.is/page/2/");
+ assert_eq!(paginator.pagers[1].path, "page/2/");
}
#[test]
@@ -230,18 +231,18 @@ mod tests {
let context = paginator.build_paginator_context(&paginator.pagers[0]);
assert_eq!(context["paginate_by"], to_value(2).unwrap());
- assert_eq!(context["first"], to_value("https://vincent.is/posts").unwrap());
- assert_eq!(context["last"], to_value("https://vincent.is/posts/page/2").unwrap());
+ assert_eq!(context["first"], to_value("https://vincent.is/posts/").unwrap());
+ assert_eq!(context["last"], to_value("https://vincent.is/posts/page/2/").unwrap());
assert_eq!(context["previous"], to_value::