Skip to content

Commit

Permalink
Add support for reads
Browse files Browse the repository at this point in the history
To allow tracking of books that are being read by folks, we can
introduce the `read` post type.

This also includes sample data for three common types of reads:

- an `h-cite` from data from books-mf2.herokuapp.com
- a URL cite to books-mf2.herokuapp.com
- an `h-cite` from https://indiebookclub.biz

To allow for better visualisation in editors, we can also hint which
expected properties are available, and required.
  • Loading branch information
jamietanna committed Nov 16, 2021
1 parent 719ef68 commit 4c0e8ce
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 2 deletions.
86 changes: 86 additions & 0 deletions scripts/posts.json
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,92 @@
"note"
]
}
},
{
"url": "2021/11/ghatp",
"type": [
"h-entry"
],
"properties": {
"entry-type": [
"read"
],
"published": [
"2021-11-13T07:51:00+0000"
],
"read-status": [
"finished"
],
"read-of": [
{
"type": [
"h-cite"
],
"properties": {
"url": [
"https://openlibrary.org/books/OL26318312M"
],
"uid": [
"isbn:9780316217651"
],
"name": [
"Gods of risk"
],
"author": [
"James S. A. Corey"
],
"photo": {
"value": "https://covers.openlibrary.org/b/id/7992542.jpg",
"alt": "Cover picture of Gods of risk"
}
}
}
]
}
},
{
"url": "2021/11/ghatp-url",
"type": [
"h-entry"
],
"properties": {
"entry-type": [
"read"
],
"published": [
"2021-11-13T07:51:00+0000"
],
"read-status": [
"finished"
],
"read-of": [
"https://books-mf2.herokuapp.com/isbn/9780316332897"
]
}
},
{
"url": "2021/11/99ib8",
"type": [
"h-entry"
],
"properties" : {
"entry-type": [
"read"
],
"summary" : [ "Finished reading: Cibola Burn by James S. A. Corey, ISBN: 9780316217620" ],
"read-status" : [ "finished" ],
"read-of" : [
{
"type" : [ "h-cite" ],
"properties" : {
"name" : [ "Cibola Burn" ],
"author" : [ "James S. A. Corey" ],
"uid" : [ "isbn:9780316217620" ]
}
}
],
"published" : [ "2020-10-09T23:08:24.411Z" ]
}
}
]
}
13 changes: 13 additions & 0 deletions src/http/get-micropub/config/post-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,18 @@ module.exports = [
{
type: 'listen',
name: 'Listen'
},
{
type: 'read',
name: 'Read',
properties: [
'content',
'read-of',
'read-status'
],
'required-properties': [
'read-of',
'read-status'
]
}
]
2 changes: 1 addition & 1 deletion src/http/get-micropub/contexts.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { isValidURL } = require('@architect/shared/utils')

async function setContexts (post) {
const data = await arc.tables()
const urlProps = ['in-reply-to', 'repost-of', 'like-of', 'bookmark-of', 'listen-of']
const urlProps = ['in-reply-to', 'repost-of', 'like-of', 'bookmark-of', 'listen-of', 'read-of']

for (const prop of urlProps) {
if ((prop in post.properties) && Array.isArray(post.properties[prop])) {
Expand Down
6 changes: 5 additions & 1 deletion src/shared/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const reservedUrls = `
bookmarks
photos
checkins
reads
reposts
likes
replies
Expand Down Expand Up @@ -51,6 +52,9 @@ function derivePostType (post) {
} else if (('listen-of' in post.properties) &&
isValidURL(post.properties['listen-of'][0])) {
return 'listen'
} else if (('read-of' in post.properties) && post.properties['read-status'] &&
['to-read', 'reading', 'finished'].includes(post.properties['read-status'][0])) {
return 'read'
} else {
return 'note'
}
Expand All @@ -67,7 +71,7 @@ function isValidURL (string) {

function findContexts (post) {
const urls = []
for (const prop of ['in-reply-to', 'repost-of', 'like-of', 'bookmark-of', 'listen-of']) {
for (const prop of ['in-reply-to', 'repost-of', 'like-of', 'bookmark-of', 'listen-of', 'read-of']) {
if ((prop in post.properties) && Array.isArray(post.properties[prop])) {
for (const i in post.properties[prop]) {
const url = post.properties[prop][i]
Expand Down

0 comments on commit 4c0e8ce

Please sign in to comment.