jam-my-stack/src/webmention/get.js

28 lines
722 B
JavaScript
Raw Normal View History

2021-03-09 21:24:22 +01:00
const got = require('got')
const config = require('../config')
const dayjs = require('dayjs')
const relativeTime = require('dayjs/plugin/relativeTime')
dayjs.extend(relativeTime)
async function getWebmentions(domain) {
const url = `${config.serveMyJamEndpoint}/webmention/${domain}/${config.serveMyJamToken}`
2021-03-09 21:24:22 +01:00
const result = await got(url)
2021-03-12 19:03:56 +01:00
if(!result.body || !result.body) {
return []
}
const json = JSON.parse(result.body).json
json.forEach(mention => {
mention.relativeTarget = mention.target.substring(mention.target.indexOf(domain) + domain.length, mention.target.length)
2021-03-09 21:24:22 +01:00
})
2021-03-12 19:03:56 +01:00
return json.sort((a, b) => dayjs(b.published).toDate() - dayjs(a.published).toDate())
2021-03-09 21:24:22 +01:00
}
module.exports = {
getWebmentions
}