Add Json LD link
This commit is contained in:
parent
eccdcd8654
commit
5e48aa725d
3 changed files with 28 additions and 4 deletions
|
@ -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 <asonix@asonix.dog>"]
|
||||
repository = "https://git.asonix.dog/Aardwolf/actix-webfinger"
|
||||
|
|
|
@ -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
|
||||
|
|
28
src/lib.rs
28
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 {
|
||||
|
|
Loading…
Reference in a new issue