Skip to content

Commit

Permalink
0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisburnell committed Dec 5, 2021
1 parent e349ec9 commit 4d6e44d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
30 changes: 17 additions & 13 deletions eleventy-cache-webmentions.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,22 @@ module.exports = (config, options = {}) => {
if (!asset.isCacheValid(options.duration)) {
const since = asset._cache.getKey(options.key) ? asset._cache.getKey(options.key).cachedAt : false
const url = `https://webmention.io/api/mentions.jf2?domain=${hostname(options.domain)}&token=${TOKEN}&per-page=9001${since ? `&since=${since}` : ``}`
const response = await fetch(url)
if (response.ok) {
const feed = await response.json()
if (feed.children.length) {
console.log(`[${hostname(options.domain)}] ${feed.children.length} new Webmentions fetched into cache.`)
}
webmentions.children = [...feed.children, ...webmentions.children].sort((a, b) => {
return epoch(b.published || b["wm-received"]) - epoch(a.published || a["wm-received"])
await fetch(url)
.then(async (response) => {
if (response.ok) {
const feed = await response.json()
if (feed.children.length) {
console.log(`[${hostname(options.domain)}] ${feed.children.length} new Webmentions fetched into cache.`)
}
webmentions.children = [...feed.children, ...webmentions.children]
await asset.save(webmentions, "json")
return webmentions
}
return Promise.reject(response)
})
.catch((error) => {
console.log("Something went wrong with your request to webmention.io!", error)
})
await asset.save(webmentions, "json")
return webmentions
}
}

return webmentions
Expand Down Expand Up @@ -131,7 +135,7 @@ module.exports = (config, options = {}) => {
}

const results = webmentions[url]
// filter webmentions by allowedTypes only if passed
// filter webmentions by allowed response post types
.filter((entry) => {
return Array.isArray(allowedTypes) ? allowedTypes.includes(entry["wm-property"]) : true
})
Expand Down Expand Up @@ -178,6 +182,6 @@ module.exports = (config, options = {}) => {
config.addLiquidFilter("getWebmentions", getWebmentionsFilter)
config.addNunjucksAsyncFilter("getWebmentions", getWebmentionsFilter)
} else {
return filteredWebmentions()
return filteredWebmentions
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@chrisburnell/eleventy-cache-webmentions",
"version": "0.1.0",
"version": "0.1.1",
"description": "Cache webmentions from webmention.io using eleventy-cache-assets.",
"main": "eleventy-cache-webmentions.js",
"author": "Chris Burnell <me@chrisburnell.com>",
Expand Down

0 comments on commit 4d6e44d

Please sign in to comment.