Compare commits

..

4 Commits

Author SHA1 Message Date
Shadowfacts 320ba3fc67
AP: actor tweaks 2019-02-18 13:58:12 -05:00
Shadowfacts 48368ae6e4
AP: fix object generation 2019-02-18 13:53:35 -05:00
Shadowfacts 8f73cd8106
Start ActivityPub stuff 2019-02-18 13:47:43 -05:00
Shadowfacts c25ecdc5b1
Fix extra margin on footer links 2019-02-16 14:45:40 -05:00
6 changed files with 106 additions and 4 deletions

View File

@ -0,0 +1,92 @@
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",
"name": "shadowfacts' blog",
"icon": {
"type": "Image",
"mediaType": "image/png",
"url": `https://${baseURL}/shadowfacts.png`
},
"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",

View File

@ -337,9 +337,12 @@ figure {
li {
list-style: none;
display: inline;
margin-right: 1em;
font-variant: small-caps;
font-weight: bold;
&:not(:last-child) {
margin-right: 1em;
}
}
}