Fix code blocks

This commit is contained in:
Jeremy Dormitzer 2019-07-12 14:03:10 -04:00
parent adab207cd6
commit 6741cfa343

View File

@ -12,36 +12,36 @@ Ive been doing a lot of research for my current side project, ◊link[#:href
One of the things I wasnt satisfied with in the first version of Pterotype was the way it stores incoming data. ActivityPub messages are serialized in a dialect of JSON called link[#:href "https://json-ld.org/"]{JSON-LD}. I didnt really get JSON-LD when I started this project. It seems overcomplicated and confusing, and I was more interested in shipping something that worked than understanding the theoretical underpinnings of the federated web. So I just kept the incoming data in JSON format. This worked, sort of, but I kept running into annoying, hard-to-reason about situations. For example, consider this ActivityPub object, representing a new note that Sally published: One of the things I wasnt satisfied with in the first version of Pterotype was the way it stores incoming data. ActivityPub messages are serialized in a dialect of JSON called link[#:href "https://json-ld.org/"]{JSON-LD}. I didnt really get JSON-LD when I started this project. It seems overcomplicated and confusing, and I was more interested in shipping something that worked than understanding the theoretical underpinnings of the federated web. So I just kept the incoming data in JSON format. This worked, sort of, but I kept running into annoying, hard-to-reason about situations. For example, consider this ActivityPub object, representing a new note that Sally published:
codeblock[#:lang "json"]{ codeblock[#:lang "json"]{
{ {
"@context": "https://www.w3.org/ns/activitystreams", "@context": "https://www.w3.org/ns/activitystreams",
"id": "https://example.org/activities/1", "id": "https://example.org/activities/1",
"type": "Create", "type": "Create",
"actor": { "actor": {
"type": "Person", "type": "Person",
"id": "https://example.org/sally", "id": "https://example.org/sally",
"name": "Sally" "name": "Sally"
}, },
"object": { "object": {
"id": "https://example.org/notes/1", "id": "https://example.org/notes/1",
"type": "Note", "type": "Note",
"content": "This is a simple note" "content": "This is a simple note"
}, },
"published": "2015-01-25T12:34:56Z" "published": "2015-01-25T12:34:56Z"
} }
} }
The problem is that the above object, according to the ActivityPub specification, is semantically equivalent to this one: The problem is that the above object, according to the ActivityPub specification, is semantically equivalent to this one:
codeblock[#:lang "json"]{ codeblock[#:lang "json"]{
{ {
"@context": "https://www.w3.org/ns/activitystreams", "@context": "https://www.w3.org/ns/activitystreams",
"id": "https://example.org/activities/1", "id": "https://example.org/activities/1",
"type": "Create", "type": "Create",
"actor": "https://example.org/sally", "actor": "https://example.org/sally",
"object": "https://example.org/notes/1", "object": "https://example.org/notes/1",
"published": "2015-01-25T12:34:56Z" "published": "2015-01-25T12:34:56Z"
} }
} }
This is the object graph in action the code{actor} and code{object} properties are pointers to other objects, and as such they can either be JSON objects embedded within the code{Create} activity, or URIs that dereference to the actual object (dereferencing is a fancy word for following the URI and replacing it with whatever JSON object is on the other side). Since I was representing these ActivityPub objects in this JSON format, that meant that whenever I saw an code{actor} or code{object} property, I always had to check whether it was an object or a URI and if it was a URI I had to dereference it to the proper object. This led to tons of annoying boilerplate and conditionals: This is the object graph in action the code{actor} and code{object} properties are pointers to other objects, and as such they can either be JSON objects embedded within the code{Create} activity, or URIs that dereference to the actual object (dereferencing is a fancy word for following the URI and replacing it with whatever JSON object is on the other side). Since I was representing these ActivityPub objects in this JSON format, that meant that whenever I saw an code{actor} or code{object} property, I always had to check whether it was an object or a URI and if it was a URI I had to dereference it to the proper object. This led to tons of annoying boilerplate and conditionals:
@ -61,30 +61,30 @@ So whats the actual solution for this? Well, as it turns out these were exact
codeblock[#:lang "json"]{ codeblock[#:lang "json"]{
[ [
{ {
"https://www.w3.org/ns/activitystreams#actor": [ "https://www.w3.org/ns/activitystreams#actor": [
{ {
"@id": "https://example.org/sally" "@id": "https://example.org/sally"
} }
], ],
"@id": "https://example.org/activities/1", "@id": "https://example.org/activities/1",
"https://www.w3.org/ns/activitystreams#object": [ "https://www.w3.org/ns/activitystreams#object": [
{ {
"@id": "https://example.org/notes/1" "@id": "https://example.org/notes/1"
} }
], ],
"https://www.w3.org/ns/activitystreams#published": [ "https://www.w3.org/ns/activitystreams#published": [
{ {
"@type": "http://www.w3.org/2001/XMLSchema#dateTime", "@type": "http://www.w3.org/2001/XMLSchema#dateTime",
"@value": "2015-01-25T12:34:56Z" "@value": "2015-01-25T12:34:56Z"
} }
], ],
"@type": [ "@type": [
"https://www.w3.org/ns/activitystreams#Create" "https://www.w3.org/ns/activitystreams#Create"
] ]
} }
] ]
} }
So whats up with those weird URL-looking attributes? And why has everything become an array? So whats up with those weird URL-looking attributes? And why has everything become an array?