2019-02-18 18:53:35 +00:00
|
|
|
import path from "path";
|
2019-02-18 18:47:43 +00:00
|
|
|
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);
|
2019-02-18 18:53:35 +00:00
|
|
|
const dir = path.dirname(post.metadata.permalink);
|
|
|
|
const base = path.basename(post.metadata.permalink);
|
|
|
|
const dest = path.format({
|
|
|
|
dir,
|
|
|
|
name: base,
|
|
|
|
ext: ".json"
|
|
|
|
});
|
2019-02-18 19:20:06 +00:00
|
|
|
const data = JSON.stringify(object);
|
|
|
|
util.write(dest, data);
|
|
|
|
util.write(path.join(post.metadata.permalink, "index.html.json"), data);
|
2019-02-18 18:47:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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",
|
2019-02-18 23:20:39 +00:00
|
|
|
"id": `https://${baseURL}${post.metadata.permalink}`,
|
2019-02-18 18:47:43 +00:00
|
|
|
"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"
|
|
|
|
],
|
2019-02-18 23:20:39 +00:00
|
|
|
"cc": [
|
|
|
|
`https://${baseURL}/ap/followers`
|
|
|
|
],
|
2019-02-18 18:47:43 +00:00
|
|
|
"name": postMeta.title,
|
|
|
|
"content": post.text
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function webfingerObject() {
|
|
|
|
return {
|
|
|
|
"subject": `acct:shadowfacts@${baseURL}`,
|
|
|
|
"links": [
|
|
|
|
{
|
|
|
|
"rel": "self",
|
|
|
|
"type": "application/activity+json",
|
|
|
|
"href": `https://${baseURL}/ap/actor`
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
}
|