diff --git a/.eleventy.js b/.eleventy.js index 2c7d9c3c4..459db1d81 100644 --- a/.eleventy.js +++ b/.eleventy.js @@ -7,6 +7,8 @@ const markdownItAnchor = require('markdown-it-anchor') const markdownItHighlightJS = require('markdown-it-highlightjs') const typogr = require('typogr') +const webmentions = require('./src/_data/webmentions') + const mdOptions = { html: true, breaks: true, @@ -65,6 +67,16 @@ module.exports = eleventyConfig => { eleventyConfig.addFilter('title_class', string => string.length > 30 ? ' is-long' : '') + eleventyConfig.addFilter('webmentionsPerPost', url => { + if (webmentions.children) { + return webmentions.children.filter(mention => { + return mention['wm-target'] && mention['wm-target'] === url + }) + } else { + return [] + } + }) + // eleventyConfig.addTransform('no_orphan', (content, outputPath) => { // if( outputPath.endsWith(".html") ) { // return typogr(content).chain().widont().value() diff --git a/src/_data/webmentions.js b/src/_data/webmentions.js new file mode 100644 index 000000000..5a7344af2 --- /dev/null +++ b/src/_data/webmentions.js @@ -0,0 +1,27 @@ +const https = require('https') + +const url = 'https://webmention.io/api/mentions.jf2?domain=indiewebcamp.com&token=aKs-nlB_-kQV8JGQ5RIw7Q' + +const getWebmentions = () => { + return new Promise((resolve, reject) => { + https.get( + url, + res => { + let data = '' + + res.on('data', d => { + data += d + }) + + res.on('end', () => { + resolve(JSON.parse(data)) + }) + } + ).on('error', error => { + console.error(error) + reject(error) + }) + }) +} + +module.exports = getWebmentions() diff --git a/src/_includes/partials/_head.liquid b/src/_includes/partials/_head.liquid index 35055fbe2..0f439b4ef 100644 --- a/src/_includes/partials/_head.liquid +++ b/src/_includes/partials/_head.liquid @@ -36,6 +36,9 @@ + + + diff --git a/src/_includes/partials/_webmentions.liquid b/src/_includes/partials/_webmentions.liquid new file mode 100644 index 000000000..a9820c747 --- /dev/null +++ b/src/_includes/partials/_webmentions.liquid @@ -0,0 +1,19 @@ +{% assign postUrl = page.url | abs_url: site.url %} +{% assign mentions = postUrl | webmentionsPerPost %} + +
No webmentions were found for this post.
+ {% endif %} +