Start ActivityPub stuff

This commit is contained in:
Shadowfacts 2019-02-18 13:47:43 -05:00
parent c25ecdc5b1
commit 8f73cd8106
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
5 changed files with 88 additions and 3 deletions

View File

@ -0,0 +1,78 @@
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);
util.write(`ap/posts/${post.metadata.permalink}.json`, 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`
}
]
};
}

View File

@ -1,3 +1,4 @@
import activitypub from "./activitypub";
import categories from "./categories";
import copy from "./copy";
import css from "./css";
@ -9,6 +10,7 @@ import rss from "./rss";
import tutorials from "./tutorials";
export = {
activitypub,
categories,
copy,
css,

View File

@ -11,7 +11,9 @@ async function generate() {
generators.homepage(posts);
generators.redirects(posts);
const categories = await generators.categories(posts);
generators.rss(posts, categories, tutorials);
await generators.rss(posts, categories, tutorials);
generators.activitypub(posts);
}
generate();

View File

@ -18,6 +18,7 @@ export interface PostMetadata extends Metadata {
category: string;
date: string | Date;
excerpt?: string;
uuid: string;
}
export async function get(path: string): Promise<Page> {

View File

@ -5,7 +5,8 @@
"license": "UNLICENSED",
"scripts": {
"generate": "tsc -p . && node built/index.js",
"serve": "npm run generate && http-server out"
"serve": "npm run generate && http-server out",
"generate-post": "node bin/generate-post.js"
},
"dependencies": {
"@sindresorhus/slugify": "^0.6.0",
@ -14,7 +15,8 @@
"highlight.js": "^9.13.1",
"markdown-it": "^8.4.2",
"node-sass": "^4.11.0",
"typescript": "^3.2.2"
"typescript": "^3.2.2",
"uuid": "^3.3.2"
},
"devDependencies": {
"@types/ejs": "^2.6.1",