Add static checking to i18n and improve types
This commit is contained in:
parent
f8ac450ab5
commit
579e5879e1
16 changed files with 126 additions and 82 deletions
|
|
@ -25,7 +25,12 @@ const { pageTitle } = Astro.props;
|
|||
<meta name="generator" content={Astro.generator} />
|
||||
<title>{pageTitle || "Gallery"} | Bad Manners</title>
|
||||
<link rel="me" href="https://meow.social/@BadManners" />
|
||||
<link rel="alternate" type="application/rss+xml" title="Gallery | Bad Manners" href={`${Astro.site}feed.xml`} />
|
||||
<link
|
||||
rel="alternate"
|
||||
type="application/rss+xml"
|
||||
title="Gallery | Bad Manners"
|
||||
href={new URL("/feed.xml", Astro.site)}
|
||||
/>
|
||||
<slot name="head" />
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
|||
|
|
@ -22,15 +22,19 @@ const copyrightedCharacters = await formatCopyrightedCharacters(props.copyrighte
|
|||
// const relatedGames = (await getEntries(props.relatedGames)).filter((game) => !game.data.isDraft);
|
||||
const categorizedTags = Object.fromEntries(
|
||||
(await getCollection("tag-categories")).flatMap((category) =>
|
||||
category.data.tags.map<[string, string]>(({ name }) =>
|
||||
typeof name === "string" ? [name, name] : [t(DEFAULT_LANG, name as any), t(props.lang, name as any)],
|
||||
category.data.tags.map<[string, string | null]>(({ name }) =>
|
||||
typeof name === "string" ? [name, name] : [name[DEFAULT_LANG], name[props.lang] ?? null],
|
||||
),
|
||||
),
|
||||
);
|
||||
const tags = props.tags.map<[string, string]>((tag) => {
|
||||
const tagSlug = slug(tag);
|
||||
if (!(tag in categorizedTags)) {
|
||||
console.log(`Tag "${tag}" doesn't have a category in the "tag-categories" collection!`);
|
||||
console.warn(`Tag "${tag}" doesn't have a category in the "tag-categories" collection`);
|
||||
return [tagSlug, tag];
|
||||
}
|
||||
if (categorizedTags[tag] == null) {
|
||||
console.warn(`No "${props.lang}" translation for tag "${tag}"`);
|
||||
return [tagSlug, tag];
|
||||
}
|
||||
return [tagSlug, categorizedTags[tag]!];
|
||||
|
|
|
|||
|
|
@ -34,15 +34,19 @@ const relatedStories = (await getEntries(props.relatedStories)).filter((story) =
|
|||
// const relatedGames = (await getEntries(props.relatedGames)).filter((game) => !game.data.isDraft);
|
||||
const categorizedTags = Object.fromEntries(
|
||||
(await getCollection("tag-categories")).flatMap((category) =>
|
||||
category.data.tags.map<[string, string]>(({ name }) =>
|
||||
typeof name === "string" ? [name, name] : [t(DEFAULT_LANG, name as any), t(props.lang, name as any)],
|
||||
category.data.tags.map<[string, string | null]>(({ name }) =>
|
||||
typeof name === "string" ? [name, name] : [name[DEFAULT_LANG], name[props.lang] ?? null],
|
||||
),
|
||||
),
|
||||
);
|
||||
const tags = props.tags.map<[string, string]>((tag) => {
|
||||
const tagSlug = slug(tag);
|
||||
if (!(tag in categorizedTags)) {
|
||||
console.log(`Tag "${tag}" doesn't have a category in the "tag-categories" collection!`);
|
||||
console.warn(`Tag "${tag}" doesn't have a category in the "tag-categories" collection`);
|
||||
return [tagSlug, tag];
|
||||
}
|
||||
if (categorizedTags[tag] == null) {
|
||||
console.warn(`No "${props.lang}" translation for tag "${tag}"`);
|
||||
return [tagSlug, tag];
|
||||
}
|
||||
return [tagSlug, categorizedTags[tag]!];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue