From b7824e090784205c156984e4d666cac31df12711 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Fri, 14 Mar 2025 15:22:07 +0530 Subject: [PATCH 1/2] feat(wip): start moving in static ActivityPub configuration --- netlify.toml | 9 ++-- netlify/edge-functions/webfinger/webfinger.ts | 50 ------------------- static/.well-known/webfinger | 18 +++++++ static/@blog | 44 ++++++++++++++++ 4 files changed, 67 insertions(+), 54 deletions(-) delete mode 100755 netlify/edge-functions/webfinger/webfinger.ts create mode 100644 static/.well-known/webfinger create mode 100644 static/@blog diff --git a/netlify.toml b/netlify.toml index 41dfa1b1..7b3cf587 100644 --- a/netlify.toml +++ b/netlify.toml @@ -13,10 +13,6 @@ NODE_VERSION = "18" path = "/*" function = "root" -[[edge_functions]] -function = "webfinger" -path = "/.well-known/webfinger" - [[redirects]] from = "/robots.txt" to = "/robots.txt" @@ -49,3 +45,8 @@ X-XSS-Protection = '1; mode=block' for = "/pretty-feed-v3.xsl" [headers.values] Content-Type = "application/xml; charset=utf-8" + +[[headers]] +for = "/@blog" +[headers.values] +Content-Type = "application/activity+json; charset=utf-8" diff --git a/netlify/edge-functions/webfinger/webfinger.ts b/netlify/edge-functions/webfinger/webfinger.ts deleted file mode 100755 index 361210ad..00000000 --- a/netlify/edge-functions/webfinger/webfinger.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { Status } from "https://deno.land/std@0.136.0/http/http_status.ts"; -import type { Context } from "https://edge.netlify.com"; - -export default async (request: Request, context: Context) => { - const url = new URL(request.url); - const resourceParam = url.searchParams.get("resource"); - if (resourceParam === null) { - return context.json( - { - error: "No 'resource' query parameter was provided", - }, - { - status: Status.BadRequest, - }, - ); - } else if (resourceParam !== "acct:harsh@msfjarvis.dev") { - return context.json( - { - error: "An invalid identity was requested", - }, - { - status: Status.BadRequest, - }, - ); - } else { - return context.json({ - subject: "acct:msfjarvis@androiddev.social", - aliases: [ - "https://androiddev.social/@msfjarvis", - "https://androiddev.social/users/msfjarvis", - ], - links: [ - { - rel: "http://webfinger.net/rel/profile-page", - type: "text/html", - href: "https://androiddev.social/@msfjarvis", - }, - { - rel: "self", - type: "application/activity+json", - href: "https://androiddev.social/users/msfjarvis", - }, - { - rel: "http://ostatus.org/schema/1.0/subscribe", - template: "https://androiddev.social/authorize_interaction?uri={uri}", - }, - ], - }); - } -}; diff --git a/static/.well-known/webfinger b/static/.well-known/webfinger new file mode 100644 index 00000000..dbb77970 --- /dev/null +++ b/static/.well-known/webfinger @@ -0,0 +1,18 @@ +{ + "subject": "acct:blog@msfjarvis.dev", + "aliases": [ + "https://msfjarvis.dev/@blog" + ], + "links": [ + { + "rel": "self", + "type": "application/activity+json", + "href": "https://msfjarvis.dev/@blog" + }, + { + "rel":"http://webfinger.net/rel/profile-page", + "type":"text/html", + "href":"https://msfjarvis.dev/" + } + ] +} diff --git a/static/@blog b/static/@blog new file mode 100644 index 00000000..b7e99da6 --- /dev/null +++ b/static/@blog @@ -0,0 +1,44 @@ +{ + "@context": "https://www.w3.org/ns/activitystreams", + "id": "https://msfjarvis.dev/@blog", + "type": "Person", + "following": "https://androiddev.social/users/msfjarvis/following", + "followers": "https://androiddev.social/users/msfjarvis/followers", + "inbox": "https://activitypubdotnet.azurewebsites.net/api/Inbox", + "outbox": "https://msfjarvis.dev/socialweb/outbox", + "preferredUsername": "blog", + "name": "Harsh Shandilya - Blog", + "summary": "Ramblings of a recovering Android engineer", + "url": "https://msfjarvis.dev/", + "discoverable": true, + "memorial": false, + "icon": { + "type": "Image", + "mediaType": "image/webp", + "url": "https://msfjarvis.dev/android-chrome-512x512.webp" + }, + "image": { + "type": "Image", + "mediaType": "image/webp", + "url": "https://msfjarvis.dev/android-chrome-512x512.webp" + }, + "publicKey": { + "@context": "https://w3id.org/security/v1", + "@type": "Key", + "id": "https://msfjarvis.dev/@blog#main-key", + "owner": "https://msfjarvis.dev/@blog", + "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAo6NNG4RG9L2gMsfqq8iB\nIa9Vw5BNliD8RJDO7AShupqRAbgjeRyO7xjat//fwlwVRArNEVmBlfHouPCWNNWb\nuEQEJhYYWbrXPE2qiggtUuKT+yfOrt9cmj2wZFuTwc7ZjCq3QbIiidrh9SXuZJZm\n8bRZB3RHfv1WZPFx/YOthmQysBfTkPp6ifE+s9GA0yUUA39ezOfKGzrI6phxxb7W\n2w4PcQFAvwZMlbEBsIv5YIBScMpTATA23bzyx5P2LzOvApJxppx8erU/ViqoQBab\nKJkSFta+9YlbYsC+hrKJX5FAjZHeOp4HZ1AkpghB92AUNYGXVKQMiDbcGRbAUKWF\nIpWvveC+MzkLd9jc2C0UJVY+Lfo97CdySf6+hHIiIZuKJc9wfRAA1MghQZ95Xu7Y\nv/eLNystOmJR91kwBoDI2cMB3aGANGw4odNUI7El00BiDhpwsXSwcEg9tLvoTHPW\nQa6TGutaWjj1RYvtjGvH39ov3uyW10eWaEoN/arlUKerYfNu0pSdME/9Bj6y86aA\nR2+k9kXOapc4IMt4aHr3lBbDE8GUIcv71MBt5HQjwi3gmwGavWu6Da2M4teHnEvK\nJhZCAXC1ptBvJd1WygtCFpyeSANFoev/uJzcRn4abcDxEw2b9b1bKLIbrIpgzHSN\no2IKVhP+FPukC1GaeB0ki1ECAwEAAQ==\n-----END PUBLIC KEY-----" + }, + "attachment": [ + { + "type": "PropertyValue", + "name": "Blog", + "value": "https://msfjarvis.dev" + }, + { + "type": "PropertyValue", + "name": "GitHub", + "value": "https://github.com/msfjarvis" + } + ] +} From 104b871f32063d9aab204bb9e2109fb784aa5443 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Sat, 15 Mar 2025 14:32:30 +0530 Subject: [PATCH 2/2] feat: setup outbox generation --- config.toml | 13 +++++++++ layouts/index.activity_outbox.ajson | 41 +++++++++++++++++++++++++++++ netlify.toml | 5 ++++ 3 files changed, 59 insertions(+) create mode 100644 layouts/index.activity_outbox.ajson diff --git a/config.toml b/config.toml index 5b0a239d..cada8d33 100644 --- a/config.toml +++ b/config.toml @@ -107,3 +107,16 @@ url = "/index.xml" [taxonomies] tag = "tags" category = "categories" + +[mediaTypes] +[mediaTypes."application/activity+json"] +suffixes = ["ajson"] + +[outputFormats] +[outputFormats.ACTIVITY_OUTBOX] +mediaType = "application/activity+json" +notAlternative = true +baseName = "outbox" + +[outputs] +home = ["HTML", "RSS", "ACTIVITY_OUTBOX"] diff --git a/layouts/index.activity_outbox.ajson b/layouts/index.activity_outbox.ajson new file mode 100644 index 00000000..2a590df0 --- /dev/null +++ b/layouts/index.activity_outbox.ajson @@ -0,0 +1,41 @@ +{{- $pctx := . -}} +{{- if .IsHome -}}{{ $pctx = .Site }}{{- end -}} +{{- $pages := slice -}} +{{- if or $.IsHome $.IsSection -}} +{{- $pages = $pctx.RegularPages -}} +{{- else -}} +{{- $pages = $pctx.Pages -}} +{{- end -}} +{{- $limit := .Site.Config.Services.RSS.Limit -}} +{{- if ge $limit 1 -}} +{{- $pages = $pages | first $limit -}} +{{- end -}} +{ + "@context": "https://www.w3.org/ns/activitystreams", + "id": "{{ $.Site.BaseURL }}outbox", + "summary": "{{$.Site.Title}}", + "type": "OrderedCollection", + {{ $notdrafts := where $pages ".Draft" "!=" true }} + {{ $all := where $notdrafts "Type" "in" "posts"}} + "totalItems": {{(len $all)}}, + "orderedItems": [ + {{ range $index, $element := $all }} + {{- if ne $index 0 }}, {{ end }} + { + "@context": "https://www.w3.org/ns/activitystreams", + "id": "{{.Permalink}}-create", + "type": "Create", + "actor": "https://msfjarvis.dev/blog", + "object": { + "id": "{{ .Permalink }}", + "type": "Note", + "content": "{{.Title}}
{{.Summary}}", + "url": "{{.Permalink}}", + "attributedTo": "https://msfjarvis.dev/blog", + "to": "https://www.w3.org/ns/activitystreams#Public", + "published": {{ dateFormat "2006-01-02T15:04:05-07:00" .Date | jsonify }} + } + } + {{end}} + ] +} diff --git a/netlify.toml b/netlify.toml index 7b3cf587..df3ac7c6 100644 --- a/netlify.toml +++ b/netlify.toml @@ -50,3 +50,8 @@ Content-Type = "application/xml; charset=utf-8" for = "/@blog" [headers.values] Content-Type = "application/activity+json; charset=utf-8" + +[[headers]] +for = "/outbox.ajson" +[headers.values] +Content-Type = "application/activity+json; charset=utf-8"