PronounsPage/server/api/pronouns-name/[...pronoun].get.ts
Valentyne Stigloher 10180aa6a3 (refactor) use #shared alias instead of ~~/shared
the #shared alias used by Nuxt cannot be easily disabled and to prevent breackage with jiti, we make use of it
2025-08-17 18:56:02 +02:00

22 lines
849 B
TypeScript

import { buildPronounUsage } from '#shared/buildPronoun.ts';
import { getLocale, loadConfig, loadPronounLibrary, loadTranslator } from '~~/server/data.ts';
export default defineEventHandler(async (event) => {
const locale = getLocale(event);
const [config, translator, pronounLibrary] =
await Promise.all([loadConfig(locale), loadTranslator(locale), loadPronounLibrary(locale)]);
checkIsConfigEnabledOr404(config, 'pronouns');
const path = getRouterParam(event, 'pronoun')!.split('/')
.map((p) => decodeURIComponent(p))
.join('/');
const usage = buildPronounUsage(pronounLibrary, path, config, translator);
if (usage === null) {
throw createError({
status: 404,
statusMessage: 'Not Found',
});
}
return usage.short.options.join(usage.short.glue);
});