|
|
|
@ -3,6 +3,7 @@ import path from "path"; |
|
|
|
|
|
|
|
|
|
import { parse } from "date-fns"; |
|
|
|
|
import matter from "gray-matter"; |
|
|
|
|
import truncateMarkdown from "markdown-truncate"; |
|
|
|
|
import { MDXRemoteSerializeResult } from "next-mdx-remote"; |
|
|
|
|
import { serialize } from "next-mdx-remote/serialize"; |
|
|
|
|
|
|
|
|
@ -66,7 +67,8 @@ export async function getNewsByTerm( |
|
|
|
|
export async function getNewsBySlug( |
|
|
|
|
year: string, |
|
|
|
|
term: Term, |
|
|
|
|
slug: string |
|
|
|
|
slug: string, |
|
|
|
|
shortened = false |
|
|
|
|
): Promise<News> { |
|
|
|
|
const raw = await fs.readFile( |
|
|
|
|
path.join(NEWS_PATH, year, term, `${slug}.md`), |
|
|
|
@ -74,9 +76,16 @@ export async function getNewsBySlug( |
|
|
|
|
); |
|
|
|
|
const { content, data: metadata } = matter(raw); |
|
|
|
|
const slugDate = slug.split("-").slice(0, 3).join("-"); |
|
|
|
|
let truncatedContent: string = content; |
|
|
|
|
if (shortened) { |
|
|
|
|
truncatedContent = truncateMarkdown(content, { |
|
|
|
|
limit: 150, |
|
|
|
|
ellipsis: true, |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
content: await serialize(content), |
|
|
|
|
content: await serialize(truncatedContent), |
|
|
|
|
metadata: { |
|
|
|
|
...metadata, |
|
|
|
|
date: getLocalDateFromEST( |
|
|
|
@ -103,7 +112,9 @@ export async function getRecentNews(): Promise<News[]> { |
|
|
|
|
try { |
|
|
|
|
const newsInTerm = await getNewsByTerm(year, TERMS[term]); |
|
|
|
|
return await Promise.all( |
|
|
|
|
newsInTerm.map((slug) => getNewsBySlug(year, TERMS[term], slug)) |
|
|
|
|
newsInTerm.map((slug) => { |
|
|
|
|
return getNewsBySlug(year, TERMS[term], slug, true); |
|
|
|
|
}) |
|
|
|
|
); |
|
|
|
|
} catch (error) { |
|
|
|
|
return []; |
|
|
|
|