From c553e9bdbc65780df393783dcffdb9590244ba3a Mon Sep 17 00:00:00 2001 From: Miniapple8888 Date: Thu, 10 Feb 2022 16:09:16 -0500 Subject: [PATCH] refactor newsCard --- components/MiniNewsCard.module.css | 57 ------------------------------ components/MiniNewsCard.tsx | 42 ---------------------- components/NewsCard.tsx | 9 +++++ lib/news.ts | 17 +++++---- pages/index.tsx | 10 +++--- 5 files changed, 22 insertions(+), 113 deletions(-) delete mode 100644 components/MiniNewsCard.module.css delete mode 100644 components/MiniNewsCard.tsx diff --git a/components/MiniNewsCard.module.css b/components/MiniNewsCard.module.css deleted file mode 100644 index 879bb08b..00000000 --- a/components/MiniNewsCard.module.css +++ /dev/null @@ -1,57 +0,0 @@ -.card { - padding: calc(30rem / 16) calc(40rem / 16); - max-width: calc(524rem / 16); - background-color: var(--primary-background); - border-radius: calc(20rem / 16); - display: -webkit-box; - -webkit-line-clamp: 3; - -webkit-box-orient: vertical; - overflow: hidden; - margin-bottom: 1rem; -} - -.fit.card { - max-width: unset; - padding: unset; - border-radius: unset; -} - -.date { - font-size: calc(18rem / 16); - margin: 0; -} - -.author { - color: var(--secondary-heading); - font-style: normal; -} - -.content { - overflow: hidden; -} - -.content > *:first-child { - margin-top: 0; -} - -@media only screen and (max-width: calc(768rem / 16)) { - .card { - padding: 0; - max-width: unset; - background-color: transparent; - border-radius: 0; - } - - .date { - font-weight: 600; - } - - .content > *:first-child { - margin-top: 1rem; - } - - .content ul, - .content ol { - padding: 0 1rem; - } -} diff --git a/components/MiniNewsCard.tsx b/components/MiniNewsCard.tsx deleted file mode 100644 index 9425dc75..00000000 --- a/components/MiniNewsCard.tsx +++ /dev/null @@ -1,42 +0,0 @@ -import React, { ReactNode } from "react"; - -import { Link } from "./Link"; - -import styles from "./MiniNewsCard.module.css"; - -interface MiniNewsCardProps { - date: Date; - author: string; - children: ReactNode; - permalink: string; - fit?: boolean; -} - -export const MiniNewsCard: React.FC = ({ - date, - author, - children, - permalink, - fit = false, -}) => { - const classes = fit ? [styles.card, styles.fit] : [styles.card]; - - return ( -
-

- -

-
{author}
-
{children}
- - Learn more - -
- ); -}; diff --git a/components/NewsCard.tsx b/components/NewsCard.tsx index 16a31be3..f7063c13 100644 --- a/components/NewsCard.tsx +++ b/components/NewsCard.tsx @@ -1,11 +1,14 @@ import React, { ReactNode } from "react"; +import { Link } from "./Link"; + import styles from "./NewsCard.module.css"; interface NewsCardProps { date: Date; author: string; children: ReactNode; + permalink: string; fit?: boolean; } @@ -13,6 +16,7 @@ export const NewsCard: React.FC = ({ date, author, children, + permalink, fit = false, }) => { const classes = fit ? [styles.card, styles.fit] : [styles.card]; @@ -30,6 +34,11 @@ export const NewsCard: React.FC = ({
{author}
{children}
+ {!fit && ( + + Learn more + + )} ); }; diff --git a/lib/news.ts b/lib/news.ts index ed93bbab..4298ea88 100644 --- a/lib/news.ts +++ b/lib/news.ts @@ -74,18 +74,17 @@ export async function getNewsBySlug( path.join(NEWS_PATH, year, term, `${slug}.md`), "utf-8" ); - const { content, data: metadata } = matter(raw); + const { content: rawContent, 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, - }); - } + const content: string = shortened + ? truncateMarkdown(rawContent, { + limit: 150, + ellipsis: true, + }) + : rawContent; return { - content: await serialize(truncatedContent), + content: await serialize(content), metadata: { ...metadata, date: getLocalDateFromEST( diff --git a/pages/index.tsx b/pages/index.tsx index a683b5f5..dcd01727 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -8,7 +8,7 @@ import { EmailSignup } from "@/components/EmailSignup"; import { EventDescriptionCard } from "@/components/EventDescriptionCard"; import { Image } from "@/components/Image"; import { Link } from "@/components/Link"; -import { MiniNewsCard } from "@/components/MiniNewsCard"; +import { NewsCard } from "@/components/NewsCard"; import { GetShapesConfig } from "@/components/ShapesBackground"; import { SocialLinks } from "@/components/SocialLinks"; import { Title } from "@/components/Title"; @@ -87,14 +87,14 @@ export default function Home(props: Props) {


{props.news.length > 0 - ? props.news.map((news) => ( - ( + - + )) : null}