Skip to content

Commit

Permalink
Add meta robots helper (lambda-fairy#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
ernestas-poskus authored and lambda-fairy committed Aug 26, 2017
1 parent b4faef8 commit 4d46029
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions maud_extras/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,34 @@ impl<T: AsRef<str>, U: AsRef<str>> Render for MetaProperty<T, U> {
}
}
}

/// Generate a `<meta robots>` element.
///
/// # Example
///
/// ```rust
/// # #![feature(proc_macro)]
/// # extern crate maud;
/// # extern crate maud_extras;
/// # use maud::html;
/// # use maud_extras::*;
/// # fn main() {
/// let markup = html! { (MetaRobots { index: true, follow: false }) };
/// assert_eq!(markup.into_string(),
/// r#"<meta name="robots" content="index,nofollow">"#);
/// # }
/// ```
pub struct MetaRobots {
pub index: bool,
pub follow: bool,
}

impl Render for MetaRobots {
fn render(&self) -> Markup {
let index = if self.index { "index" } else { "noindex" };
let follow = if self.follow { "follow" } else { "nofollow" };
html! {
meta name="robots" content={ (index) "," (follow) } /
}
}
}

0 comments on commit 4d46029

Please sign in to comment.