Skip to main content

MetaTagGroups

Struct MetaTagGroups 

Source
#[non_exhaustive]
pub struct MetaTagGroups { pub apple: String, pub primary: String, pub og: String, pub ms: String, pub twitter: String, }
Expand description

Holds collections of meta tags for different platforms and categories.

Each field is the rendered <meta> elements of one group, one per line. MetaTagGroups::iter gives the same tags as values.

§Example

use metadata_gen::metatags::generate_metatags;
use metadata_gen::MetadataMap;

let mut metadata = MetadataMap::new();
metadata.insert("description".to_string(), "A sample page".to_string());
metadata.insert("og:title".to_string(), "Sample".to_string());

let tags = generate_metatags(&metadata);
assert!(tags.primary.contains("description"));
assert!(tags.og.contains(r#"property="og:title""#));

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§apple: String

Meta tags specific to Apple devices.

§primary: String

Primary meta tags (description, keywords, author, viewport).

§og: String

Open Graph meta tags.

§ms: String

Microsoft-specific meta tags.

§twitter: String

Twitter meta tags.

Implementations§

Source§

impl MetaTagGroups

Source

pub fn add_custom_tag(&mut self, name: &str, content: &str)

Adds a custom meta tag to the appropriate group, chosen by its name: apple-* and mobile-web-app-capable go to apple, msapplication-* to ms, Open Graph prefixes to og, twitter:* to twitter, everything else to primary.

§Example
use metadata_gen::MetaTagGroups;

let mut groups = MetaTagGroups::default();
groups.add_custom_tag("og:locale", "en_GB");
assert_eq!(groups.og, r#"<meta property="og:locale" content="en_GB">"#);
Source

pub fn format_meta_tag(&self, name: &str, content: &str) -> String

Formats one meta tag as MetaTag::render does.

§Example
use metadata_gen::MetaTagGroups;

let groups = MetaTagGroups::default();
assert_eq!(
    groups.format_meta_tag("description", r#"say "hi""#),
    r#"<meta name="description" content="say &quot;hi&quot;">"#
);
Source

pub fn generate_apple_meta_tags(&mut self, metadata: &MetadataMap)

Generates the Apple-specific group from metadata.

Source

pub fn generate_primary_meta_tags(&mut self, metadata: &MetadataMap)

Generates the primary group (author, description, keywords, viewport) from metadata.

Source

pub fn generate_og_meta_tags(&mut self, metadata: &MetadataMap)

Generates the Open Graph group from metadata.

Source

pub fn generate_ms_meta_tags(&mut self, metadata: &MetadataMap)

Generates the Microsoft-specific group from metadata.

Source

pub fn generate_twitter_meta_tags(&mut self, metadata: &MetadataMap)

Generates the Twitter group from metadata.

Source

pub fn generate_tags(&self, metadata: &MetadataMap, tags: &[&str]) -> String

Renders every tag in tags that has a value in metadata, one per line, in the order given.

§Example
use metadata_gen::{MetaTagGroups, MetadataMap};

let mut metadata = MetadataMap::new();
metadata.insert("author".into(), "Ada".into());
let groups = MetaTagGroups::default();
assert_eq!(
    groups.generate_tags(&metadata, &["author", "missing"]),
    r#"<meta name="author" content="Ada">"#
);
Source

pub fn iter(&self) -> impl Iterator<Item = MetaTag> + '_

Every rendered element across the five groups, in group order, as MetaTag values again.

§Example
use metadata_gen::MetaTagGroups;

let mut groups = MetaTagGroups::default();
groups.add_custom_tag("og:title", "T");
groups.add_custom_tag("author", "A");
let names: Vec<String> = groups.iter().map(|t| t.name).collect();
assert_eq!(names, ["author", "og:title"]);

Trait Implementations§

Source§

impl Clone for MetaTagGroups

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MetaTagGroups

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MetaTagGroups

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for MetaTagGroups

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for MetaTagGroups

Source§

impl Hash for MetaTagGroups

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for MetaTagGroups

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for MetaTagGroups

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.