rsnext/examples/cms-cosmic/components/cover-image.js
Jazib Sawar 6ce7a0378e
CMS Cosmic Example (#13499)
* Add Cosmic CMS Example

* with native .env support, this file isn't needed anymore

* FIX use path alias

* Add cosmicjs package

* Fix alias import in pages/api/preview

* Added: react-imgix & lazysizes package

* Load lazysizes in layout

* Used imgix image with lazyloading

* Added avatar imgix optimizations

* EDITED: steps to install content, preview

* EDITED: demo link

* EDITED: Install step

* EDITED: preview link steps

* Edited: demo link

* FIXED: object_slug

* Screenshots

* Fixed object_slug link

* Update README.md

* Fix: formatting issue

* Updated readme and renamed .env to env.local

* Sanity checks

* Handle fallback data when expected

* Added link to the example in other examples

* Updated demo deployment

* Added example to docs

* minor lint fix

* Remove manual download step

* use vercel.json

Co-authored-by: Tony Spiro <tspiro@tonyspiro.com>
Co-authored-by: Luis Alvarez <luis@vercel.com>
2020-06-04 15:18:11 -05:00

35 lines
838 B
JavaScript

import cn from 'classnames'
import Link from 'next/link'
import Imgix from 'react-imgix'
export default function CoverImage({ title, url, slug }) {
const image = (
<Imgix
src={url}
alt={`Cover Image for ${title}`}
className={cn('lazyload shadow-small', {
'hover:shadow-medium transition-shadow duration-200': slug,
})}
sizes="100vw"
attributeConfig={{
src: 'data-src',
srcSet: 'data-srcset',
sizes: 'data-sizes',
}}
htmlAttributes={{
src: `${url}?auto=format,compress&q=1&blur=500&w=auto`,
}}
/>
)
return (
<div className="-mx-5 sm:mx-0">
{slug ? (
<Link as={`/posts/${slug}`} href="/posts/[slug]">
<a aria-label={title}>{image}</a>
</Link>
) : (
image
)}
</div>
)
}