mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-04-19 13:40:41 -05:00
* Kysely initial * Badges initial * Badge routes migrated * Badges migrated * Calendar work * Fix one type problem * Calendar work * findResultsByUserId work * Calendar reworking finished * PlusSuggestions work * Migrated suggestions * Builds progress * Migrated builds * Admin migrated * Migrate articles * User search * Faster getUser * Selectable/insertable as global * Refresh prod db script + patronTier index * identifierToUserId * updateProfile * findByIdentifier * More indexes * User upsert * upsertLite * findAllPlusMembers * updateResultHighlights * updateMany * User finished migration * Fix types * Fix PlusVotingResult typing * PlusVotingRepository WIP * Migrated resultsByMonthYear * Migrated plusVotes (done with db. related migrations) * Plus code to features folder * Fix TODOs * Export * Fix range * Migrate some user pages * Move rest user routes * Move /play * Map list generator * Front page * Move map list generation logic * Move plus voting logic * Info * API * Adjust TODOs * theme * Auth * Remove TODO
45 lines
1.1 KiB
TypeScript
45 lines
1.1 KiB
TypeScript
import matter from "gray-matter";
|
|
import fs from "node:fs";
|
|
import { ZodError } from "zod";
|
|
import { articleDataSchema } from "../articles-schemas.server";
|
|
import path from "node:path";
|
|
import { ARTICLES_FOLDER_PATH } from "../articles-constants";
|
|
|
|
export function articleBySlug(slug: string) {
|
|
try {
|
|
const rawMarkdown = fs.readFileSync(
|
|
path.join(ARTICLES_FOLDER_PATH, `${slug}.md`),
|
|
"utf8",
|
|
);
|
|
const { content, data } = matter(rawMarkdown);
|
|
|
|
const { date, ...restParsed } = articleDataSchema.parse(data);
|
|
|
|
return {
|
|
content,
|
|
date,
|
|
dateString: date.toLocaleDateString("en-US", {
|
|
day: "2-digit",
|
|
month: "long",
|
|
year: "numeric",
|
|
}),
|
|
authorLink: authorToLink(restParsed.author),
|
|
...restParsed,
|
|
};
|
|
} catch (e) {
|
|
if (!(e instanceof Error)) throw e;
|
|
|
|
if (e.message.includes("ENOENT") || e instanceof ZodError) {
|
|
return null;
|
|
}
|
|
|
|
throw e;
|
|
}
|
|
}
|
|
|
|
function authorToLink(author: string) {
|
|
if (author === "Riczi") return "https://twitter.com/Riczi2k";
|
|
|
|
return;
|
|
}
|