From 2d3ea16bb13c33a740f2f7c32cb3aa9c1011170d Mon Sep 17 00:00:00 2001
From: LunarEclipse <luna@lunareclipse.zone>
Date: Mon, 17 Jun 2024 15:46:54 +0200
Subject: [PATCH] added #[serde(deny_unknown_fields)] to front-matter, fixed
 problems this found in tests

---
 CHANGELOG.md                                  |  2 +-
 components/config/src/lib.rs                  | 28 +------------------
 .../content/src/front_matter/section.rs       | 14 +---------
 components/content/src/section.rs             |  2 +-
 test_site_i18n/content/blog/_index.fr.md      |  2 +-
 test_site_i18n/content/blog/_index.it.md      |  2 +-
 test_site_i18n/content/blog/_index.md         |  2 +-
 7 files changed, 7 insertions(+), 45 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5a0cf270e2..4b786ff35d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,7 +14,7 @@
 - Added support for generating multiple kinds of feeds at once
 - Changed config options named `generate_feed` to `generate_feeds` (both in config.toml and in section front-matter)
 - Changed config option `feed_filename: String` to `feed_filenames: Vec<String>`
-- The config file no longer allows arbitrary fields outside the `[extra]` section (front-matter is unaffected)
+- The config file no longer allows arbitrary fields outside the `[extra]` section
 
 ## 0.18.0 (2023-12-18)
 
diff --git a/components/config/src/lib.rs b/components/config/src/lib.rs
index bbc4b93255..05d621615c 100644
--- a/components/config/src/lib.rs
+++ b/components/config/src/lib.rs
@@ -2,7 +2,7 @@ mod config;
 pub mod highlighting;
 mod theme;
 
-use std::{marker::PhantomData, path::Path};
+use std::path::Path;
 
 pub use crate::config::{
     languages::LanguageOptions,
@@ -14,35 +14,9 @@ pub use crate::config::{
     Config,
 };
 use errors::Result;
-use serde::Deserialize;
 
 /// Get and parse the config.
 /// If it doesn't succeed, exit
 pub fn get_config(filename: &Path) -> Result<Config> {
     Config::from_file(filename)
 }
-
-/// This is used to print an error message for deprecated fields
-#[derive(Copy, Clone, Debug, PartialEq, Eq)]
-pub struct Deprecated<T> {
-    _type: PhantomData<T>,
-}
-
-impl<T> Deprecated<T> {
-    pub fn new() -> Self {
-        Self { _type: PhantomData }
-    }
-}
-
-pub trait DeprecationReason {
-    const REASON: &'static str;
-}
-
-impl<'de, T: DeprecationReason> Deserialize<'de> for Deprecated<T> {
-    fn deserialize<D>(_deserializer: D) -> std::prelude::v1::Result<Self, D::Error>
-    where
-        D: serde::Deserializer<'de>,
-    {
-        Err(serde::de::Error::custom(format!("Failed to parse a deprecated option: {}", T::REASON)))
-    }
-}
diff --git a/components/content/src/front_matter/section.rs b/components/content/src/front_matter/section.rs
index d8456fad67..76c51461c2 100644
--- a/components/content/src/front_matter/section.rs
+++ b/components/content/src/front_matter/section.rs
@@ -1,7 +1,6 @@
 use libs::tera::{Map, Value};
 use serde::{Deserialize, Serialize};
 
-use config::{Deprecated, DeprecationReason};
 use errors::Result;
 use utils::de::fix_toml_dates;
 use utils::types::InsertAnchor;
@@ -13,7 +12,7 @@ static DEFAULT_PAGINATE_PATH: &str = "page";
 
 /// The front matter of every section
 #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
-#[serde(default)]
+#[serde(default, deny_unknown_fields)]
 pub struct SectionFrontMatter {
     /// <title> of the page
     pub title: Option<String>,
@@ -68,9 +67,6 @@ pub struct SectionFrontMatter {
     /// redirect to this
     #[serde(skip_serializing)]
     pub aliases: Vec<String>,
-    /// Deprecated
-    #[serde(skip_serializing)]
-    pub generate_feed: Deprecated<DeprecatedGenerateFeed>,
     /// Whether to generate a feed for the current section
     #[serde(skip_serializing)]
     pub generate_feeds: bool,
@@ -78,13 +74,6 @@ pub struct SectionFrontMatter {
     pub extra: Map<String, Value>,
 }
 
-#[derive(Copy, Clone, Debug, PartialEq, Eq)]
-pub struct DeprecatedGenerateFeed {}
-
-impl DeprecationReason for DeprecatedGenerateFeed {
-    const REASON: &'static str = "generate_feed is deprecated, please use generate_feeds instead";
-}
-
 impl SectionFrontMatter {
     pub fn parse(raw: &RawFrontMatter) -> Result<SectionFrontMatter> {
         let mut f: SectionFrontMatter = raw.deserialize()?;
@@ -124,7 +113,6 @@ impl Default for SectionFrontMatter {
             transparent: false,
             page_template: None,
             aliases: Vec::new(),
-            generate_feed: Deprecated::new(),
             generate_feeds: false,
             extra: Map::new(),
             draft: false,
diff --git a/components/content/src/section.rs b/components/content/src/section.rs
index 920f863ee6..d4c84a9bd3 100644
--- a/components/content/src/section.rs
+++ b/components/content/src/section.rs
@@ -283,7 +283,7 @@ mod tests {
         create_dir_all(path.join(&article_path).join("foo/baz/quux"))
             .expect("create nested temp dir");
         let mut f = File::create(article_path.join("_index.md")).unwrap();
-        f.write_all(b"+++\nslug=\"hey\"\n+++\n").unwrap();
+        f.write_all(b"+++\n+++\n").unwrap();
         File::create(article_path.join("example.js")).unwrap();
         File::create(article_path.join("graph.jpg")).unwrap();
         File::create(article_path.join("fail.png")).unwrap();
diff --git a/test_site_i18n/content/blog/_index.fr.md b/test_site_i18n/content/blog/_index.fr.md
index 8e1497c0d8..80e98f723f 100644
--- a/test_site_i18n/content/blog/_index.fr.md
+++ b/test_site_i18n/content/blog/_index.fr.md
@@ -1,7 +1,7 @@
 +++
 title = "Mon blog"
 sort_by = "date"
-insert_anchors = "right"
+insert_anchor_links = "right"
 +++
 
 [Dernières nouvelles](#news)
diff --git a/test_site_i18n/content/blog/_index.it.md b/test_site_i18n/content/blog/_index.it.md
index 5e008825b4..6a2f151212 100644
--- a/test_site_i18n/content/blog/_index.it.md
+++ b/test_site_i18n/content/blog/_index.it.md
@@ -1,5 +1,5 @@
 +++
 title = "Il mio blog"
 sort_by = "date"
-insert_anchors = "right"
+insert_anchor_links = "right"
 +++
diff --git a/test_site_i18n/content/blog/_index.md b/test_site_i18n/content/blog/_index.md
index a0b42407cd..bab311ae07 100644
--- a/test_site_i18n/content/blog/_index.md
+++ b/test_site_i18n/content/blog/_index.md
@@ -1,5 +1,5 @@
 +++
 title = "My blog"
 sort_by = "date"
-insert_anchors = "left"
+insert_anchor_links = "left"
 +++