From d068697b69b6ef303add084bf7538553c2040d3d Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 6 May 2026 07:08:58 +0000 Subject: [PATCH 1/3] feat: add email badge endpoint - Add `pages/api/email.ts` to handle `/email/:tld/:name/:domain` - Register `/email` endpoint in `next.config.js` - Add E2E tests for the new email endpoint This implements the proposal from https://github.com/badgen/badgen.net/issues/293#issuecomment-506623856 Co-authored-by: amio <215282+amio@users.noreply.github.com> --- next.config.js | 1 + pages/api/email.ts | 20 ++++++++++++++++++++ test/email.test.mjs | 24 ++++++++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 pages/api/email.ts create mode 100644 test/email.test.mjs diff --git a/next.config.js b/next.config.js index 2829c429..02b38458 100644 --- a/next.config.js +++ b/next.config.js @@ -94,6 +94,7 @@ const nextConfig = { '/liberapay', '/opencollective', '/tidelift', + '/email', // discontinued '/apm', '/lgtm', diff --git a/pages/api/email.ts b/pages/api/email.ts new file mode 100644 index 00000000..a667b161 --- /dev/null +++ b/pages/api/email.ts @@ -0,0 +1,20 @@ +import { createBadgenHandler, PathArgs } from '../../libs/create-badgen-handler-next' + +export default createBadgenHandler({ + title: 'Email', + examples: { + '/email/com/consulting/tunnckocore': 'email', + '/email/co.uk/foobar/mydomain': 'email', + }, + handlers: { + '/email/:tld/:name/:domain': handler + } +}) + +async function handler ({ tld, name, domain }: PathArgs) { + return { + subject: 'email', + status: `${name}@${domain}.${tld}`, + color: 'blue' + } +} diff --git a/test/email.test.mjs b/test/email.test.mjs new file mode 100644 index 00000000..df293177 --- /dev/null +++ b/test/email.test.mjs @@ -0,0 +1,24 @@ +import test from 'node:test' +import assert from 'node:assert/strict' + +const BASE_URL = process.env.BASE_URL || 'http://localhost:3000' + +test('/email: simple email badge', async (t) => { + const badgeURL = `${BASE_URL}/email/com/consulting/tunnckocore` + const response = await fetch(badgeURL) + + assert.strictEqual(response.status, 200) + assert.strictEqual(response.headers.get('content-type'), 'image/svg+xml;charset=utf-8') + const body = await response.text() + assert.ok(body.includes('consulting@tunnckocore.com')) +}) + +test('/email: email badge with TLD and domain', async (t) => { + const badgeURL = `${BASE_URL}/email/co.uk/foobar/mydomain` + const response = await fetch(badgeURL) + + assert.strictEqual(response.status, 200) + assert.strictEqual(response.headers.get('content-type'), 'image/svg+xml;charset=utf-8') + const body = await response.text() + assert.ok(body.includes('foobar@mydomain.co.uk')) +}) From 38795155bd9c2d66f1dadd3e210936e09857139e Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 6 May 2026 07:22:09 +0000 Subject: [PATCH 2/3] feat: add email badge endpoint with /email/:name/:domain schema - Add `pages/api/email.ts` to handle `/email/:name/:domain` - Register `/email` endpoint in `next.config.js` - Add E2E tests for the new email endpoint in `test/email.test.mjs` This implements the email badge as requested, allowing users to provide the mailbox name and domain separately. Co-authored-by: amio <215282+amio@users.noreply.github.com> --- pages/api/email.ts | 10 +++++----- test/email.test.mjs | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pages/api/email.ts b/pages/api/email.ts index a667b161..c419bbb8 100644 --- a/pages/api/email.ts +++ b/pages/api/email.ts @@ -3,18 +3,18 @@ import { createBadgenHandler, PathArgs } from '../../libs/create-badgen-handler- export default createBadgenHandler({ title: 'Email', examples: { - '/email/com/consulting/tunnckocore': 'email', - '/email/co.uk/foobar/mydomain': 'email', + '/email/consulting/tunnckocore.com': 'email', + '/email/foobar/mydomain.co.uk': 'email', }, handlers: { - '/email/:tld/:name/:domain': handler + '/email/:name/:domain': handler } }) -async function handler ({ tld, name, domain }: PathArgs) { +async function handler ({ name, domain }: PathArgs) { return { subject: 'email', - status: `${name}@${domain}.${tld}`, + status: `${name}@${domain}`, color: 'blue' } } diff --git a/test/email.test.mjs b/test/email.test.mjs index df293177..47bae9e5 100644 --- a/test/email.test.mjs +++ b/test/email.test.mjs @@ -4,7 +4,7 @@ import assert from 'node:assert/strict' const BASE_URL = process.env.BASE_URL || 'http://localhost:3000' test('/email: simple email badge', async (t) => { - const badgeURL = `${BASE_URL}/email/com/consulting/tunnckocore` + const badgeURL = `${BASE_URL}/email/consulting/tunnckocore.com` const response = await fetch(badgeURL) assert.strictEqual(response.status, 200) @@ -13,8 +13,8 @@ test('/email: simple email badge', async (t) => { assert.ok(body.includes('consulting@tunnckocore.com')) }) -test('/email: email badge with TLD and domain', async (t) => { - const badgeURL = `${BASE_URL}/email/co.uk/foobar/mydomain` +test('/email: email badge with TLD in domain', async (t) => { + const badgeURL = `${BASE_URL}/email/foobar/mydomain.co.uk` const response = await fetch(badgeURL) assert.strictEqual(response.status, 200) From 4aa7191f9e45810e6165fb8ff331fea279abb280 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 6 May 2026 07:26:20 +0000 Subject: [PATCH 3/3] feat: add email badge and update badge list - Add email badge endpoint with /email/:name/:domain schema - Register /email endpoint in next.config.js - Update libs/badge-list2.ts with email badge metadata - Add E2E tests for email badge Co-authored-by: amio <215282+amio@users.noreply.github.com> --- libs/badge-list2.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/badge-list2.ts b/libs/badge-list2.ts index 74653c73..77d2e9e1 100644 --- a/libs/badge-list2.ts +++ b/libs/badge-list2.ts @@ -63,6 +63,7 @@ import opencollective from '../pages/api/opencollective' import keybase from '../pages/api/keybase' import mastodon from '../pages/api/mastodon' import tidelift from '../pages/api/tidelift' +import email from '../pages/api/email' export default { static: staticBadge.meta, @@ -130,4 +131,5 @@ export default { keybase: keybase.meta, mastodon: mastodon.meta, tidelift: tidelift.meta, + email: email.meta, }