Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions libs/badge-list2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@
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,

Check warning on line 69 in libs/badge-list2.ts

View workflow job for this annotation

GitHub Actions / build

Assign object to a variable before exporting as module default
github: github.meta,
gitlab: gitlab.meta,
https: https.meta,
Expand Down Expand Up @@ -130,4 +131,5 @@
keybase: keybase.meta,
mastodon: mastodon.meta,
tidelift: tidelift.meta,
email: email.meta,
}
1 change: 1 addition & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ const nextConfig = {
'/liberapay',
'/opencollective',
'/tidelift',
'/email',
// discontinued
'/apm',
'/lgtm',
Expand Down
20 changes: 20 additions & 0 deletions pages/api/email.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { createBadgenHandler, PathArgs } from '../../libs/create-badgen-handler-next'

export default createBadgenHandler({
title: 'Email',
examples: {
'/email/consulting/tunnckocore.com': 'email',
'/email/foobar/mydomain.co.uk': 'email',
},
handlers: {
'/email/:name/:domain': handler
}
})

async function handler ({ name, domain }: PathArgs) {
return {
subject: 'email',
status: `${name}@${domain}`,
color: 'blue'
}
}
24 changes: 24 additions & 0 deletions test/email.test.mjs
Original file line number Diff line number Diff line change
@@ -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/consulting/tunnckocore.com`
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 in domain', async (t) => {
const badgeURL = `${BASE_URL}/email/foobar/mydomain.co.uk`
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'))
})
Loading