diff --git a/components/config/src/config/mod.rs b/components/config/src/config/mod.rs index 322116677..b41ccc27f 100644 --- a/components/config/src/config/mod.rs +++ b/components/config/src/config/mod.rs @@ -658,10 +658,30 @@ anchors = "off" let config = Config::parse(config_str).unwrap(); assert_eq!(config.slugify.paths, SlugifyStrategy::On); + assert_eq!(config.slugify.paths_keep_dates, false); assert_eq!(config.slugify.taxonomies, SlugifyStrategy::Safe); assert_eq!(config.slugify.anchors, SlugifyStrategy::Off); } + #[test] + fn slugify_paths_keep_dates() { + let config_str = r#" +title = "My site" +base_url = "example.com" + +[slugify] +paths_keep_dates = true +taxonomies = "off" +anchors = "safe" + "#; + + let config = Config::parse(config_str).unwrap(); + assert_eq!(config.slugify.paths, SlugifyStrategy::On); + assert_eq!(config.slugify.paths_keep_dates, true); + assert_eq!(config.slugify.taxonomies, SlugifyStrategy::Off); + assert_eq!(config.slugify.anchors, SlugifyStrategy::Safe); + } + #[test] fn cannot_overwrite_theme_mapping_with_invalid_type() { let config_str = r#" diff --git a/components/config/src/config/slugify.rs b/components/config/src/config/slugify.rs index c22065b34..1a67376c2 100644 --- a/components/config/src/config/slugify.rs +++ b/components/config/src/config/slugify.rs @@ -6,6 +6,7 @@ use utils::slugs::SlugifyStrategy; #[serde(default)] pub struct Slugify { pub paths: SlugifyStrategy, + pub paths_keep_dates: bool, pub taxonomies: SlugifyStrategy, pub anchors: SlugifyStrategy, } diff --git a/components/content/src/page.rs b/components/content/src/page.rs index 57d9812f8..7501a4c62 100644 --- a/components/content/src/page.rs +++ b/components/content/src/page.rs @@ -126,7 +126,9 @@ impl Page { }; if let Some(ref caps) = RFC3339_DATE.captures(&file_path_for_slug) { - slug_from_dated_filename = Some(caps.name("slug").unwrap().as_str().to_string()); + if !config.slugify.paths_keep_dates { + slug_from_dated_filename = Some(caps.name("slug").unwrap().as_str().to_string()); + } if page.meta.date.is_none() { page.meta.date = Some(caps.name("datetime").unwrap().as_str().to_string()); page.meta.date_to_datetime(); diff --git a/docs/content/documentation/content/page.md b/docs/content/documentation/content/page.md index 0f018e04c..18d0a8cb9 100644 --- a/docs/content/documentation/content/page.md +++ b/docs/content/documentation/content/page.md @@ -16,11 +16,13 @@ create a **page** at `[base_url]/about`). If the file is given any name _other_ than `index.md` or `_index.md`, then it will create a page with that name (without the `.md`). For example, naming a file in the root of your content directory `about.md` would create a page at `[base_url]/about`. + Another exception to this rule is that a filename starting with a datetime (YYYY-mm-dd or [an RFC3339 datetime](https://www.ietf.org/rfc/rfc3339.txt)) followed by an underscore (`_`) or a dash (`-`) will use that date as the page date, unless already set in the front matter. The page name will be anything after `_`/`-`, so the file `2018-10-10-hello-world.md` will be available at `[base_url]/hello-world`. Note that the full RFC3339 datetime contains colons, which is not a valid character in a filename on Windows. +This behavior can be disabled by setting `slugify.paths_keep_date` to `true` (the default is `false`). Note that a `_` separating the date would be slugified into a `-` with the default value for `slugify.paths` of `"on"`. As you can see, creating an `about.md` file is equivalent to creating an `about/index.md` file. The only difference between the two methods is that creating diff --git a/docs/content/documentation/getting-started/configuration.md b/docs/content/documentation/getting-started/configuration.md index f8f2d473f..92675197c 100644 --- a/docs/content/documentation/getting-started/configuration.md +++ b/docs/content/documentation/getting-started/configuration.md @@ -142,6 +142,10 @@ external_level = "error" paths = "on" taxonomies = "on" anchors = "on" +# Whether to remove date prefixes for page path slugs. +# For example, content/posts/2016-10-08_a-post-with-dates.md => posts/a-post-with-dates +# When true, content/posts/2016-10-08_a-post-with-dates.md => posts/2016-10-08-a-post-with-dates +paths_keep_dates = false [search] # Whether to include the title of the page/section in the index