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
|
|
@ -6,6 +6,7 @@ import sanitizeHtml from "sanitize-html";
|
|||
import { t } from "../i18n";
|
||||
import type { Lang } from "../content/config";
|
||||
import { markdownToPlaintext } from "../utils/markdown_to_plaintext";
|
||||
import { getUsernameForLang } from "../utils/get_username_for_lang";
|
||||
|
||||
type FeedItem = RSSFeedItem & {
|
||||
pubDate: Date;
|
||||
|
|
@ -20,7 +21,7 @@ function toNoonUTCDate(date: Date) {
|
|||
}
|
||||
|
||||
const getLinkForUser = (user: CollectionEntry<"users">, lang: Lang) => {
|
||||
const userName = user.data.nameLang[lang] || user.data.name;
|
||||
const userName = getUsernameForLang(user, lang);
|
||||
if (user.data.preferredLink) {
|
||||
const link = user.data.links[user.data.preferredLink]!;
|
||||
return `<a href="${typeof link === "string" ? link : link[0]}">${userName}</a>`;
|
||||
|
|
@ -40,7 +41,7 @@ export const GET: APIRoute = async ({ site }) => {
|
|||
return rss({
|
||||
title: "Gallery | Bad Manners",
|
||||
description: "Stories, games, and (possibly) more by Bad Manners",
|
||||
site: site as URL,
|
||||
site: site!,
|
||||
items: [
|
||||
await Promise.all(
|
||||
stories.map<Promise<FeedItem>>(async ({ data, slug, body }) => ({
|
||||
|
|
@ -48,7 +49,7 @@ export const GET: APIRoute = async ({ site }) => {
|
|||
pubDate: toNoonUTCDate(data.pubDate!),
|
||||
link: `/stories/${slug}`,
|
||||
description:
|
||||
`${t(data.lang, "story/warnings", data.wordCount, data.contentWarning.trim())}\n\n${markdownToPlaintext(data.description)}`
|
||||
`${t(data.lang, "story/warnings", data.wordCount || "???", data.contentWarning.trim())}\n\n${markdownToPlaintext(data.description)}`
|
||||
.replaceAll(/[\n ]+/g, " ")
|
||||
.trim(),
|
||||
categories: ["story"],
|
||||
|
|
@ -72,7 +73,7 @@ export const GET: APIRoute = async ({ site }) => {
|
|||
(data.commissioner
|
||||
? `<p>${t(data.lang, "export_story/commissioned_by", getLinkForUser(users.find((user) => user.id === data.commissioner!.id)!, data.lang))}</p>`
|
||||
: "") +
|
||||
`<hr><p><em>${t(data.lang, "story/warnings", data.wordCount, data.contentWarning.trim())}</em></p>` +
|
||||
`<hr><p><em>${t(data.lang, "story/warnings", data.wordCount || "???", data.contentWarning.trim())}</em></p>` +
|
||||
`<hr>${await markdown(body)}` +
|
||||
`<hr>${await markdown(data.description)}`,
|
||||
),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue