From 2e135352d0b3662ef44336994465ec7d75d400f1 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 25 Jun 2023 18:20:53 +0900 Subject: feat(nuldoc): improve error handling when a tag is undefined --- nuldoc-src/config.ts | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'nuldoc-src/config.ts') diff --git a/nuldoc-src/config.ts b/nuldoc-src/config.ts index cbbabca..76a05fe 100644 --- a/nuldoc-src/config.ts +++ b/nuldoc-src/config.ts @@ -33,3 +33,10 @@ export const config = { }; export type Config = typeof config; + +export function getTagLabel(c: Config, slug: string): string { + if (!(slug in c.blog.tagLabels)) { + throw new Error(`Unknown tag: ${slug}`); + } + return (c.blog.tagLabels as { [slug: string]: string })[slug]; +} -- cgit v1.2.3-70-g09d2