27 lines
674 B
JavaScript
27 lines
674 B
JavaScript
|
|
const got = require('got')
|
|
|
|
const dayjs = require('dayjs')
|
|
const relativeTime = require('dayjs/plugin/relativeTime')
|
|
dayjs.extend(relativeTime)
|
|
|
|
async function getWebmentions(domain, config) {
|
|
const url = `${config.endpoint}/webmention/${domain}/${config.token}`
|
|
const result = await got(url)
|
|
|
|
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)
|
|
})
|
|
|
|
return json.sort((a, b) => dayjs(b.published).toDate() - dayjs(a.published).toDate())
|
|
}
|
|
|
|
module.exports = {
|
|
getWebmentions
|
|
}
|