From 20a05da475804fb9fca3057f9588f28462989376 Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Tue, 13 Nov 2018 00:08:46 +0100 Subject: [PATCH] Fix bug with pages starting with dates --- components/library/src/content/page.rs | 1 + components/site/tests/site.rs | 22 +++++++++---------- .../posts/2016-10-08_a-post-with-dates.md | 3 +++ 3 files changed, 15 insertions(+), 11 deletions(-) create mode 100644 test_site/content/posts/2016-10-08_a-post-with-dates.md diff --git a/components/library/src/content/page.rs b/components/library/src/content/page.rs index 5f4895b0..122df166 100644 --- a/components/library/src/content/page.rs +++ b/components/library/src/content/page.rs @@ -118,6 +118,7 @@ impl Page { has_date_in_name = true; if page.meta.date.is_none() { page.meta.date = Some(page.file.name[..10].to_string()); + page.meta.date_to_datetime(); } } diff --git a/components/site/tests/site.rs b/components/site/tests/site.rs index 717e83ee..54e4ac55 100644 --- a/components/site/tests/site.rs +++ b/components/site/tests/site.rs @@ -18,7 +18,7 @@ fn can_parse_site() { site.load().unwrap(); // Correct number of pages (sections do not count as pages) - assert_eq!(site.library.pages().len(), 21); + assert_eq!(site.library.pages().len(), 22); let posts_path = path.join("content").join("posts"); // Make sure the page with a url doesn't have any sections @@ -41,7 +41,7 @@ fn can_parse_site() { let posts_section = site.library.get_section(&posts_path.join("_index.md")).unwrap(); assert_eq!(posts_section.subsections.len(), 2); - assert_eq!(posts_section.pages.len(), 9); + assert_eq!(posts_section.pages.len(), 10); assert_eq!( posts_section.ancestors, vec![*site.library.get_section_key(&index_section.file.path).unwrap()] @@ -392,7 +392,7 @@ fn can_build_site_with_pagination_for_section() { "posts/page/1/index.html", "http-equiv=\"refresh\" content=\"0;url=https://replace-this-with-your-url.com/posts/\"" )); - assert!(file_contains!(public, "posts/index.html", "Num pagers: 4")); + assert!(file_contains!(public, "posts/index.html", "Num pagers: 5")); assert!(file_contains!(public, "posts/index.html", "Page size: 2")); assert!(file_contains!(public, "posts/index.html", "Current index: 1")); assert!(!file_contains!(public, "posts/index.html", "has_prev")); @@ -405,12 +405,12 @@ fn can_build_site_with_pagination_for_section() { assert!(file_contains!( public, "posts/index.html", - "Last: https://replace-this-with-your-url.com/posts/page/4/" + "Last: https://replace-this-with-your-url.com/posts/page/5/" )); assert_eq!(file_contains!(public, "posts/index.html", "has_prev"), false); assert!(file_exists!(public, "posts/page/2/index.html")); - assert!(file_contains!(public, "posts/page/2/index.html", "Num pagers: 4")); + assert!(file_contains!(public, "posts/page/2/index.html", "Num pagers: 5")); assert!(file_contains!(public, "posts/page/2/index.html", "Page size: 2")); assert!(file_contains!(public, "posts/page/2/index.html", "Current index: 2")); assert!(file_contains!(public, "posts/page/2/index.html", "has_prev")); @@ -423,11 +423,11 @@ fn can_build_site_with_pagination_for_section() { assert!(file_contains!( public, "posts/page/2/index.html", - "Last: https://replace-this-with-your-url.com/posts/page/4/" + "Last: https://replace-this-with-your-url.com/posts/page/5/" )); assert!(file_exists!(public, "posts/page/3/index.html")); - assert!(file_contains!(public, "posts/page/3/index.html", "Num pagers: 4")); + assert!(file_contains!(public, "posts/page/3/index.html", "Num pagers: 5")); assert!(file_contains!(public, "posts/page/3/index.html", "Page size: 2")); assert!(file_contains!(public, "posts/page/3/index.html", "Current index: 3")); assert!(file_contains!(public, "posts/page/3/index.html", "has_prev")); @@ -440,15 +440,15 @@ fn can_build_site_with_pagination_for_section() { assert!(file_contains!( public, "posts/page/3/index.html", - "Last: https://replace-this-with-your-url.com/posts/page/4/" + "Last: https://replace-this-with-your-url.com/posts/page/5/" )); assert!(file_exists!(public, "posts/page/4/index.html")); - assert!(file_contains!(public, "posts/page/4/index.html", "Num pagers: 4")); + assert!(file_contains!(public, "posts/page/4/index.html", "Num pagers: 5")); assert!(file_contains!(public, "posts/page/4/index.html", "Page size: 2")); assert!(file_contains!(public, "posts/page/4/index.html", "Current index: 4")); assert!(file_contains!(public, "posts/page/4/index.html", "has_prev")); - assert!(!file_contains!(public, "posts/page/4/index.html", "has_next")); + assert!(file_contains!(public, "posts/page/4/index.html", "has_next")); assert!(file_contains!( public, "posts/page/4/index.html", @@ -457,7 +457,7 @@ fn can_build_site_with_pagination_for_section() { assert!(file_contains!( public, "posts/page/4/index.html", - "Last: https://replace-this-with-your-url.com/posts/page/4/" + "Last: https://replace-this-with-your-url.com/posts/page/5/" )); } diff --git a/test_site/content/posts/2016-10-08_a-post-with-dates.md b/test_site/content/posts/2016-10-08_a-post-with-dates.md new file mode 100644 index 00000000..aece952a --- /dev/null +++ b/test_site/content/posts/2016-10-08_a-post-with-dates.md @@ -0,0 +1,3 @@ ++++ +title = "A post with dates" ++++