diff --git a/CHANGELOG.md b/CHANGELOG.md index 5810f500..ac3a5220 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## unreleased +## 0.14.0 (unreleased) ### Breaking @@ -24,7 +24,9 @@ - Add `path` to the taxonomy terms to be on par with pages and sections - Add the `base16-aterlierdune-light` syntax highlight theme - Improve link checking: less concurrency and try to not overload the servers -- Allow using POST for `load_data`, along with a body to POST +- Allow using POST for `load_data`, along with a body to POST and allow it to fail +- Add Zig syntax highlighting +- Footnotes links are now stripped from summaries - they were not linking to anything. ## 0.13.0 (2021-01-09) diff --git a/components/front_matter/src/lib.rs b/components/front_matter/src/lib.rs index e343e649..12dd4393 100644 --- a/components/front_matter/src/lib.rs +++ b/components/front_matter/src/lib.rs @@ -12,11 +12,14 @@ pub use page::PageFrontMatter; pub use section::SectionFrontMatter; lazy_static! { - static ref TOML_RE: Regex = - Regex::new(r"^[[:space:]]*\+\+\+(\r?\n(?s).*?(?-s))\+\+\+[[:space:]]*(?:$|(?:\r?\n((?s).*(?-s))$))") - .unwrap(); - static ref YAML_RE: Regex = - Regex::new(r"^[[:space:]]*---(\r?\n(?s).*?(?-s))---[[:space:]]*(?:$|(?:\r?\n((?s).*(?-s))$))").unwrap(); + static ref TOML_RE: Regex = Regex::new( + r"^[[:space:]]*\+\+\+(\r?\n(?s).*?(?-s))\+\+\+[[:space:]]*(?:$|(?:\r?\n((?s).*(?-s))$))" + ) + .unwrap(); + static ref YAML_RE: Regex = Regex::new( + r"^[[:space:]]*---(\r?\n(?s).*?(?-s))---[[:space:]]*(?:$|(?:\r?\n((?s).*(?-s))$))" + ) + .unwrap(); } pub enum RawFrontMatter<'a> { diff --git a/components/library/src/content/page.rs b/components/library/src/content/page.rs index 9a37ecc8..b131e07f 100644 --- a/components/library/src/content/page.rs +++ b/components/library/src/content/page.rs @@ -27,6 +27,8 @@ lazy_static! { static ref RFC3339_DATE: Regex = Regex::new( r"^(?P(\d{4})-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])(T([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)(\.[0-9]+)?(Z|(\+|-)([01][0-9]|2[0-3]):([0-5][0-9])))?)\s?(_|-)(?P.+$)" ).unwrap(); + + static ref FOOTNOTES_RE: Regex = Regex::new(r"\s*.*?").unwrap(); } #[derive(Clone, Debug, Default, PartialEq)] @@ -263,7 +265,11 @@ impl Page { Error::chain(format!("Failed to render content of {}", self.file.path.display()), e) })?; - self.summary = res.summary_len.map(|l| res.body[0..l].to_owned()); + self.summary = if let Some(s) = res.summary_len.map(|l| &res.body[0..l]) { + Some(FOOTNOTES_RE.replace(s, "").into_owned()) + } else { + None + }; self.content = res.body; self.toc = res.toc; self.external_links = res.external_links; @@ -530,6 +536,33 @@ Hello world assert_eq!(page.summary, Some("

Hello world

\n".to_string())); } + #[test] + fn strips_footnotes_in_summary() { + let config = Config::default(); + let content = r#" ++++ ++++ +This page has footnotes, here's one. [^1] + + + +And here's another. [^2] + +[^1]: This is the first footnote. + +[^2]: This is the second footnote."# + .to_string(); + let res = Page::parse(Path::new("hello.md"), &content, &config, &PathBuf::new()); + assert!(res.is_ok()); + let mut page = res.unwrap(); + page.render_markdown(&HashMap::default(), &Tera::default(), &config, InsertAnchor::None) + .unwrap(); + assert_eq!( + page.summary, + Some("

This page has footnotes, here\'s one.

\n".to_string()) + ); + } + #[test] fn page_with_assets_gets_right_info() { let tmp_dir = tempdir().expect("create temp dir");