mirror of
https://github.com/cobalt-org/cobalt.rs
synced 2024-11-14 16:07:22 +00:00
feat(front): Change permalink variable names
General reasons - The hope is this will make the meaning more clear - This is more aligned with the planned document_attributes Specific reasons - path: unclear if includes filename or not (it doesn't) - filename: unclear of includes extension or not (it doesn't) - output_ext: overly verbose. We don't call `path`, `output_path`, so why does this need it? Finish fixing #198 BREAKING CHANGE: permalink variables renamed - path -> parent - filename -> name - output_ext -> ext `cobalt migrate` should take care of this.
This commit is contained in:
parent
c6c4d7aca4
commit
e78b806c95
4 changed files with 21 additions and 11 deletions
|
@ -13,7 +13,7 @@ use error::Result;
|
|||
use super::datetime;
|
||||
use super::slug;
|
||||
|
||||
const PATH_ALIAS: &'static str = "/{{path}}/{{filename}}{{output_ext}}";
|
||||
const PATH_ALIAS: &'static str = "/{{parent}}/{{name}}{{ext}}";
|
||||
lazy_static!{
|
||||
static ref PERMALINK_ALIASES: HashMap<&'static str, &'static str> = [
|
||||
("path", PATH_ALIAS),
|
||||
|
|
|
@ -41,15 +41,13 @@ fn format_path_variable(source_file: &Path) -> String {
|
|||
fn permalink_attributes(front: &cobalt_model::Frontmatter, dest_file: &Path) -> liquid::Object {
|
||||
let mut attributes = liquid::Object::new();
|
||||
|
||||
attributes.insert("path".to_owned(),
|
||||
attributes.insert("parent".to_owned(),
|
||||
Value::Str(format_path_variable(dest_file)));
|
||||
|
||||
let filename = dest_file.file_stem().and_then(|s| s.to_str());
|
||||
if let Some(filename) = filename {
|
||||
attributes.insert("filename".to_owned(), Value::str(filename));
|
||||
}
|
||||
let filename = dest_file.file_stem().and_then(|s| s.to_str()).unwrap_or("");
|
||||
attributes.insert("name".to_owned(), Value::str(filename));
|
||||
|
||||
attributes.insert("output_ext".to_owned(), Value::str(".html"));
|
||||
attributes.insert("ext".to_owned(), Value::str(".html"));
|
||||
|
||||
// TODO(epage): Add `collection` (the collection's slug), see #257
|
||||
// or `parent.slug`, see #323
|
||||
|
|
|
@ -75,6 +75,12 @@ fn migrate_variable(var: String) -> Part {
|
|||
let name: &str = &var;
|
||||
VARIABLES.contains(&name)
|
||||
};
|
||||
let var = match var.as_str() {
|
||||
"path" => "parent".to_owned(),
|
||||
"filename" => "name".to_owned(),
|
||||
"output_ext" => "ext".to_owned(),
|
||||
x => x.to_owned(),
|
||||
};
|
||||
let variable = if native_variable {
|
||||
format!("{{{{ {} }}}}", var)
|
||||
} else {
|
||||
|
@ -106,7 +112,7 @@ mod test {
|
|||
#[test]
|
||||
fn migrate_variable_known() {
|
||||
let fixture = "path".to_owned();
|
||||
let expected = Part::Constant("{{ path }}".to_owned());
|
||||
let expected = Part::Constant("{{ parent }}".to_owned());
|
||||
let actual = migrate_variable(fixture);
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
|
@ -137,7 +143,7 @@ mod test {
|
|||
#[test]
|
||||
fn convert_permalink_known_variable() {
|
||||
assert_eq!(convert_permalink("hello/:path/world/:i_day/"),
|
||||
"/hello/{{ path }}/world/{{ i_day }}/".to_owned());
|
||||
"/hello/{{ parent }}/world/{{ i_day }}/".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -86,6 +86,12 @@ fn migrate_variable(var: String) -> Part {
|
|||
let name: &str = &var;
|
||||
VARIABLES.contains(&name)
|
||||
};
|
||||
let var = match var.as_str() {
|
||||
"path" => "parent".to_owned(),
|
||||
"filename" => "name".to_owned(),
|
||||
"output_ext" => "ext".to_owned(),
|
||||
x => x.to_owned(),
|
||||
};
|
||||
let variable = if native_variable {
|
||||
format!("{{{{ {} }}}}", var)
|
||||
} else {
|
||||
|
@ -109,7 +115,7 @@ mod tests {
|
|||
#[test]
|
||||
fn migrate_variable_known() {
|
||||
let fixture = "path".to_owned();
|
||||
let expected = Part::Constant("{{ path }}".to_owned());
|
||||
let expected = Part::Constant("{{ parent }}".to_owned());
|
||||
let actual = migrate_variable(fixture);
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
|
@ -140,7 +146,7 @@ mod tests {
|
|||
#[test]
|
||||
fn convert_permalink_known_variable() {
|
||||
assert_eq!(convert_permalink("hello/:path/world/:i_day/"),
|
||||
"/hello/{{ path }}/world/{{ i_day }}/".to_owned());
|
||||
"/hello/{{ parent }}/world/{{ i_day }}/".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in a new issue