chomp/private/rules.rkt

94 lines
4.1 KiB
Racket
Raw Normal View History

2020-05-01 23:43:37 +00:00
#lang racket
;; static generation rules
(require json
net/url-string
2020-05-01 23:43:37 +00:00
"compile.rkt")
(define (get-pref prefs what)
(match prefs
[(list _ ... (list (? (curry symbol=? what)) value) _ ...) value]
[_ (error "no such pref" prefs what)]))
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"
'movedTo "as:movedTo"
'Hashtag "as:Hashtag"
'toot "http://joinmastodon.org/ns#"
'Emoji "toot:Emoji"
'focalPoint (hash '@container "@list"
'@id "toot:focalPoint")
'featured "toot:featured")))
(define compile-index-json
(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")))
(define prefs (read (hash-ref in "src/instance.rktd")))
(define instance-url (get-pref prefs 'shonks:instance-url))
(define display-name (get-pref prefs 'shonks:display-name))
(define name (get-pref prefs 'shonks:name))
(define bio (port->string (hash-ref in "src/bio.md")))
2020-05-01 23:43:37 +00:00
(define actor (hash
'@context ACTOR-CONTEXT
'Type "Person"
'id instance-url
'name display-name
'preferredUsername name
2020-05-01 23:43:37 +00:00
'icon (hash 'type "Image"
'url "something"
'sensitive #f)
'image (hash 'type "Image"
'url "something"
'sensitive #f)
'tag (list (hash 'type "Hashtag"
'href (string-append instance-url "tags/blahaj")
2020-05-01 23:43:37 +00:00
'name "#blahaj"))
'manuallyApprovesFollowers #f
'summary bio
2020-05-01 23:43:37 +00:00
'attachment (list (hash 'type "PropertyValue"
'name "pronouns"
'value "they/them"))
'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
'followers (string-append instance-url "followers")
2020-05-01 23:43:37 +00:00
'liked 'null
'publicKey (hash 'id (string-append instance-url "#main-key")
2020-05-01 23:43:37 +00:00
'type "Key"
'owner instance-url
2020-05-01 23:43:37 +00:00
'publicKeyPem key)))
(write-json actor out))))
(define compile-webfinger
(rule '("src/instance.rktd") "public/webfinger.json"
(lambda (in out)
(define prefs (read (hash-ref in "src/instance.rktd")))
(define instance-url (get-pref prefs 'shonks:instance-url))
(define host (url-host (string->url instance-url)))
(define name (get-pref prefs 'shonks:name))
(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
(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))