From 0199017d07d1d378f2f93bebf486e4278346cde4 Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Sun, 4 Aug 2019 16:13:07 +0200 Subject: [PATCH] Slugify given slugs as well --- components/library/src/content/page.rs | 18 +++++++++++++++++- components/site/tests/site.rs | 18 +++++++++--------- components/site/tests/site_i18n.rs | 14 +++++++------- components/templates/src/builtins/rss.xml | 8 ++++---- components/templates/src/builtins/sitemap.xml | 2 +- test_site/content/posts/fixed-slug.md | 2 +- 6 files changed, 39 insertions(+), 23 deletions(-) diff --git a/components/library/src/content/page.rs b/components/library/src/content/page.rs index 934ba6fa..45733571 100644 --- a/components/library/src/content/page.rs +++ b/components/library/src/content/page.rs @@ -160,7 +160,7 @@ impl Page { page.slug = { if let Some(ref slug) = page.meta.slug { - slug.trim().to_string() + slugify(&slug.trim()) } else if page.file.name == "index" { if let Some(parent) = page.file.path.parent() { if let Some(slug) = slug_from_dated_filename { @@ -437,6 +437,22 @@ Hello world"#; assert_eq!(page.permalink, config.make_permalink("hello-world")); } + #[test] + fn can_make_url_from_slug_only_with_no_special_chars() { + let content = r#" + +++ + slug = "hello-&-world" + +++ + Hello world"#; + let config = Config::default(); + let res = Page::parse(Path::new("start.md"), content, &config, &PathBuf::new()); + assert!(res.is_ok()); + let page = res.unwrap(); + assert_eq!(page.path, "hello-world/"); + assert_eq!(page.components, vec!["hello-world"]); + assert_eq!(page.permalink, config.make_permalink("hello-world")); + } + #[test] fn can_make_url_from_path() { let content = r#" diff --git a/components/site/tests/site.rs b/components/site/tests/site.rs index c5288be6..015f6caf 100644 --- a/components/site/tests/site.rs +++ b/components/site/tests/site.rs @@ -167,12 +167,12 @@ fn can_build_site_without_live_reload() { assert!(file_contains!( public, "sitemap.xml", - "https%3A//replace-this-with-your-url.com/posts/simple/" + "https://replace-this-with-your-url.com/posts/simple/" )); assert!(file_contains!( public, "sitemap.xml", - "https%3A//replace-this-with-your-url.com/posts/" + "https://replace-this-with-your-url.com/posts/" )); // Drafts are not in the sitemap assert!(!file_contains!(public, "sitemap.xml", "draft")); @@ -280,7 +280,7 @@ fn can_build_site_with_taxonomies() { assert!(file_contains!( public, "categories/a/rss.xml", - "https%3A//replace-this-with-your-url.com/categories/a/rss.xml" + "https://replace-this-with-your-url.com/categories/a/rss.xml" )); // Extending from a theme works assert!(file_contains!(public, "categories/a/index.html", "EXTENDED")); @@ -291,12 +291,12 @@ fn can_build_site_with_taxonomies() { assert!(file_contains!( public, "sitemap.xml", - "https%3A//replace-this-with-your-url.com/categories/" + "https://replace-this-with-your-url.com/categories/" )); assert!(file_contains!( public, "sitemap.xml", - "https%3A//replace-this-with-your-url.com/categories/a/" + "https://replace-this-with-your-url.com/categories/a/" )); } @@ -425,7 +425,7 @@ fn can_build_site_with_pagination_for_section() { assert!(file_contains!( public, "sitemap.xml", - "https%3A//replace-this-with-your-url.com/posts/page/4/" + "https://replace-this-with-your-url.com/posts/page/4/" )); } @@ -478,7 +478,7 @@ fn can_build_site_with_pagination_for_index() { assert!(file_contains!( public, "sitemap.xml", - "https%3A//replace-this-with-your-url.com/page/1/" + "https://replace-this-with-your-url.com/page/1/" )) } @@ -559,7 +559,7 @@ fn can_build_site_with_pagination_for_taxonomy() { assert!(file_contains!( public, "sitemap.xml", - "https%3A//replace-this-with-your-url.com/tags/a/page/6/" + "https://replace-this-with-your-url.com/tags/a/page/6/" )) } @@ -643,7 +643,7 @@ fn can_apply_page_templates() { assert_eq!(child.meta.title, Some("Local section override".into())); } -// https%3A//github.com/getzola/zola/issues/571 +// https://github.com/getzola/zola/issues/571 #[test] fn can_build_site_custom_builtins_from_theme() { let (_, _tmp_dir, public) = build_site("test_site"); diff --git a/components/site/tests/site_i18n.rs b/components/site/tests/site_i18n.rs index 2ba1b102..2f81c7cd 100644 --- a/components/site/tests/site_i18n.rs +++ b/components/site/tests/site_i18n.rs @@ -112,17 +112,17 @@ fn can_build_multilingual_site() { // sitemap contains all languages assert!(file_exists!(public, "sitemap.xml")); - assert!(file_contains!(public, "sitemap.xml", "https%3A//example.com/blog/something-else/")); - assert!(file_contains!(public, "sitemap.xml", "https%3A//example.com/fr/blog/something-else/")); - assert!(file_contains!(public, "sitemap.xml", "https%3A//example.com/it/blog/something-else/")); + assert!(file_contains!(public, "sitemap.xml", "https://example.com/blog/something-else/")); + assert!(file_contains!(public, "sitemap.xml", "https://example.com/fr/blog/something-else/")); + assert!(file_contains!(public, "sitemap.xml", "https://example.com/it/blog/something-else/")); // one rss per language assert!(file_exists!(public, "rss.xml")); - assert!(file_contains!(public, "rss.xml", "https%3A//example.com/blog/something-else/")); - assert!(!file_contains!(public, "rss.xml", "https%3A//example.com/fr/blog/something-else/")); + assert!(file_contains!(public, "rss.xml", "https://example.com/blog/something-else/")); + assert!(!file_contains!(public, "rss.xml", "https://example.com/fr/blog/something-else/")); assert!(file_exists!(public, "fr/rss.xml")); - assert!(!file_contains!(public, "fr/rss.xml", "https%3A//example.com/blog/something-else/")); - assert!(file_contains!(public, "fr/rss.xml", "https%3A//example.com/fr/blog/something-else/")); + assert!(!file_contains!(public, "fr/rss.xml", "https://example.com/blog/something-else/")); + assert!(file_contains!(public, "fr/rss.xml", "https://example.com/fr/blog/something-else/")); // Italian doesn't have RSS enabled assert!(!file_exists!(public, "it/rss.xml")); diff --git a/components/templates/src/builtins/rss.xml b/components/templates/src/builtins/rss.xml index 3d5e909d..8f889737 100644 --- a/components/templates/src/builtins/rss.xml +++ b/components/templates/src/builtins/rss.xml @@ -2,18 +2,18 @@ {{ config.title }} - {{ config.base_url | urlencode | safe }} + {{ config.base_url | safe }} {{ config.description }} Zola {{ config.default_language }} - + {{ last_build_date | date(format="%a, %d %b %Y %H:%M:%S %z") }} {% for page in pages %} {{ page.title }} {{ page.date | date(format="%a, %d %b %Y %H:%M:%S %z") }} - {{ page.permalink | urlencode | safe }} - {{ page.permalink | urlencode | safe }} + {{ page.permalink | safe }} + {{ page.permalink | safe }} {% if page.summary %}{{ page.summary }}{% else %}{{ page.content }}{% endif %} {% endfor %} diff --git a/components/templates/src/builtins/sitemap.xml b/components/templates/src/builtins/sitemap.xml index 7186e534..171ae2e7 100644 --- a/components/templates/src/builtins/sitemap.xml +++ b/components/templates/src/builtins/sitemap.xml @@ -2,7 +2,7 @@ {% for sitemap_entry in entries %} - {{ sitemap_entry.permalink | urlencode | safe }} + {{ sitemap_entry.permalink | safe }} {% if sitemap_entry.date %} {{ sitemap_entry.date }} {% endif %} diff --git a/test_site/content/posts/fixed-slug.md b/test_site/content/posts/fixed-slug.md index afec24bc..6bac415a 100644 --- a/test_site/content/posts/fixed-slug.md +++ b/test_site/content/posts/fixed-slug.md @@ -1,7 +1,7 @@ +++ title = "Fixed slug" description = "" -slug = "something-else" +slug = "something-&-else" date = 2017-01-01 aliases = ["/an-old-url/old-page", "/an-old-url/an-old-alias.html"] +++