add serve-my-jams getwebmention part
parent
e740476232
commit
0ff54d8a7b
|
@ -44,6 +44,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
|
|||
["howlongtobeat", "npm:1.3.1"],
|
||||
["jest", "npm:26.6.3"],
|
||||
["lunr", "npm:2.3.9"],
|
||||
["mockdate", "npm:3.0.2"],
|
||||
["parser-front-matter", "npm:1.6.4"]
|
||||
],
|
||||
"linkType": "SOFT",
|
||||
|
@ -3534,6 +3535,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
|
|||
["howlongtobeat", "npm:1.3.1"],
|
||||
["jest", "npm:26.6.3"],
|
||||
["lunr", "npm:2.3.9"],
|
||||
["mockdate", "npm:3.0.2"],
|
||||
["parser-front-matter", "npm:1.6.4"]
|
||||
],
|
||||
"linkType": "SOFT",
|
||||
|
@ -4516,6 +4518,15 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
|
|||
"linkType": "HARD",
|
||||
}]
|
||||
]],
|
||||
["mockdate", [
|
||||
["npm:3.0.2", {
|
||||
"packageLocation": "./.yarn/cache/mockdate-npm-3.0.2-14482dcf0f-27a242abaa.zip/node_modules/mockdate/",
|
||||
"packageDependencies": [
|
||||
["mockdate", "npm:3.0.2"]
|
||||
],
|
||||
"linkType": "HARD",
|
||||
}]
|
||||
]],
|
||||
["ms", [
|
||||
["npm:2.0.0", {
|
||||
"packageLocation": "./.yarn/cache/ms-npm-2.0.0-9e1101a471-1a230340cc.zip/node_modules/ms/",
|
||||
|
|
|
@ -142,3 +142,11 @@ Usage example:
|
|||
It will print out games and metadata it found. Uses the cool [howlongtobeat npm package](https://www.npmjs.com/package/howlongtobeat) to do its dirty work.
|
||||
|
||||
Working example: https://jefklakscodex.com/articles/reviews/diablo-3/ (on the left side). Check out the Hugo template to use the properties at https://github.com/wgroeneveld/jefklakscodex .
|
||||
|
||||
### 5. Webmentions
|
||||
|
||||
In cooperation with https://github.com/wgroeneveld/serve-my-jams
|
||||
|
||||
#### 5.1 `getWebmentions`
|
||||
|
||||
Calls the get webmention endpoint, sorts by date, adds metadata such as relative date (`x days ago`, property `publishedFromNow`), and returns data. Could be written in a `data` folder for Hugo to parse, for example.
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
"parser-front-matter": "^1.6.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"jest": "^26.6.3"
|
||||
"jest": "^26.6.3",
|
||||
"mockdate": "^3.0.2"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
|
||||
const serveMyJamDomain = "brainbaking.com"
|
||||
const serveMyJamToken = "miauwkes"
|
||||
|
||||
const serveMyJamEndpoint = "https://jam.brainbaking.com"
|
||||
|
||||
// see https://github.com/wgroeneveld/serve-my-jams
|
||||
// don't care if token is visible, just an extra security-by-obscurity step, everything is public anyway
|
||||
module.exports = {
|
||||
serveMyJamEndpoint,
|
||||
|
||||
serveMyJamDomain,
|
||||
serveMyJamToken
|
||||
}
|
|
@ -2,6 +2,7 @@ const { parseMastoFeed } = require('./mastodon/feed-parser')
|
|||
const { widgetify } = require('./goodreads/widgetify.js')
|
||||
const { buildIndex } = require('./lunr/index-builder.js')
|
||||
const { howlong } = require('./howlongtobeat/howlong.js')
|
||||
const { getWebmentions } = require('./webmention/get.js')
|
||||
|
||||
module.exports = {
|
||||
mastodon: {
|
||||
|
@ -15,5 +16,8 @@ module.exports = {
|
|||
},
|
||||
howlongtobeat: {
|
||||
howlong: howlong
|
||||
},
|
||||
webmention: {
|
||||
getWebmentions: getWebmentions
|
||||
}
|
||||
};
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
|
||||
const got = require('got')
|
||||
const config = require('../config')
|
||||
|
||||
const dayjs = require('dayjs')
|
||||
const relativeTime = require('dayjs/plugin/relativeTime')
|
||||
dayjs.extend(relativeTime)
|
||||
|
||||
async function getWebmentions() {
|
||||
const url = `${config.serveMyJamEndpoint}/webmention/${config.serveMyJamDomain}/${config.serveMyJamToken}`
|
||||
const result = await got(url)
|
||||
|
||||
result.body.json.forEach(mention => {
|
||||
mention.publishedFromNow = dayjs(mention.published).fromNow()
|
||||
})
|
||||
|
||||
return result.body.json.sort((a, b) => dayjs(b.published).toDate() - dayjs(a.published).toDate())
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getWebmentions
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
{"status":"success","json":[{"author":{"name":"Stampeding Longhorn"},"content":"undefined...","published":"2021-03-08T18:35:24","source":"https://brid.gy/like/mastodon/@wouter@chat.brainbaking.com/A4nx1rFwKUJYSe4TqK/A4nwg4LYyh4WgrJOXg","target":"https://brainbaking.com/post/2021/02/my-retro-desktop-setup/"},{"author":{"name":"Wouter Groeneveld"},"content":"@StampedingLonghorn I tried to chase him away, but you know how that turned out... 😼 There's even cat hair inside the cases... (to be clear: also unintentional)...","published":"2021-03-02T16:18:46.000Z","source":"https://brid.gy/comment/mastodon/@wouter@chat.brainbaking.com/A4nx1rFwKUJYSe4TqK/A4nxVFgAbVtebcM9gW","target":"https://brainbaking.com/post/2021/02/my-retro-desktop-setup/"},{"author":{"name":"https://jefklakscodex.com/about"},"content":"About the Codex | Jefklaks Codex","published":"2021-03-08T17:14:25","source":"https://jefklakscodex.com/about","target":"https://brainbaking.com/about/"},{"author":{"name":"Stampeding Longhorn"},"content":"@wouter The cat pictures are awesome....","published":"2021-03-02T16:17:18.000Z","source":"https://brid.gy/comment/mastodon/@wouter@chat.brainbaking.com/A4nx1rFwKUJYSe4TqK/A4nxN8ytch0BW2FVXU","target":"https://brainbaking.com/post/2021/02/my-retro-desktop-setup/"}]}
|
|
@ -1,7 +1,16 @@
|
|||
const fs = require('fs').promises
|
||||
|
||||
async function got() {
|
||||
return fs.readFile('./test/__mocks__/masto-feed-sample.xml', 'utf8');
|
||||
async function got(url) {
|
||||
console.log(`through got mock, url ${url}`)
|
||||
if(url.indexOf('/webmention') >= 0) {
|
||||
const result = await fs.readFile(`./test/__mocks__/get-sample.json`, 'utf8');
|
||||
return {
|
||||
body: JSON.parse(result)
|
||||
}
|
||||
}
|
||||
|
||||
const result = await fs.readFile(`./test/__mocks__/masto-feed-sample.xml`, 'utf8');
|
||||
return result
|
||||
}
|
||||
|
||||
module.exports = got
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
const fs = require('fs')
|
||||
|
||||
const fakedata = fs.readFileSync('./test/__mocks__/expected-goodreads-content.js')
|
||||
const fakedata = fs.readFileSync('./test/goodreads/__mocks__/expected-goodreads-content.js')
|
||||
|
||||
function getmock(url, callback) {
|
||||
callback({
|
|
@ -1,15 +1,16 @@
|
|||
const fs = require('fs');
|
||||
const fsp = require('fs').promises;
|
||||
const { rmdir } = require('./../utils')
|
||||
|
||||
const frontMatterParser = require('parser-front-matter');
|
||||
|
||||
jest.mock('got');
|
||||
|
||||
const { parseMastoFeed } = require('../../src/mastodon/feed-parser')
|
||||
const dumpdir = `${__dirname}/dump`
|
||||
|
||||
describe("mastodon feed parser tests", () => {
|
||||
const fs = require('fs');
|
||||
const fsp = require('fs').promises;
|
||||
const { rmdir } = require('./../utils')
|
||||
|
||||
const frontMatterParser = require('parser-front-matter');
|
||||
|
||||
jest.mock('got');
|
||||
|
||||
const { parseMastoFeed } = require('../../src/mastodon/feed-parser')
|
||||
const dumpdir = `${__dirname}/dump`
|
||||
|
||||
beforeEach(() => {
|
||||
if(fs.existsSync(dumpdir)) {
|
||||
rmdir(dumpdir)
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
|
||||
jest.mock('got');
|
||||
const gotmock = require("got");
|
||||
|
||||
test("got is mocked", async () => {
|
||||
const data = await gotmock("bla");
|
||||
expect(data).toMatch(/brainbaking/)
|
||||
})
|
|
@ -0,0 +1,31 @@
|
|||
|
||||
const MockDate = require('mockdate')
|
||||
const dayjs = require('dayjs')
|
||||
|
||||
describe("webmention receive serve-my-jam tests", () => {
|
||||
|
||||
const { getWebmentions } = require('./../../src/webmention/get')
|
||||
MockDate.set(dayjs('2021-03-11T19:00:00').toDate())
|
||||
|
||||
test("getWebmentions fetches from serve-my-jam depending on config", async () => {
|
||||
const result = await getWebmentions()
|
||||
expect(result.length).toBe(4)
|
||||
})
|
||||
|
||||
test("getWebmentions enriches data with fromNow data", async () => {
|
||||
const result = await getWebmentions()
|
||||
const mention = result[0]
|
||||
|
||||
expect(mention.published).toEqual("2021-03-08T18:35:24")
|
||||
expect(mention.publishedFromNow).toEqual("3 days ago")
|
||||
})
|
||||
|
||||
test("getWebmentions are sorted by published date descending", async() => {
|
||||
const result = await getWebmentions()
|
||||
|
||||
expect(result[0].published).toEqual("2021-03-08T18:35:24")
|
||||
expect(result[1].published).toEqual("2021-03-08T17:14:25")
|
||||
expect(result[2].published).toEqual("2021-03-02T16:18:46.000Z")
|
||||
})
|
||||
|
||||
})
|
|
@ -2954,6 +2954,7 @@ fsevents@^2.1.2:
|
|||
howlongtobeat: ^1.3.1
|
||||
jest: ^26.6.3
|
||||
lunr: ^2.3.9
|
||||
mockdate: ^3.0.2
|
||||
parser-front-matter: ^1.6.4
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
@ -3834,6 +3835,13 @@ fsevents@^2.1.2:
|
|||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"mockdate@npm:^3.0.2":
|
||||
version: 3.0.2
|
||||
resolution: "mockdate@npm:3.0.2"
|
||||
checksum: 27a242abaa48f170f6174988b3cd597806715c11d8dc644efa466ca4f1b899e66e6d0618808df60f8a7807c89e6e316b832138f2028039d1caf23341e3d01f90
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"ms@npm:2.0.0":
|
||||
version: 2.0.0
|
||||
resolution: "ms@npm:2.0.0"
|
||||
|
|
Loading…
Reference in New Issue