86 lines
2.2 KiB
TypeScript
86 lines
2.2 KiB
TypeScript
import path from "path";
|
|
import { Page, PostMetadata } from "../metadata";
|
|
import * as util from "../util";
|
|
|
|
const baseURL = process.env.BASE_URL || "shadowfacts.net";
|
|
|
|
export default async function activitypub(posts: Page[]) {
|
|
for (const post of posts) {
|
|
const object = postObject(post);
|
|
const dir = path.dirname(post.metadata.permalink);
|
|
const base = path.basename(post.metadata.permalink);
|
|
const dest = path.format({
|
|
dir,
|
|
name: base,
|
|
ext: ".json"
|
|
});
|
|
util.write(dest, JSON.stringify(object));
|
|
}
|
|
|
|
util.write("ap/actor", JSON.stringify(actorObject()))
|
|
|
|
util.write(".well-known/webfinger", JSON.stringify(webfingerObject()));
|
|
}
|
|
|
|
function postObject(post: Page): object {
|
|
const postMeta = <PostMetadata>post.metadata;
|
|
return {
|
|
"@context": [
|
|
"https://www.w3.org/ns/activitystreams"
|
|
],
|
|
"type": "Article",
|
|
"id": `https://${baseURL}${postMeta.permalink}.json`,
|
|
"published": (<Date>postMeta.date).toISOString(),
|
|
"inReplyTo": null,
|
|
"url": `https://${baseURL}${postMeta.permalink}`,
|
|
"attributedTo": `https://${baseURL}/ap/actor`,
|
|
"to": [
|
|
"https://www.w3.org/ns/activitystreams#Public"
|
|
],
|
|
"cc": [],
|
|
"name": postMeta.title,
|
|
"content": post.text
|
|
};
|
|
}
|
|
|
|
function actorObject() {
|
|
return {
|
|
"@context": [
|
|
"https://www.w3.org/ns/activitystreams",
|
|
"https://w3id.org/security/v1"
|
|
],
|
|
"type": "Person",
|
|
"id": `https://${baseURL}/ap/actor`,
|
|
"preferredUsername": "shadowfacts",
|
|
"inbox": `https://${baseURL}/ap/inbox`,
|
|
"publicKey": {
|
|
"id": `https://${baseURL}/ap/actor#main-key`,
|
|
"owner": `https://${baseURL}/ap/actor`,
|
|
"publicKeyPem":
|
|
`
|
|
-----BEGIN PUBLIC KEY-----
|
|
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxsePhOEq6EqqgGe+5vKa
|
|
ti8cnvLoP3eJDTHENxX4M9epMIeo48cI214wkAERoNufZLtYeGOHO6YJcVydVSYN
|
|
Ud4lQxgaPwAlh0DB0BUrXR1yfcSAhHS86XBSUq86O3fY5V+vEdZiN5PfUCG5rg5t
|
|
5V/TrcbVQngXqDmwVZ/OcJ+5vUo+B62Mul7EmiNkZHKzp1VZGVtZ6nZ/4TxsdeSN
|
|
XT8Vb0f/GJQOQLzW6dV0CBupts6x7o+9oRiYiAH+cXLFyQdTQ+1TrqMSMscdfX9I
|
|
Kos5Ih7oKdj6wQt0pDEOGx090c9JzQC25RzxRk7jc1Jt1UzDi/a1U/BbucxIvPr3
|
|
PQIDAQAB
|
|
-----END PUBLIC KEY-----
|
|
`
|
|
}
|
|
};
|
|
}
|
|
|
|
function webfingerObject() {
|
|
return {
|
|
"subject": `acct:shadowfacts@${baseURL}`,
|
|
"links": [
|
|
{
|
|
"rel": "self",
|
|
"type": "application/activity+json",
|
|
"href": `https://${baseURL}/ap/actor`
|
|
}
|
|
]
|
|
};
|
|
} |