diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e66120c..90fa1dfe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,10 +8,15 @@ - Config value `rss_limit` is renamed to `feed_limit` - Config value `languages.*.rss` is renamed to `languages.*.feed` - Config value `generate_rss` is renamed to `generate_feed` - - Feed template variable `last_build_date` is renamed to `latest_date` Users with existing feeds should either set `feed_filename = "rss.xml"` in config.toml to keep things the same, or set up a 3xx redirect from rss.xml to atom.xml so that existing feed consumers aren’t broken. +- The feed template variable `last_build_date` is renamed to `last_updated` to more accurately reflect its semantics +- The sitemap template’s `SitemapEntry` type’s `date` field has been renamed to `updated` to reflect that it will use the `updated` front-matter field if available, rather than `date` + +### Other +- Add `updated` front-matter field for pages, which sitemap templates will use for the `SitemapEntry.date` field instead of the `date` front-matter field, and which the default Atom feed template will use + ## 0.10.2 (unreleased) - Fix link checker not looking for anchor with capital id/name diff --git a/components/front_matter/src/page.rs b/components/front_matter/src/page.rs index dba73511..c26371af 100644 --- a/components/front_matter/src/page.rs +++ b/components/front_matter/src/page.rs @@ -16,6 +16,9 @@ pub struct PageFrontMatter { pub title: Option, /// Description in that appears when linked, e.g. on twitter pub description: Option, + /// Updated date + #[serde(default, deserialize_with = "from_toml_datetime")] + pub updated: Option, /// Date if we want to order pages (ie blog post) #[serde(default, deserialize_with = "from_toml_datetime")] pub date: Option, @@ -117,6 +120,7 @@ impl Default for PageFrontMatter { PageFrontMatter { title: None, description: None, + updated: None, date: None, datetime: None, datetime_tuple: None, diff --git a/components/library/src/content/ser.rs b/components/library/src/content/ser.rs index ca794481..39e6439c 100644 --- a/components/library/src/content/ser.rs +++ b/components/library/src/content/ser.rs @@ -63,6 +63,7 @@ pub struct SerializingPage<'a> { ancestors: Vec, title: &'a Option, description: &'a Option, + updated: &'a Option, date: &'a Option, year: Option, month: Option, @@ -126,6 +127,7 @@ impl<'a> SerializingPage<'a> { title: &page.meta.title, description: &page.meta.description, extra: &page.meta.extra, + updated: &page.meta.updated, date: &page.meta.date, year, month, @@ -182,6 +184,7 @@ impl<'a> SerializingPage<'a> { title: &page.meta.title, description: &page.meta.description, extra: &page.meta.extra, + updated: &page.meta.updated, date: &page.meta.date, year, month, diff --git a/components/site/src/lib.rs b/components/site/src/lib.rs index 88c8c0a9..562ea387 100644 --- a/components/site/src/lib.rs +++ b/components/site/src/lib.rs @@ -1065,7 +1065,14 @@ impl Site { pages.par_sort_unstable_by(sort_actual_pages_by_date); - context.insert("latest_date", &pages[0].meta.date.clone()); + context.insert( + "last_updated", + pages.iter() + .filter_map(|page| page.meta.updated.as_ref()) + .chain(pages[0].meta.date.as_ref()) + .max() // I love lexicographically sorted date strings + .unwrap(), // Guaranteed because of pages[0].meta.date + ); let library = self.library.read().unwrap(); // limit to the last n elements if the limit is set; otherwise use all. let num_entries = self.config.feed_limit.unwrap_or_else(|| pages.len()); diff --git a/components/site/src/sitemap.rs b/components/site/src/sitemap.rs index 51bf43c4..afb20928 100644 --- a/components/site/src/sitemap.rs +++ b/components/site/src/sitemap.rs @@ -14,7 +14,7 @@ use tera::{Map, Value}; #[derive(Debug, Serialize)] pub struct SitemapEntry<'a> { pub permalink: Cow<'a, str>, - pub date: Option, + pub updated: Option, pub extra: Option<&'a Map>, } @@ -33,8 +33,8 @@ impl<'a> PartialEq for SitemapEntry<'a> { impl<'a> Eq for SitemapEntry<'a> {} impl<'a> SitemapEntry<'a> { - pub fn new(permalink: Cow<'a, str>, date: Option) -> Self { - SitemapEntry { permalink, date, extra: None } + pub fn new(permalink: Cow<'a, str>, updated: Option) -> Self { + SitemapEntry { permalink, updated, extra: None } } pub fn add_extra(&mut self, extra: &'a Map) { @@ -65,11 +65,10 @@ pub fn find_entries<'a>( .pages_values() .iter() .map(|p| { - let date = match p.meta.date { - Some(ref d) => Some(d.to_string()), - None => None, - }; - let mut entry = SitemapEntry::new(Cow::Borrowed(&p.permalink), date); + let mut entry = SitemapEntry::new( + Cow::Borrowed(&p.permalink), + p.meta.updated.clone().or_else(|| p.meta.date.clone()), + ); entry.add_extra(&p.meta.extra); entry }) diff --git a/components/templates/src/builtins/atom.xml b/components/templates/src/builtins/atom.xml index 106ade4a..279b2339 100644 --- a/components/templates/src/builtins/atom.xml +++ b/components/templates/src/builtins/atom.xml @@ -7,7 +7,7 @@ Zola - {{ latest_date | date(format="%+") }} + {{ last_updated | date(format="%+") }} {{ feed_url | safe }} {%- for page in pages %} {{ page.title }} {{ page.date | date(format="%+") }} + {{ page.updated | default(value=page.date) | date(format="%+") }} {{ page.permalink | safe }} {{ page.content }} diff --git a/components/templates/src/builtins/rss.xml b/components/templates/src/builtins/rss.xml index d66befd4..a76f6475 100644 --- a/components/templates/src/builtins/rss.xml +++ b/components/templates/src/builtins/rss.xml @@ -7,7 +7,7 @@ Zola {{ config.default_language }} - {{ latest_date | date(format="%a, %d %b %Y %H:%M:%S %z") }} + {{ last_updated | date(format="%a, %d %b %Y %H:%M:%S %z") }} {%- for page in pages %} {{ page.title }} diff --git a/components/templates/src/builtins/sitemap.xml b/components/templates/src/builtins/sitemap.xml index fd8ab76b..aeb85387 100644 --- a/components/templates/src/builtins/sitemap.xml +++ b/components/templates/src/builtins/sitemap.xml @@ -3,8 +3,8 @@ {%- for sitemap_entry in entries %} {{ sitemap_entry.permalink | escape_xml | safe }} - {%- if sitemap_entry.date %} - {{ sitemap_entry.date }} + {%- if sitemap_entry.updated %} + {{ sitemap_entry.updated }} {%- endif %} {%- endfor %} diff --git a/docs/content/documentation/content/page.md b/docs/content/documentation/content/page.md index 21237e68..d1f98fc1 100644 --- a/docs/content/documentation/content/page.md +++ b/docs/content/documentation/content/page.md @@ -93,6 +93,10 @@ description = "" # Setting this overrides a date set in the filename. date = +# The last updated date of the post, if different from the date. +# Same format as `date`. +updated = + # The weight as defined on the Section page of the documentation. # If the section variable `sort_by` is set to `weight`, then any page that lacks a `weight` # will not be rendered. diff --git a/docs/content/documentation/templates/feeds.md b/docs/content/documentation/templates/feeds.md index 71fd7c1d..7ab92ff7 100644 --- a/docs/content/documentation/templates/feeds.md +++ b/docs/content/documentation/templates/feeds.md @@ -20,6 +20,6 @@ need to provide a template yourself. The feed template gets three variables in addition to `config`: - `feed_url`: the full url to that specific feed -- `latest_date`: the date of the latest post +- `last_updated`: the most recent `updated` or `date` field of any post - `pages`: see [page variables](@/documentation/templates/pages-sections.md#page-variables) for a detailed description of what this contains diff --git a/docs/content/documentation/templates/pages-sections.md b/docs/content/documentation/templates/pages-sections.md index 91e2f7a0..7d249e30 100644 --- a/docs/content/documentation/templates/pages-sections.md +++ b/docs/content/documentation/templates/pages-sections.md @@ -19,6 +19,8 @@ content: String; title: String?; description: String?; date: String?; +// `updated` will be the same as `date` if `date` is specified but `updated` is not in front-matter +updated: String?; slug: String; path: String; draft: Bool; diff --git a/docs/content/documentation/templates/sitemap.md b/docs/content/documentation/templates/sitemap.md index decd397c..3c213516 100644 --- a/docs/content/documentation/templates/sitemap.md +++ b/docs/content/documentation/templates/sitemap.md @@ -25,7 +25,7 @@ A `SitemapEntry` has the following fields: ```ts permalink: String; -date: String?; +updated: String?; extra: Hashmap?; ```