Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions components/content/src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pub struct SerializingPage<'a> {
day: Option<u8>,
taxonomies: &'a HashMap<String, Vec<String>>,
authors: &'a [String],
aliases: &'a [String],
extra: &'a Map<String, Value>,
path: &'a str,
components: &'a [String],
Expand Down Expand Up @@ -121,6 +122,7 @@ impl<'a> SerializingPage<'a> {
day,
taxonomies: &page.meta.taxonomies,
authors: &page.meta.authors,
aliases: &page.meta.aliases,
path: &page.path,
components: &page.components,
summary: &page.summary,
Expand All @@ -138,6 +140,26 @@ impl<'a> SerializingPage<'a> {
}
}

#[cfg(test)]
mod tests {
use super::SerializingPage;
use crate::Page;
use tera::to_value;

#[test]
fn page_serialization_includes_aliases() {
let mut page = Page::default();
page.meta.aliases = vec!["/old-url/".to_owned(), "/legacy.html".to_owned()];

let serialized = to_value(SerializingPage::new(&page, None, false)).unwrap();

assert_eq!(
serialized.get("aliases").unwrap(),
&to_value(["/old-url/", "/legacy.html"]).unwrap()
);
}
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
pub struct SerializingSection<'a> {
relative_path: &'a str,
Expand Down
5 changes: 5 additions & 0 deletions components/site/tests/site.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ fn can_build_site_without_live_reload() {
assert!(file_exists!(public, "an-old-url/old-page/index.html"));
assert!(file_contains!(public, "an-old-url/old-page/index.html", "something-else"));
assert!(file_contains!(public, "another-old-url/index.html", "posts/"));
assert!(file_contains!(
public,
"posts/something-else/index.html",
"Page aliases: /an-old-url/old-page,/an-old-url/an-old-alias.html"
));

// html aliases work
assert!(file_exists!(public, "an-old-url/an-old-alias.html"));
Expand Down
1 change: 1 addition & 0 deletions docs/content/documentation/templates/pages-sections.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ updated: String?;
slug: String;
path: String;
authors: Array<String>;
aliases: Array<String>;
draft: Bool;
// the path, split on '/'
components: Array<String>;
Expand Down
1 change: 1 addition & 0 deletions test_site/templates/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{{ page.title | safe }}
{{ page.content | safe }}
{{ page.relative_path | safe }}
{% if page.aliases %}Page aliases: {{ page.aliases | join(sep=",") | safe }}{% endif %}
{{ page.toc }}

{% if page.earlier %}Previous article: {{ page.earlier.permalink }}{% endif %}
Expand Down