diff --git a/Cargo.toml b/Cargo.toml index b68969f..8d67cf1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "actix-webfinger" description = "Types and helpers to create and fetch Webfinger resources" -version = "0.3.0-alpha.3" +version = "0.3.0-alpha.4" license = "GPL-3.0" authors = ["asonix "] repository = "https://git.asonix.dog/Aardwolf/actix-webfinger" diff --git a/README.md b/README.md index 0478d59..5f4a838 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ First, add Actix Webfinger as a dependency [dependencies] actix = "0.10.0-alpha.1" actix-web = "3.0.0-alpha.1" -actix-webfinger = "0.3.0-alpha.3" +actix-webfinger = "0.3.0-alpha.4" ``` Then use it in your application diff --git a/src/lib.rs b/src/lib.rs index a834626..634a34f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -467,7 +467,9 @@ impl Webfinger { &self.links } - /// Add an Activitypub link to this Webfinger + /// Add an ActivityPub link to this Webfinger + /// + /// Since ActivityPub extends JsonLD, this also adds an ActivityStreams JsonLD link pub fn add_activitypub(&mut self, href: &str) -> &mut Self { self.links.push(Link { rel: "self".to_owned(), @@ -475,10 +477,21 @@ impl Webfinger { href: Some(href.to_owned()), template: None, }); + self.add_json_ld(href, "https://www.w3.org/ns/activitystreams") + } + + /// Add a JsonLD Link to this Webfinger + pub fn add_json_ld(&mut self, href: &str, context: &str) -> &mut Self { + self.links.push(Link { + rel: "self".to_owned(), + kind: Some(format!("application/ld+json; context=\"{}\"", context)), + href: Some(href.to_owned()), + template: None, + }); self } - /// Get an Activitypub link from this Webfinger + /// Get an ActivityPub link from this Webfinger pub fn activitypub(&self) -> Option<&Link> { self.links.iter().find(|l| { l.rel == "self" @@ -489,6 +502,17 @@ impl Webfinger { }) } + /// Get a JsonLD link from this Webfinger + pub fn json_ld(&self) -> Option<&Link> { + self.links.iter().find(|l| { + l.rel == "self" + && l.kind + .as_ref() + .map(|k| k.starts_with("application/ld+json")) + .unwrap_or(false) + }) + } + /// Add a profile link to this Webfinger pub fn add_profile(&mut self, href: &str) -> &mut Self { self.links.push(Link {