Skip to content

Commit

Permalink
move newsletters page to newsletter route
Browse files Browse the repository at this point in the history
  • Loading branch information
IgboPharaoh committed Feb 13, 2025
1 parent a929514 commit 2f53d04
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import { NewsLetter, NewsLetterDataType, sortedAuthorData } from "@/helpers/type
import Wrapper from "@/app/components/server/wrapper";
import { formattedDate, getSummaryDataInfo } from "@/helpers/utils";

const monthlyNewsletter = async (path: string[]) => {
const pathString = path.join("/").replace("month/", "/");

const monthlyNewsletter = async (path: string) => {
try {
const data = fs.readFileSync(`${process.cwd()}/public/static/static/${pathString}`, "utf-8");
const data = fs.readFileSync(`${process.cwd()}/public/static/static/${path}`, "utf-8");
const parsedData = JSON.parse(data) as NewsLetterDataType;
return parsedData;
} catch (err) {
Expand All @@ -28,10 +26,28 @@ const getSummaryData = async (path: string[]) => {
}
};

export default async function Page({ params }: { params: { path: string[] } }) {
const url = params.path.join("/").replace("month/", "/");
export default async function Page({ params }: { params: { path: string } }) {
const url = params.path;
const splitUrl = url.split("-");
const monthsInOrder: Record<string, string> = {
"01": "Jan",
"02": "Feb",
"03": "March",
"04": "April",
"05": "May",
"06": "June",
"07": "July",
"08": "Aug",
"09": "Sept",
"10": "Oct",
"11": "Nov",
"12": "Dec",
};

const [year, month, _day] = splitUrl;
const newsletterPath = `/newsletters/${`${monthsInOrder[month]}_${year}`}/${url}-newsletter.json`;

const data = await monthlyNewsletter(params.path);
const data = await monthlyNewsletter(newsletterPath);
if (!data) return <h1>No Data found</h1>;

const sortedNewThreadData = data.new_threads_this_week.sort((a, b) => new Date(b.published_at).getTime() - new Date(a.published_at).getTime());
Expand Down Expand Up @@ -75,7 +91,7 @@ export default async function Page({ params }: { params: { path: string[] } }) {

return (
<Wrapper>
<MonthlyNewsletterDisplay newsletter={data} url={`/month/${url}`} activeDiscussions={datedPosts} />
<MonthlyNewsletterDisplay newsletter={data} url={`/newsletters/${url}`} activeDiscussions={datedPosts} />
</Wrapper>
);
}
File renamed without changes.

0 comments on commit 2f53d04

Please sign in to comment.