Merge pull request #8 from SaraVieira/meta-proprety

Add proprety in meta tags
This commit is contained in:
ashley williams 2022-12-19 11:03:39 -06:00 committed by GitHub
commit e073a67193
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 0 deletions

View File

@ -78,6 +78,8 @@ declare_elements! {
content: String, content: String,
http_equiv: HTTPEquiv, http_equiv: HTTPEquiv,
name: Metadata, name: Metadata,
// non standard, uses https://en.wikipedia.org/wiki/RDFa
property: MetadataProperties,
} in [MetadataContent]; } in [MetadataContent];
style { style {
type: Mime, type: Mime,
@ -459,3 +461,16 @@ fn test_data_attributes() {
assert_eq!("<div data-id=\"1234\">Boo!</div>", frag.to_string()); assert_eq!("<div data-id=\"1234\">Boo!</div>", frag.to_string());
} }
#[test]
fn test_meta_tags() {
use crate as axohtml;
use crate::{dom::DOMTree, html};
let frag: DOMTree<String> = html!(<meta property="og:url" content="http://example.com"/>
);
assert_eq!(
"<meta content=\"http://example.com\" property=\"og:url\"/>",
frag.to_string()
);
}

View File

@ -254,6 +254,32 @@ pub enum Metadata {
Viewport, Viewport,
} }
#[derive(EnumString, Display, PartialEq, Eq, PartialOrd, Ord, AsRefStr, IntoStaticStr)]
pub enum MetadataProperties {
#[strum(to_string = "og:title")]
Title,
#[strum(to_string = "og:type")]
Type,
#[strum(to_string = "og:image")]
Image,
#[strum(to_string = "og:url")]
Homepage,
#[strum(to_string = "og:audio")]
Audio,
#[strum(to_string = "og:description")]
Description,
#[strum(to_string = "og:determiner")]
Determiner,
#[strum(to_string = "og:locale")]
Locale,
#[strum(to_string = "og:site_name")]
ParentSiteName,
#[strum(to_string = "og:video")]
Video,
#[strum(to_string = "og:locale:alternate")]
ExtraLocales,
}
#[derive(EnumString, Display, PartialEq, Eq, PartialOrd, Ord, AsRefStr, IntoStaticStr)] #[derive(EnumString, Display, PartialEq, Eq, PartialOrd, Ord, AsRefStr, IntoStaticStr)]
pub enum OnOff { pub enum OnOff {
#[strum(to_string = "on")] #[strum(to_string = "on")]