Add slugify.paths_keep_dates option. Update docs.
Manual testing: Existing test_site/config.toml http://127.0.0.1:1111/posts/a-post-with-dates ==== --- a/test_site/config.toml +++ b/test_site/config.toml @@ -18,6 +18,7 @@ extra_syntaxes_and_themes = ["syntaxes", "highlight_themes"] [slugify] paths = "on" +paths_keep_dates = true taxonomies = "on" anchors = "on" http://127.0.0.1:1111/posts/2016-10-08-a-post-with-dates ==== --- a/test_site/config.toml +++ b/test_site/config.toml @@ -17,7 +17,8 @@ highlight_theme = "custom_gruvbox" extra_syntaxes_and_themes = ["syntaxes", "highlight_themes"] [slugify] -paths = "on" +paths = "off" +paths_keep_dates = true taxonomies = "on" anchors = "on" http://127.0.0.1:1111/posts/2016-10-08_a-post-with-dates ==== --- a/test_site/config.toml +++ b/test_site/config.toml @@ -17,7 +17,8 @@ highlight_theme = "custom_gruvbox" extra_syntaxes_and_themes = ["syntaxes", "highlight_themes"] [slugify] -paths = "on" +paths = "safe" +paths_keep_dates = true taxonomies = "on" anchors = "on" http://127.0.0.1:1111/posts/2016-10-08_a-post-with-dates
This commit is contained in:
parent
74c090a637
commit
7b562fcd2c
@ -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#"
|
||||
|
||||
@ -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,
|
||||
}
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user