Skip to content

Commit

Permalink
Add meta robots helper
Browse files Browse the repository at this point in the history
  • Loading branch information
ernestas-poskus committed Aug 25, 2017
1 parent b4faef8 commit fe4413a
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions maud_extras/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,39 @@ 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::new(true,false)) };
/// assert_eq!(markup.into_string(),
/// r#"<meta name="robots" content="index,nofollow">"#);
/// # }
/// ```
pub struct MetaRobots {
pub index: bool,
pub follow: bool,
}
impl MetaRobots {
pub fn new(index: bool, follow: bool) -> MetaRobots {
MetaRobots { index, follow }
}
}

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 fe4413a

Please sign in to comment.