--- date: '2023-03-17' title: 'Webmentions in Eleventy' description: "In the interest of continuing to repeat myself I'm writing, once again, about adding webmentions to a blog." draft: false tags: ['webmentions', 'Eleventy', 'API'] --- In the interest of continuing to repeat myself I'm writing, once again, about adding webmentions to a blog.[^1] To quote myself[^2]: > To kick this off you'll need to log in and establish an account with [webmention.io](https://webmention.io) and [Bridgy](https://brid.gy). The former provides you with a pair of meta tags that collect webmentions, the latter connects your site to social media > Once you've added the appropriate tags from webmention.io, connected your desired accounts to Bridgy and received some mentions on these sites, you should be able to access said mentions via their API. I'm fetching data from [webmention.io](https://webmention.io) at build time in `/src/_data/webmentions.js`: ```javascript const EleventyFetch = require('@11ty/eleventy-fetch') module.exports = async function () { const KEY_CORYD = process.env.API_KEY_WEBMENTIONS_CORYD_DEV const url = `https://webmention.io/api/mentions.jf2?token=${KEY_CORYD}&per-page=1000` const res = EleventyFetch(url, { duration: '1h', type: 'json', }) const webmentions = await res return { mentions: webmentions.children, } } ``` I have cache duration set to `1h` and a scheduled build operating on approximately the same schedule that's handled by a [GitHub action](https://github.com/actions) leveraging [Vercel's CLI](https://vercel.com/docs/cli): ```yaml name: Scheduled Vercel build env: VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} on: schedule: - cron: '0 * * * *' jobs: cron: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Install Vercel CLI run: npm install --global vercel@latest - name: Pull Vercel Environment Information run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }} - name: Build Project Artifacts run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }} - name: Deploy Project Artifacts to Vercel run: vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }} ``` When the build runs, it renders any mentions of a given post via a [liquid.js](https://liquidjs.com/) template that looks like this: {% raw %} ```liquid {% if webmentions %}