Add "Woofer Exploration" and improve drafting
This commit is contained in:
parent
a9d5a88d0e
commit
405ad38f5d
25 changed files with 300 additions and 189 deletions
|
|
@ -4,18 +4,24 @@ import { marked, type RendererApi } from "marked";
|
|||
import { decode as tinyDecode } from "tiny-decode";
|
||||
import type { Lang, Website } from "../../../content/config";
|
||||
import { t } from "../../../i18n";
|
||||
import { formatCopyrightedCharacters } from "../../../utils/format_copyrighted_characters";
|
||||
|
||||
type ExportFormat = "bbcode" | "markdown";
|
||||
interface ExportWebsiteInfo {
|
||||
website: string;
|
||||
exportFormat: "bbcode" | "markdown";
|
||||
}
|
||||
|
||||
const WEBSITE_LIST = [
|
||||
["eka", "bbcode"],
|
||||
["furaffinity", "bbcode"],
|
||||
["inkbunny", "bbcode"],
|
||||
["sofurry", "bbcode"],
|
||||
["weasyl", "markdown"],
|
||||
] as const satisfies [Website, ExportFormat][];
|
||||
{ website: "eka", exportFormat: "bbcode" },
|
||||
{ website: "furaffinity", exportFormat: "bbcode" },
|
||||
{ website: "inkbunny", exportFormat: "bbcode" },
|
||||
{ website: "sofurry", exportFormat: "bbcode" },
|
||||
{ website: "weasyl", exportFormat: "markdown" },
|
||||
] as const satisfies ExportWebsiteInfo[];
|
||||
|
||||
type ExportWebsite = typeof WEBSITE_LIST extends ReadonlyArray<[infer K, ExportFormat]> ? K : never;
|
||||
type ExportWebsiteName = typeof WEBSITE_LIST extends ReadonlyArray<{ website: infer K }> ? K : never;
|
||||
|
||||
//type ExportWebsiteName = typeof WEBSITE_LIST extends ReadonlyArray<[infer K, DescriptionExportFormat]> ? K : never;
|
||||
|
||||
const bbcodeRenderer: RendererApi = {
|
||||
strong: (text) => `[b]${text}[/b]`,
|
||||
|
|
@ -122,7 +128,7 @@ function isPreferredWebsite(user: CollectionEntry<"users">, website: Website): b
|
|||
return !preferredLink || preferredLink == website;
|
||||
}
|
||||
|
||||
function getLinkForUser(user: CollectionEntry<"users">, website: ExportWebsite, anonymousFallback: string): string {
|
||||
function getLinkForUser(user: CollectionEntry<"users">, website: ExportWebsiteName, anonymousFallback: string): string {
|
||||
if (user.data.isAnonymous) {
|
||||
return anonymousFallback;
|
||||
}
|
||||
|
|
@ -207,35 +213,21 @@ export const getStaticPaths: GetStaticPaths = async () => {
|
|||
|
||||
export const GET: APIRoute<Props, Params> = async ({ props: { story }, site }) => {
|
||||
const { lang } = story.data;
|
||||
const copyrightedCharacters = await Promise.all(
|
||||
Object.values(
|
||||
Object.keys(story.data.copyrightedCharacters).reduce(
|
||||
(acc, character) => {
|
||||
const user = story.data.copyrightedCharacters[character];
|
||||
if (!(user.id in acc)) {
|
||||
acc[user.id] = [getEntry(user), []];
|
||||
}
|
||||
acc[user.id][1].push(character);
|
||||
return acc;
|
||||
},
|
||||
{} as Record<string, [Promise<CollectionEntry<"users">>, string[]]>,
|
||||
),
|
||||
).map(async ([userPromise, characters]) => [await userPromise, characters] as [CollectionEntry<"users">, string[]]),
|
||||
);
|
||||
const copyrightedCharacters = await formatCopyrightedCharacters(story.data.copyrightedCharacters);
|
||||
const authorsList = await getEntries([story.data.authors].flat());
|
||||
const commissioner = story.data.commissioner && (await getEntry(story.data.commissioner));
|
||||
const requester = story.data.requester && (await getEntry(story.data.requester));
|
||||
const anonymousUser = await getEntry("users", "anonymous");
|
||||
const anonymousFallback = getNameForUser(anonymousUser, anonymousUser, lang);
|
||||
|
||||
const description: Record<ExportWebsite, string> = Object.fromEntries(
|
||||
const description: Record<ExportWebsiteName, string> = Object.fromEntries(
|
||||
await Promise.all(
|
||||
WEBSITE_LIST.map(async ([website, exportFormat]) => {
|
||||
WEBSITE_LIST.map(async ({ website, exportFormat }) => {
|
||||
const u = (user: CollectionEntry<"users">) => getLinkForUser(user, website, anonymousFallback);
|
||||
const storyDescription = (
|
||||
[
|
||||
story.data.description,
|
||||
`*${t(lang, "story/warnings", story.data.wordCount, story.data.contentWarning.trim())}*`,
|
||||
`*${t(lang, "story/warnings", story.data.wordCount || "???", story.data.contentWarning.trim())}*`,
|
||||
t(
|
||||
lang,
|
||||
"export_story/writing",
|
||||
|
|
@ -253,8 +245,7 @@ export const GET: APIRoute<Props, Params> = async ({ props: { story }, site }) =
|
|||
.join("\n\n")
|
||||
.replaceAll(
|
||||
/\[([^\]]+)\]\((\/[^\)]+)\)/g,
|
||||
(_, group1, group2) =>
|
||||
`[${group1}](${new URL(group2, site).toString()})`,
|
||||
(_, group1, group2) => `[${group1}](${new URL(group2, site).toString()})`,
|
||||
);
|
||||
if (exportFormat === "bbcode") {
|
||||
return [
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue