Deprecate descriptionPlaintext field
This commit is contained in:
parent
a713adc1ec
commit
688f9b982d
27 changed files with 64 additions and 121 deletions
|
|
@ -215,13 +215,18 @@ export const GET: APIRoute<Props, Params> = async ({ props: { story }, site }) =
|
|||
(_, group1, group2) => `[${group1}](${new URL(group2, site).toString()})`,
|
||||
);
|
||||
if (exportFormat === "bbcode") {
|
||||
return [website, markdownToBbcode(storyDescription).replaceAll(/\n\n\n+/g, "\n\n").trim()];
|
||||
return [
|
||||
website,
|
||||
markdownToBbcode(storyDescription)
|
||||
.replaceAll(/\n\n\n+/g, "\n\n")
|
||||
.trim(),
|
||||
];
|
||||
} else if (exportFormat === "markdown") {
|
||||
return [website, storyDescription.replaceAll(/\n\n\n+/g, "\n\n").trim()];
|
||||
} else {
|
||||
throw new Error(`Unhandled export format "${exportFormat}"`);
|
||||
}
|
||||
})
|
||||
}),
|
||||
);
|
||||
|
||||
const storyHeader =
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@ import rss, { type RSSFeedItem } from "@astrojs/rss";
|
|||
import type { APIRoute } from "astro";
|
||||
import { getCollection, type CollectionEntry } from "astro:content";
|
||||
import sanitizeHtml from "sanitize-html";
|
||||
import { marked } from "marked";
|
||||
import { decode as tinyDecode } from "tiny-decode";
|
||||
import { t } from "../i18n";
|
||||
import type { Lang } from "../content/config";
|
||||
import { markdownToHtml } from "../utils/markdown_to_html";
|
||||
import { markdownToPlaintext } from "../utils/markdown_to_plaintext";
|
||||
|
||||
type FeedItem = RSSFeedItem & {
|
||||
pubDate: Date;
|
||||
|
|
@ -48,7 +48,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())} ${data.descriptionPlaintext || data.description}`
|
||||
`${t(data.lang, "story/warnings", data.wordCount, data.contentWarning.trim())}\n\n${markdownToPlaintext(data.description)}`
|
||||
.replaceAll(/[\n ]+/g, " ")
|
||||
.trim(),
|
||||
categories: ["story"],
|
||||
|
|
@ -73,8 +73,8 @@ export const GET: APIRoute = async ({ site }) => {
|
|||
? `<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>${tinyDecode(await marked(body))}` +
|
||||
`<hr>${tinyDecode(await marked(data.description))}`,
|
||||
`<hr>${markdownToHtml(body)}` +
|
||||
`<hr>${markdownToHtml(data.description)}`,
|
||||
),
|
||||
})),
|
||||
),
|
||||
|
|
@ -84,7 +84,7 @@ export const GET: APIRoute = async ({ site }) => {
|
|||
pubDate: toNoonUTCDate(data.pubDate!),
|
||||
link: `/games/${slug}`,
|
||||
description:
|
||||
`${t(data.lang, "game/warnings", data.platforms, data.contentWarning)} ${data.descriptionPlaintext || data.description}`
|
||||
`${t(data.lang, "game/warnings", data.platforms, data.contentWarning)}\n\n${markdownToPlaintext(data.description)}`
|
||||
.replaceAll(/[\n ]+/g, " ")
|
||||
.trim(),
|
||||
categories: ["game"],
|
||||
|
|
@ -104,8 +104,8 @@ export const GET: APIRoute = async ({ site }) => {
|
|||
)}</p>` +
|
||||
`<hr><p>${t(data.lang, "game/platforms", data.platforms)}</p>` +
|
||||
`<hr><p><em>${data.contentWarning.trim()}</em></p>` +
|
||||
`<hr>${tinyDecode(marked.parse(body) as string)}` +
|
||||
`<hr>${tinyDecode(marked.parse(data.description) as string)}`,
|
||||
`<hr>${markdownToHtml(body)}` +
|
||||
`<hr>${markdownToHtml(data.description)}`,
|
||||
),
|
||||
})),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -31,38 +31,36 @@ const seriesCollection = await getCollection("series");
|
|||
});
|
||||
|
||||
const uncategorizedTagsSet = new Set(tagsSet);
|
||||
const categorizedTags: Array<[string, string, [string, string | undefined][]]> = await Promise.all(
|
||||
tagCategories
|
||||
.sort((a, b) => a.data.index - b.data.index)
|
||||
.map(async (category) => {
|
||||
const tagList = category.data.tags.map(({ name, description }) => {
|
||||
description = description && markdownToPlaintext(description).replaceAll(/\n+/g, " ").trim();
|
||||
return (typeof name === "string" ? [name, description] : [name["eng"]!, description]) as [
|
||||
string,
|
||||
string | undefined,
|
||||
];
|
||||
});
|
||||
tagList.forEach(([tag, _], index) => {
|
||||
if (index !== tagList.findLastIndex(([otherTag, _]) => tag == otherTag)) {
|
||||
throw new Error(`Duplicated tag "${tag}" found in multiple tag-categories lists`);
|
||||
const categorizedTags = tagCategories
|
||||
.sort((a, b) => a.data.index - b.data.index)
|
||||
.map((category) => {
|
||||
const tagList = category.data.tags.map(({ name, description }) => {
|
||||
description = description && markdownToPlaintext(description).replaceAll(/\n+/g, " ").trim();
|
||||
return (typeof name === "string" ? { name, description } : { name: name["eng"]!, description }) as {
|
||||
name: string;
|
||||
description?: string;
|
||||
};
|
||||
});
|
||||
tagList.forEach(({ name }, index) => {
|
||||
if (index !== tagList.findLastIndex(({ name: otherTag }) => name == otherTag)) {
|
||||
throw new Error(`Duplicated tag "${name}" found in multiple tag-categories lists`);
|
||||
}
|
||||
});
|
||||
return [
|
||||
category.data.name,
|
||||
category.id,
|
||||
tagList.filter(({ name }) => {
|
||||
if (draftOnlyTagsSet.has(name)) {
|
||||
console.log(`Omitting draft-only tag "${name}"`);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
return [
|
||||
category.data.name,
|
||||
category.id,
|
||||
tagList.filter(([tag, _]) => {
|
||||
if (draftOnlyTagsSet.has(tag)) {
|
||||
console.log(`Omitting draft-only tag "${tag}"`);
|
||||
return false;
|
||||
}
|
||||
if (tagsSet.has(tag)) {
|
||||
uncategorizedTagsSet.delete(tag);
|
||||
}
|
||||
return true;
|
||||
}),
|
||||
];
|
||||
}),
|
||||
);
|
||||
if (tagsSet.has(name)) {
|
||||
uncategorizedTagsSet.delete(name);
|
||||
}
|
||||
return true;
|
||||
}),
|
||||
] as [string, string, { name: string; description?: string }[]];
|
||||
});
|
||||
|
||||
if (uncategorizedTagsSet.size > 0) {
|
||||
const tagList = [...uncategorizedTagsSet];
|
||||
|
|
@ -101,10 +99,10 @@ if (uncategorizedTagsSet.size > 0) {
|
|||
{category}
|
||||
</h2>
|
||||
<ul class="flex max-w-3xl flex-wrap gap-x-2 gap-y-2 px-2">
|
||||
{tagList.map(([tag, description]) => (
|
||||
{tagList.map(({ name, description }) => (
|
||||
<li class="rounded-full bg-bm-300 px-3 py-1 text-sm text-black shadow-sm dark:bg-bm-600 dark:text-white">
|
||||
<a class="hover:underline focus:underline" href={`/tags/${slug(tag)}`} title={description}>
|
||||
{tag}
|
||||
<a class="hover:underline focus:underline" href={`/tags/${slug(name)}`} title={description}>
|
||||
{name}
|
||||
</a>
|
||||
</li>
|
||||
))}
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ export const getStaticPaths: GetStaticPaths = async () => {
|
|||
);
|
||||
return acc;
|
||||
},
|
||||
[] as [string, { description: string | undefined; related: string[] | undefined }][],
|
||||
[] as [string, { description?: string; related?: string[] }][],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue