Changed article style on writing page

This commit is contained in:
r-freeman 2023-02-07 23:39:38 +00:00
parent c91fbc6d9f
commit 83702463d5
2 changed files with 27 additions and 8 deletions

View File

@ -1,10 +1,12 @@
import Link from 'next/link' import Link from 'next/link'
import clsx from 'clsx' import clsx from 'clsx'
import {ElementType, ReactNode} from 'react' import {ElementType, ReactNode} from 'react'
import {twMerge} from 'tailwind-merge'
import {Props} from 'types' import {Props} from 'types'
type Card = { type Card = {
as?: ElementType as?: ElementType
variant?: string
className?: string className?: string
children: ReactNode children: ReactNode
} }
@ -52,12 +54,33 @@ function ChevronRightIcon(props: Props) {
export function Card({ export function Card({
as: Component = 'div', as: Component = 'div',
variant = 'normal',
className, className,
children children
}: Card) { }: Card) {
type VariantStyles = {
normal: string
inline: string
}
const variantStyles: VariantStyles = {
normal:
'flex-col',
inline:
'flex-col md:flex-row md:justify-between',
}
return ( return (
<Component <Component
className={clsx(className, 'group relative flex flex-col items-baseline')} className={twMerge(`
group
relative
flex
items-baseline
${variantStyles[variant as keyof VariantStyles]}
${className ?? ""}
`)}
> >
{children} {children}
</Component> </Component>

View File

@ -4,7 +4,6 @@ import Head from 'next/head'
import {Card} from '@/components/Card' import {Card} from '@/components/Card'
import {SimpleLayout} from '@/components/layouts/SimpleLayout' import {SimpleLayout} from '@/components/layouts/SimpleLayout'
import {Views} from '@/components/Views' import {Views} from '@/components/Views'
import {Subscribe} from '@/components/Subscribe'
import {getAllArticles} from '@/lib/getAllArticles' import {getAllArticles} from '@/lib/getAllArticles'
import {formatDate} from '@/lib/formatDate' import {formatDate} from '@/lib/formatDate'
import {Article} from 'types' import {Article} from 'types'
@ -12,11 +11,11 @@ import {Article} from 'types'
function Article({article}: { article: Article }) { function Article({article}: { article: Article }) {
return ( return (
<article> <article>
<Card> <Card variant="inline">
<Card.Title href={`/writing/${article.slug}`}> <Card.Title href={`/writing/${article.slug}`}>
{article.title} {article.title}
</Card.Title> </Card.Title>
<p className="flex order-first space-x-1 z-10 mb-3"> <p className="flex order-first space-x-1 z-10 mb-3 md:mb-0 md:ml-4 md:order-last">
<Card.Eyebrow as="time" dateTime={article.date} decorate={false}> <Card.Eyebrow as="time" dateTime={article.date} decorate={false}>
{formatDate(article.date)} {formatDate(article.date)}
</Card.Eyebrow> </Card.Eyebrow>
@ -50,15 +49,12 @@ export default function ArticlesIndex({articles}: { articles: Article[] }) {
intro="All of my long-form thoughts on software engineering, and more, displayed in chronological order." intro="All of my long-form thoughts on software engineering, and more, displayed in chronological order."
gradient="bg-gradient-to-r from-pink-500 to-violet-500" gradient="bg-gradient-to-r from-pink-500 to-violet-500"
> >
<div className="mx-auto grid max-w-xl grid-cols-1 gap-y-20 lg:max-w-none lg:grid-cols-2"> <div className="mx-auto grid max-w-xl grid-cols-1 gap-y-20 lg:max-w-none">
<div className="max-w-3xl space-y-16 mt-6"> <div className="max-w-3xl space-y-16 mt-6">
{articles.map((article) => ( {articles.map((article) => (
<Article key={article.slug} article={article}/> <Article key={article.slug} article={article}/>
))} ))}
</div> </div>
<div className="lg:pl-16 xl:pl-24">
<Subscribe/>
</div>
</div> </div>
</SimpleLayout> </SimpleLayout>
</> </>