From dbef527278c9beebfdeaa7b36c036aaff3ca114d Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Mon, 6 Feb 2023 19:35:08 +0200 Subject: feat: add dummy brokenlinks directive We won't want this in the long run, but it helps while I test with my journal. Sponsored-by: author --- src/directive/brokenlinks.rs | 26 ++++++++++++++++++++++++++ src/directive/mod.rs | 14 ++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 src/directive/brokenlinks.rs diff --git a/src/directive/brokenlinks.rs b/src/directive/brokenlinks.rs new file mode 100644 index 0000000..b95c0aa --- /dev/null +++ b/src/directive/brokenlinks.rs @@ -0,0 +1,26 @@ +use crate::directive::{DirectiveError, DirectiveImplementation, Processed}; +use crate::page::PageMeta; +use crate::site::Site; +use crate::wikitext::ParsedDirective; +use log::warn; + +#[derive(Debug, Default, Eq, PartialEq)] +pub struct Brokenlinks {} + +impl DirectiveImplementation for Brokenlinks { + const REQUIRED: &'static [&'static str] = &["pages"]; + const ALLOWED: &'static [&'static str] = &[]; + const ALLOW_ANY_UNNAMED: bool = false; + + fn from_parsed(_: &ParsedDirective) -> Self { + Self::default() + } + + fn process(&self, _site: &Site, meta: &mut PageMeta) -> Result { + warn!( + "page {} uses unimplemented brokenlinks", + meta.path().display() + ); + Ok(Processed::Markdown("\n".into())) + } +} diff --git a/src/directive/mod.rs b/src/directive/mod.rs index 4efde55..a5f6b77 100644 --- a/src/directive/mod.rs +++ b/src/directive/mod.rs @@ -61,6 +61,7 @@ pub enum Directive { QuotedArg, MultilineArg, + Brokenlinks(Brokenlinks), Calendar(Calendar), Format(Format), Graph(Graph), @@ -111,6 +112,15 @@ impl TryFrom<&ParsedDirective> for Directive { Directive::MultilineArg } + "brokenlinks" => { + Self::check_args( + p, + Brokenlinks::REQUIRED, + Brokenlinks::ALLOWED, + Brokenlinks::ALLOW_ANY_UNNAMED, + )?; + Directive::Brokenlinks(Brokenlinks::from_parsed(p)) + } "calendar" => { Self::check_args( p, @@ -264,6 +274,7 @@ impl Directive { | Self::MultilineArg => { panic!("directive {:?} may only be used in parsing tests", self) } + Self::Brokenlinks(x) => x.process(site, meta), Self::Calendar(x) => x.process(site, meta), Self::Format(x) => x.process(site, meta), Self::Graph(x) => x.process(site, meta), @@ -323,3 +334,6 @@ use calendar::Calendar; mod sidebar; use sidebar::Sidebar; + +mod brokenlinks; +use brokenlinks::Brokenlinks; -- cgit v1.2.1