feat(author badges): add 5chan developer badges

This commit is contained in:
Tommaso Casaburi
2026-05-13 17:29:33 +07:00
parent c40353d2e6
commit 9f6c073264
8 changed files with 214 additions and 20 deletions
@@ -0,0 +1,55 @@
import { describe, expect, it } from 'vitest';
import { KNOWN_5CHAN_DEVELOPER_ENTRIES, getAuthorBadge, isKnown5chanDeveloper } from '../author-display-utils';
describe('author display utils', () => {
it('recognizes the hardcoded 5chan developer addresses', () => {
expect(isKnown5chanDeveloper('estebanabaroa.bso')).toBe(true);
expect(isKnown5chanDeveloper('rinse12.bso')).toBe(true);
expect(isKnown5chanDeveloper('plebeius.bso')).toBe(true);
expect(isKnown5chanDeveloper('someone-else.bso')).toBe(false);
});
it('keeps optional developer profile metadata next to the hardcoded address', () => {
expect(KNOWN_5CHAN_DEVELOPER_ENTRIES).toContainEqual({
address: 'rinse12.bso',
githubProfileUrl: 'https://github.com/rinse12',
name: 'Rinse',
});
expect(KNOWN_5CHAN_DEVELOPER_ENTRIES).toContainEqual({
address: 'plebeius.bso',
githubProfileUrl: 'https://github.com/tomcasaburi',
name: 'Tommaso Casaburi',
});
});
it('labels known developers with the admin icon style', () => {
expect(getAuthorBadge({ address: 'rinse12.bso' })).toEqual({
icon: 'admin',
label: '5chan Dev',
title: '5chan Dev',
});
});
it('keeps the developer label even when the account has a board role', () => {
expect(getAuthorBadge({ address: 'plebeius.bso', role: 'owner' })).toEqual({
icon: 'admin',
label: '5chan Dev',
title: '5chan Dev',
});
});
it('keeps board role labels for non-developers', () => {
expect(getAuthorBadge({ address: 'other.bso', role: 'moderator' })).toEqual({
capitalizeLabel: true,
icon: 'mod',
label: 'Board mod',
title: 'moderator_of_this_board',
});
expect(getAuthorBadge({ address: 'other.bso', role: 'owner' })).toEqual({
capitalizeLabel: true,
icon: 'admin',
label: 'Board owner',
title: 'administrator_of_this_board',
});
});
});
+51
View File
@@ -0,0 +1,51 @@
import known5chanDeveloperEntries from '../../data/known-5chan-developers.json';
interface Known5chanDeveloperEntry {
address: string;
githubProfileUrl?: string;
name?: string;
}
export const KNOWN_5CHAN_DEVELOPER_ENTRIES = known5chanDeveloperEntries as readonly Known5chanDeveloperEntry[];
export const KNOWN_5CHAN_DEVELOPER_ADDRESSES = KNOWN_5CHAN_DEVELOPER_ENTRIES.map(({ address }) => address);
type AuthorBadgeIcon = 'admin' | 'mod';
interface AuthorBadge {
capitalizeLabel?: boolean;
icon: AuthorBadgeIcon;
label: string;
title: '5chan Dev' | 'administrator_of_this_board' | 'moderator_of_this_board';
}
const normalizeBoardRole = (role?: string): string | undefined => {
const normalizedRole = role?.trim();
if (!normalizedRole) return undefined;
return normalizedRole.toLowerCase() === 'moderator' ? 'mod' : normalizedRole;
};
export const isKnown5chanDeveloper = (address?: string): boolean =>
typeof address === 'string' && KNOWN_5CHAN_DEVELOPER_ENTRIES.some((developer) => developer.address === address);
export const getAuthorBadge = ({ address, role }: { address?: string; role?: string }): AuthorBadge | undefined => {
const boardRole = normalizeBoardRole(role);
const isDeveloper = isKnown5chanDeveloper(address);
if (isDeveloper) {
return {
icon: 'admin',
label: '5chan Dev',
title: '5chan Dev',
};
}
if (!boardRole) return undefined;
const isMod = boardRole?.toLowerCase() === 'mod';
return {
capitalizeLabel: true,
icon: isMod ? 'mod' : 'admin',
label: `Board ${boardRole}`,
title: isMod ? 'moderator_of_this_board' : 'administrator_of_this_board',
};
};