Skip to content

Commit 6c212d0

Browse files
committed
use next/image and update all dependencies, use tailwind JIT mode, addressing feedback
1 parent f587e0e commit 6c212d0

19 files changed

+92
-97
lines changed

examples/cms-builder-io/components/alert.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Container from './container'
22
import cn from 'classnames'
3-
import { EXAMPLE_PATH } from '@/lib/constants'
3+
import { EXAMPLE_PATH } from '../lib/constants'
44

55
export default function Alert({ preview }) {
66
return (

examples/cms-builder-io/components/avatar.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1+
import BuilderImage from './builder-image'
2+
13
export default function Avatar({ name, picture }) {
24
return (
35
<div className="flex items-center">
4-
<img
5-
src={picture}
6-
className="w-12 h-12 rounded-full mr-4 grayscale"
7-
alt={name}
8-
/>
6+
<div className="relative w-12 h-12 mr-4">
7+
<BuilderImage
8+
src={picture}
9+
layout="fill"
10+
className="rounded-full"
11+
alt={name}
12+
/>
13+
</div>
914
<div className="text-xl font-bold">{name}</div>
1015
</div>
1116
)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import Image from 'next/image'
2+
3+
const builderLoader = ({ src, width, quality }) => {
4+
return `${src}?width=${width}&quality=${quality || 75}`
5+
}
6+
7+
const BuilderImage = (props) => {
8+
return <Image loader={builderLoader} {...props} />
9+
}
10+
11+
export default BuilderImage

examples/cms-builder-io/components/cover-image.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
1+
import BuilderImage from './builder-image'
12
import Link from 'next/link'
3+
import cn from 'classnames'
24

35
export default function CoverImage({ title, url, slug }) {
6+
const image = (
7+
<BuilderImage
8+
width={2000}
9+
height={1000}
10+
alt={`Cover Image for ${title}`}
11+
className={cn('shadow-small', {
12+
'hover:shadow-medium transition-shadow duration-200': slug,
13+
})}
14+
src={url}
15+
/>
16+
)
17+
418
return (
519
<div className="sm:mx-0">
620
{slug ? (
7-
<Link as={`/posts/${slug}`} href="/posts/[slug]">
8-
<a aria-label={title}>
9-
<img src={url} alt={title} />
10-
</a>
21+
<Link href={`/posts/${slug}`}>
22+
<a aria-label={title}>{image}</a>
1123
</Link>
1224
) : (
13-
<img src={url} alt={title} />
25+
image
1426
)}
1527
</div>
1628
)
Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
import { parseISO, format } from 'date-fns'
2-
import { useEffect, useState } from 'react'
1+
import { format } from 'date-fns'
32

4-
// dateString might be null for unpublished posts
53
export default function DateComponent({ dateString }) {
6-
const [date, setDate] = useState(dateString ? parseISO(dateString) : null)
7-
useEffect(() => {
8-
if (!date) {
9-
setDate(new Date())
10-
}
11-
}, [date])
12-
return date && <time dateTime={date}>{format(date, 'LLLL d, yyyy')}</time>
4+
return (
5+
<time dateTime={new Date(dateString)}>
6+
{format(new Date(dateString), 'LLLL d, yyyy')}
7+
</time>
8+
)
139
}

examples/cms-builder-io/components/footer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Container from './container'
2-
import { EXAMPLE_PATH } from '@/lib/constants'
2+
import { EXAMPLE_PATH } from '../lib/constants'
33

44
export default function Footer() {
55
return (

examples/cms-builder-io/components/hero-post.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import Avatar from './avatar'
2-
import Date from './date'
3-
import CoverImage from './cover-image'
41
import Link from 'next/link'
2+
import Avatar from '../components/avatar'
3+
import DateComponent from '../components/date'
4+
import CoverImage from '../components/cover-image'
55

66
export default function HeroPost({
77
title,
@@ -14,7 +14,7 @@ export default function HeroPost({
1414
return (
1515
<section>
1616
<div className="mb-8 md:mb-16">
17-
<CoverImage title={title} url={coverImage} slug={slug} />
17+
<CoverImage title={title} slug={slug} url={coverImage} />
1818
</div>
1919
<div className="md:grid md:grid-cols-2 md:col-gap-16 lg:col-gap-8 mb-20 md:mb-28">
2020
<div>
@@ -24,12 +24,12 @@ export default function HeroPost({
2424
</Link>
2525
</h3>
2626
<div className="mb-4 md:mb-0 text-lg">
27-
<Date dateString={date} />
27+
<DateComponent dateString={date} />
2828
</div>
2929
</div>
3030
<div>
3131
<p className="text-lg leading-relaxed mb-4">{excerpt}</p>
32-
<Avatar name={author.name} picture={author.image} />
32+
{author && <Avatar name={author.name} picture={author.image} />}
3333
</div>
3434
</div>
3535
</section>

examples/cms-builder-io/components/intro.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CMS_NAME, CMS_URL } from '@/lib/constants'
1+
import { CMS_NAME, CMS_URL } from '../lib/constants'
22

33
export default function Intro() {
44
return (

examples/cms-builder-io/components/layout.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import Alert from './alert'
2-
import Footer from './footer'
3-
import Meta from './meta'
1+
import Alert from '../components/alert'
2+
import Footer from '../components/footer'
3+
import Meta from '../components/meta'
44

55
export default function Layout({ preview, children }) {
66
return (

examples/cms-builder-io/components/meta.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Head from 'next/head'
2-
import { CMS_NAME, HOME_OG_IMAGE_URL } from '@/lib/constants'
2+
import { CMS_NAME, HOME_OG_IMAGE_URL } from '../lib/constants'
33

44
export default function Meta() {
55
return (

0 commit comments

Comments
 (0)