2020-05-01 23:43:37 +00:00
|
|
|
#lang racket
|
|
|
|
|
|
|
|
;; static generation rules
|
|
|
|
|
|
|
|
(require json
|
2020-05-02 08:17:22 +00:00
|
|
|
net/url-string
|
2020-05-04 05:54:07 +00:00
|
|
|
"compile.rkt"
|
|
|
|
"prefs.rkt")
|
2020-05-02 08:17:22 +00:00
|
|
|
|
2020-05-01 23:43:37 +00:00
|
|
|
(define ACTOR-CONTEXT
|
|
|
|
(list "https://www.w3.org/ns/activitystreams"
|
|
|
|
"https://w3id.org/security/v1"
|
|
|
|
(hash 'manuallyApprovesFollowers "as:manuallyApprovesFollowers"
|
|
|
|
'sensitive "as:sensitive"
|
2020-05-04 05:54:07 +00:00
|
|
|
'movedTo (hash '@id "as:movedTo"
|
|
|
|
'@type "@id")
|
|
|
|
'alsoKnownAs (hash '@id "as:alsoKnownAs"
|
|
|
|
'@type "@id")
|
2020-05-01 23:43:37 +00:00
|
|
|
'Hashtag "as:Hashtag"
|
2020-05-04 05:54:07 +00:00
|
|
|
;; i like how there's actually nothing in this ns
|
|
|
|
;; thanks eugen lmao
|
2020-05-01 23:43:37 +00:00
|
|
|
'toot "http://joinmastodon.org/ns#"
|
|
|
|
'Emoji "toot:Emoji"
|
|
|
|
'focalPoint (hash '@container "@list"
|
2020-05-04 05:54:07 +00:00
|
|
|
'@id "toot:focalPoint")
|
|
|
|
'featured (hash '@id "toot:featured"
|
|
|
|
'@type "@id")
|
|
|
|
'schema "http://schema.org#"
|
|
|
|
'PropertyValue "schema:PropertyValue"
|
|
|
|
'value "schema:value"
|
|
|
|
'discoverable "toot:discoverable"
|
|
|
|
;; todo put an actual ns here
|
|
|
|
'awoo "https://awoo.systems/ns#"
|
|
|
|
;; misskey has no ns for this so i'm stealing it
|
|
|
|
'isCat "awoo:isCat"
|
|
|
|
;; yeah ok why not lol
|
|
|
|
'pronouns "awoo:pronouns")))
|
2020-05-01 23:43:37 +00:00
|
|
|
|
|
|
|
(define compile-index-json
|
2020-05-02 08:17:22 +00:00
|
|
|
(rule '("db/actorkey.pub" "src/instance.rktd" "src/bio.md") "public/index.json"
|
2020-05-01 23:43:37 +00:00
|
|
|
(lambda (in out)
|
|
|
|
(define key (port->string (hash-ref in "db/actorkey.pub")))
|
2020-05-04 05:54:07 +00:00
|
|
|
(define prefs (prefs-load (hash-ref in "src/instance.rktd")))
|
2020-05-02 08:17:22 +00:00
|
|
|
(define bio (port->string (hash-ref in "src/bio.md")))
|
2020-05-04 05:54:07 +00:00
|
|
|
(define (render-pronouns)
|
|
|
|
(define p (prefs-get prefs 'pronouns))
|
|
|
|
(match p
|
|
|
|
[(list a b _ ...) (format "~a/~a" a b)]
|
|
|
|
[_ "any"]))
|
|
|
|
(define instance-url (prefs-get prefs 'instance-url))
|
2020-05-01 23:43:37 +00:00
|
|
|
(define actor (hash
|
|
|
|
'@context ACTOR-CONTEXT
|
|
|
|
'Type "Person"
|
2020-05-02 08:17:22 +00:00
|
|
|
'id instance-url
|
2020-05-04 05:54:07 +00:00
|
|
|
'name (prefs-get prefs 'display-name)
|
|
|
|
'preferredUsername (prefs-get prefs 'name)
|
|
|
|
'discoverable (prefs-get prefs 'make-discoverable)
|
|
|
|
'isCat (prefs-get prefs 'is-cat)
|
|
|
|
'pronouns (hash 'en (prefs-get prefs 'pronouns))
|
2020-05-01 23:43:37 +00:00
|
|
|
'icon (hash 'type "Image"
|
2020-05-04 05:54:07 +00:00
|
|
|
'url "something"
|
|
|
|
'sensitive #f)
|
2020-05-01 23:43:37 +00:00
|
|
|
'image (hash 'type "Image"
|
|
|
|
'url "something"
|
|
|
|
'sensitive #f)
|
|
|
|
'tag (list (hash 'type "Hashtag"
|
2020-05-04 05:54:07 +00:00
|
|
|
'href (string-append instance-url "tags/blahaj")
|
|
|
|
'name "#blahaj"))
|
2020-05-01 23:43:37 +00:00
|
|
|
'manuallyApprovesFollowers #f
|
2020-05-02 08:17:22 +00:00
|
|
|
'summary bio
|
2020-05-01 23:43:37 +00:00
|
|
|
'attachment (list (hash 'type "PropertyValue"
|
2020-05-04 05:54:07 +00:00
|
|
|
'name "pronouns"
|
|
|
|
'value (render-pronouns)))
|
2020-05-02 08:17:22 +00:00
|
|
|
'url instance-url
|
|
|
|
'inbox (string-append instance-url "inbox")
|
|
|
|
'sharedInbox (string-append instance-url "inbox")
|
|
|
|
'endpoints (hash 'sharedInbox (string-append instance-url "inbox"))
|
|
|
|
'outbox (string-append instance-url "outbox")
|
2020-05-01 23:43:37 +00:00
|
|
|
'following 'null
|
2020-05-02 08:17:22 +00:00
|
|
|
'followers (string-append instance-url "followers")
|
2020-05-01 23:43:37 +00:00
|
|
|
'liked 'null
|
2020-05-02 08:17:22 +00:00
|
|
|
'publicKey (hash 'id (string-append instance-url "#main-key")
|
2020-05-04 05:54:07 +00:00
|
|
|
'type "Key"
|
|
|
|
'owner instance-url
|
|
|
|
'publicKeyPem key)))
|
2020-05-01 23:43:37 +00:00
|
|
|
(write-json actor out))))
|
|
|
|
|
2020-05-02 08:17:22 +00:00
|
|
|
(define compile-webfinger
|
|
|
|
(rule '("src/instance.rktd") "public/webfinger.json"
|
|
|
|
(lambda (in out)
|
2020-05-04 05:54:07 +00:00
|
|
|
(define prefs (prefs-load (hash-ref in "src/instance.rktd")))
|
|
|
|
(define instance-url (prefs-get prefs 'instance-url))
|
2020-05-02 08:17:22 +00:00
|
|
|
(define host (url-host (string->url instance-url)))
|
2020-05-04 05:54:07 +00:00
|
|
|
(define name (prefs-get prefs 'name))
|
2020-05-02 08:17:22 +00:00
|
|
|
(define webfinger
|
|
|
|
(hash
|
|
|
|
'subject (format "acct:~a@~a" name host)
|
|
|
|
'links (list (hash
|
|
|
|
'rel "self"
|
|
|
|
'type "application/activity+json"
|
|
|
|
'href instance-url))))
|
|
|
|
(write-json webfinger out))))
|
|
|
|
|
2020-05-01 23:43:37 +00:00
|
|
|
(define compiler-rules
|
2020-05-02 08:17:22 +00:00
|
|
|
(set compile-index-json
|
|
|
|
compile-webfinger))
|
2020-05-01 23:43:37 +00:00
|
|
|
|
|
|
|
(define ops (generate-operations compiler-rules))
|
|
|
|
(for ([op (in-list ops)])
|
|
|
|
(printf "executing ~s\n" op)
|
|
|
|
(execute-rule op))
|