move wm token to a parameter
This commit is contained in:
parent
886f610e1c
commit
47a905747d
15
README.md
15
README.md
|
@ -158,19 +158,26 @@ Working example: https://jefklakscodex.com/articles/reviews/diablo-3/ (on the le
|
||||||
|
|
||||||
### 5. Webmentions
|
### 5. Webmentions
|
||||||
|
|
||||||
In cooperation with https://github.com/wgroeneveld/serve-my-jams
|
In cooperation with https://github.com/wgroeneveld/go-jamming
|
||||||
|
|
||||||
#### 5.1 `getWebmentions`
|
#### 5.1 `getWebmentions`
|
||||||
|
|
||||||
Calls the get webmention endpoint, sorts by date, adds metadata such as relative date (`relativeTarget`, property), and returns data. Could be written in a `data` folder for Hugo to parse, for example.
|
Calls the get webmention endpoint, sorts by date, adds metadata such as relative date (`relativeTarget`, property), and returns data. Could be written in a `data` folder for Hugo to parse, for example.
|
||||||
|
|
||||||
Parameters: just one, the `domain`.
|
Parameters: first `domain`, second the config for the endpoint and token. Usage example:
|
||||||
|
|
||||||
|
```js
|
||||||
|
await getWebmentions("brainbaking.com", {
|
||||||
|
endpoint: 'https://jam.brainbaking.com',
|
||||||
|
token: 'lol'
|
||||||
|
})
|
||||||
|
````
|
||||||
|
|
||||||
#### 5.1 `send`
|
#### 5.1 `send`
|
||||||
|
|
||||||
Calls the set webmention endpoint using a `PUT`. Based on the RSS feed located at `/index.xml`, see the [go-jamming](github.com/wgroeneveld/go-jamming) README.
|
Calls the set webmention endpoint using a `PUT`. Based on the RSS feed, see the [go-jamming](github.com/wgroeneveld/go-jamming) README.
|
||||||
|
|
||||||
Parameters: just one, the `domain`.
|
Same as `getWebmentions`.
|
||||||
|
|
||||||
### 6. YouTube
|
### 6. YouTube
|
||||||
|
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
|
|
||||||
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,
|
|
||||||
serveMyJamToken
|
|
||||||
}
|
|
|
@ -1,13 +1,12 @@
|
||||||
|
|
||||||
const got = require('got')
|
const got = require('got')
|
||||||
const config = require('../config')
|
|
||||||
|
|
||||||
const dayjs = require('dayjs')
|
const dayjs = require('dayjs')
|
||||||
const relativeTime = require('dayjs/plugin/relativeTime')
|
const relativeTime = require('dayjs/plugin/relativeTime')
|
||||||
dayjs.extend(relativeTime)
|
dayjs.extend(relativeTime)
|
||||||
|
|
||||||
async function getWebmentions(domain) {
|
async function getWebmentions(domain, config) {
|
||||||
const url = `${config.serveMyJamEndpoint}/webmention/${domain}/${config.serveMyJamToken}`
|
const url = `${config.endpoint}/webmention/${domain}/${config.token}`
|
||||||
const result = await got(url)
|
const result = await got(url)
|
||||||
|
|
||||||
if(!result.body || !result.body) {
|
if(!result.body || !result.body) {
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
|
|
||||||
const got = require('got')
|
const got = require('got')
|
||||||
const config = require('../config')
|
|
||||||
const fsp = require('fs').promises
|
const fsp = require('fs').promises
|
||||||
|
|
||||||
const dayjs = require('dayjs')
|
const dayjs = require('dayjs')
|
||||||
|
|
||||||
async function sendWebmentions(domain) {
|
async function sendWebmentions(domain, config) {
|
||||||
const url = `${config.serveMyJamEndpoint}/webmention/${domain}/${config.serveMyJamToken}`
|
const url = `${config.endpoint}/webmention/${domain}/${config.token}`
|
||||||
|
|
||||||
// this is an async call and will return 202 to say "started sending them out".
|
// this is an async call and will return 202 to say "started sending them out".
|
||||||
const result = await got.put(url)
|
const result = await got.put(url)
|
||||||
|
|
|
@ -7,9 +7,13 @@ const domain = "brainbaking.com"
|
||||||
|
|
||||||
describe("webmention receive scenario test", () => {
|
describe("webmention receive scenario test", () => {
|
||||||
|
|
||||||
|
// this tests against the real endpoint, meaning the token has to be correct.
|
||||||
test("getWebmentions fetches anything at all", async () => {
|
test("getWebmentions fetches anything at all", async () => {
|
||||||
const result = await getWebmentions(domain)
|
const result = await getWebmentions(domain, {
|
||||||
expect(result.length).toBeGreaterThan(-1)
|
token: 'miauwkes',
|
||||||
|
endpoint: 'https://jam.brainbaking.com'
|
||||||
|
})
|
||||||
|
//expect(result.length).toBeGreaterThan(-1)
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
|
@ -9,12 +9,18 @@ describe("webmention receive serve-my-jam tests", () => {
|
||||||
MockDate.set(dayjs('2021-03-11T19:00:00').toDate())
|
MockDate.set(dayjs('2021-03-11T19:00:00').toDate())
|
||||||
|
|
||||||
test("getWebmentions fetches from serve-my-jam depending on config", async () => {
|
test("getWebmentions fetches from serve-my-jam depending on config", async () => {
|
||||||
const result = await getWebmentions(domain)
|
const result = await getWebmentions(domain, {
|
||||||
|
token: 'miauwkes',
|
||||||
|
endpoint: 'https://jam.brainbaking.com'
|
||||||
|
})
|
||||||
expect(result.length).toBe(4)
|
expect(result.length).toBe(4)
|
||||||
})
|
})
|
||||||
|
|
||||||
test("getWebmentions enriches data with relatiave url", async () => {
|
test("getWebmentions enriches data with relatiave url", async () => {
|
||||||
const result = await getWebmentions(domain)
|
const result = await getWebmentions(domain, {
|
||||||
|
token: 'miauwkes',
|
||||||
|
endpoint: 'https://jam.brainbaking.com/'
|
||||||
|
})
|
||||||
const mention = result[0]
|
const mention = result[0]
|
||||||
|
|
||||||
expect(mention.relativeTarget).toEqual("/post/2021/02/my-retro-desktop-setup/")
|
expect(mention.relativeTarget).toEqual("/post/2021/02/my-retro-desktop-setup/")
|
||||||
|
@ -22,7 +28,10 @@ describe("webmention receive serve-my-jam tests", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
test("getWebmentions are sorted by published date descending", async() => {
|
test("getWebmentions are sorted by published date descending", async() => {
|
||||||
const result = await getWebmentions(domain)
|
const result = await getWebmentions(domain, {
|
||||||
|
token: 'miauwkes',
|
||||||
|
endpoint: 'https://jam.brainbaking.com'
|
||||||
|
})
|
||||||
|
|
||||||
expect(result[0].published).toEqual("2021-03-08T18:35:24")
|
expect(result[0].published).toEqual("2021-03-08T18:35:24")
|
||||||
expect(result[1].published).toEqual("2021-03-08T17:14:25")
|
expect(result[1].published).toEqual("2021-03-08T17:14:25")
|
||||||
|
|
|
@ -14,8 +14,11 @@ describe("webmention send serve-my-jam tests", () => {
|
||||||
|
|
||||||
|
|
||||||
test("sendWebmentions", async() => {
|
test("sendWebmentions", async() => {
|
||||||
await sendWebmentions('brainbaking.com')
|
await sendWebmentions('brainbaking.com', {
|
||||||
expect(calledPut).toBe("https://jam.brainbaking.com/webmention/brainbaking.com/miauwkes")
|
token: 'lol',
|
||||||
|
endpoint: 'https://jam.brainbaking.com'
|
||||||
|
})
|
||||||
|
expect(calledPut).toBe("https://jam.brainbaking.com/webmention/brainbaking.com/lol")
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue