Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Agility CMS example 🏆 #12788

Merged
merged 35 commits into from
Jun 2, 2020
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
ea365ba
initial check-in of agility-cms example
jamesvidler Apr 11, 2020
a728d3c
updated readme
jamesvidler Apr 11, 2020
a93b6b6
updated environment var names
jamesvidler Apr 11, 2020
63e0a54
added explicit preview for blogs
jamesvidler Apr 11, 2020
90b4441
Updated readme, added preview bar to homepage
jamesvidler Apr 11, 2020
240b50d
updated readme
jamesvidler Apr 11, 2020
af04592
added preview link to the readme
jamesvidler Apr 11, 2020
f9ba177
fixed typo in readme
jamesvidler Apr 11, 2020
4924457
added page management and updated preview
jamesvidler Apr 14, 2020
14e7c47
updated readme
jamesvidler Apr 14, 2020
7d0d258
udpated doc
jamesvidler Apr 14, 2020
939aef0
fixed steps in readme
jamesvidler Apr 14, 2020
849d72f
updated step numbers in read me
jamesvidler Apr 16, 2020
1831692
added fix for null author if author is not set or published
jamesvidler Apr 29, 2020
7d9d4aa
bug fix for static paths returning folders
jamesvidler Apr 29, 2020
71e8003
Merge pull request #1 from agility/cms-agilitycms-pagemanagement
May 12, 2020
3d5feab
Merge branch 'canary' of https://github.com/zeit/next.js into agility…
lfades May 25, 2020
b011921
Updated readme
lfades May 25, 2020
d25f7dd
Lint fix and other fixes
lfades May 26, 2020
3bbaf38
Updated more steps
lfades May 26, 2020
ff86fe3
More step updates
lfades May 27, 2020
a4a8490
updated more steps
lfades May 28, 2020
4864da1
Updated steps
lfades May 28, 2020
f22abb9
Added getClient method
lfades May 28, 2020
f30b00a
Separate client code from server code
lfades May 28, 2020
6f0b29a
Added key
lfades May 28, 2020
6bf55b4
Updated final steps and replaced now.json with vercel.json
lfades May 28, 2020
8861e1c
Updated links
lfades May 28, 2020
3a52502
Use the router to redirect to preview
lfades May 29, 2020
12b6e2f
Fix
lfades May 29, 2020
9fc50b5
Another fix
lfades May 29, 2020
fc7b35d
Merge branch 'canary' into canary
lfades Jun 2, 2020
6939b65
Update examples/cms-agilitycms/README.md
lfades Jun 2, 2020
66d6900
Update examples/cms-agilitycms/README.md
lfades Jun 2, 2020
71aa6f5
Apply suggestions from code review
lfades Jun 2, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions examples/cms-agilitycms/.env.local.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
NEXT_EXAMPLE_CMS_AGILITY_GUID=
NEXT_EXAMPLE_CMS_AGILITY_API_FETCH_KEY=
NEXT_EXAMPLE_CMS_AGILITY_API_PREVIEW_KEY=
NEXT_EXAMPLE_CMS_AGILITY_SECURITY_KEY=
2 changes: 2 additions & 0 deletions examples/cms-agilitycms/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.env*.local
lfades marked this conversation as resolved.
Show resolved Hide resolved
.vercel
326 changes: 326 additions & 0 deletions examples/cms-agilitycms/README.md

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions examples/cms-agilitycms/components/alert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import Container from './container'
import cn from 'classnames'
import { EXAMPLE_PATH } from '../lib/constants'

export default function Alert({ preview }) {
return (
<div
className={cn('border-b', {
'bg-accent-7 border-accent-7 text-white': preview,
'bg-accent-1 border-accent-2': !preview,
})}
>
<Container>
<div className="py-2 text-center text-sm">
{preview ? (
<>
This is page is a preview.{' '}
<a
href="/api/exit-preview"
className="underline hover:text-cyan duration-200 transition-colors"
>
Click here
</a>{' '}
to exit preview mode.
</>
) : (
<>
The source code for this blog is{' '}
<a
href={`https://github.com/zeit/next.js/tree/canary/examples/${EXAMPLE_PATH}`}
className="underline hover:text-success duration-200 transition-colors"
>
available on GitHub
</a>
.
</>
)}
</div>
</Container>
</div>
)
}
12 changes: 12 additions & 0 deletions examples/cms-agilitycms/components/avatar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default function Avatar({ name, picture }) {
return (
<div className="flex items-center">
<img
src={picture.url}
className="w-12 h-12 rounded-full mr-4"
alt={name}
/>
<div className="text-xl font-bold">{name}</div>
</div>
)
}
3 changes: 3 additions & 0 deletions examples/cms-agilitycms/components/container.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Container({ children }) {
return <div className="container mx-auto px-5">{children}</div>
}
28 changes: 28 additions & 0 deletions examples/cms-agilitycms/components/cover-image.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//import { Image } from 'react-datocms'
import Image from '../lib/components/image'
import cn from 'classnames'
import Link from 'next/link'

export default function CoverImage({ title, responsiveImage, slug }) {
const image = (
<Image
data={{
...responsiveImage,
}}
className={cn('shadow-small', {
'hover:shadow-medium transition-shadow duration-200': slug,
})}
/>
)
return (
<div className="-mx-5 sm:mx-0">
{slug ? (
<Link href="/[...slug]" as={`/posts/${slug}`}>
<a aria-label={title}>{image}</a>
</Link>
) : (
image
)}
</div>
)
}
6 changes: 6 additions & 0 deletions examples/cms-agilitycms/components/date.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { parseISO, format } from 'date-fns'

export default function Date({ dateString }) {
const date = parseISO(dateString)
return <time dateTime={dateString}>{format(date, 'LLLL d, yyyy')}</time>
}
30 changes: 30 additions & 0 deletions examples/cms-agilitycms/components/footer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import Container from './container'
import { EXAMPLE_PATH } from '../lib/constants'

export default function Footer() {
return (
<footer className="bg-accent-1 border-t border-accent-2">
<Container>
<div className="py-28 flex flex-col lg:flex-row items-center">
<h3 className="text-4xl lg:text-5xl font-bold tracking-tighter leading-tight text-center lg:text-left mb-10 lg:mb-0 lg:pr-4 lg:w-1/2">
Statically Generated with Next.js.
</h3>
<div className="flex flex-col lg:flex-row justify-center items-center lg:pl-4 lg:w-1/2">
<a
href="https://nextjs.org/docs/basic-features/pages"
className="mx-3 bg-black hover:bg-white hover:text-black border border-black text-white font-bold py-3 px-12 lg:px-8 duration-200 transition-colors mb-6 lg:mb-0"
>
Read Documentation
</a>
<a
href={`https://github.com/zeit/next.js/tree/canary/examples/${EXAMPLE_PATH}`}
className="mx-3 font-bold hover:underline"
>
View on GitHub
</a>
</div>
</div>
</Container>
</footer>
)
}
12 changes: 12 additions & 0 deletions examples/cms-agilitycms/components/header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Link from 'next/link'

export default function Header() {
return (
<h2 className="text-2xl md:text-4xl font-bold tracking-tight md:tracking-tighter leading-tight mb-20 mt-8">
<Link href="/">
<a className="hover:underline">Blog</a>
</Link>
.
</h2>
)
}
49 changes: 49 additions & 0 deletions examples/cms-agilitycms/components/hero-post.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import Link from 'next/link'
import Avatar from '../components/avatar'
import Date from '../components/date'
import CoverImage from '../components/cover-image'

export default function HeroPost({
title,
coverImage,
date,
excerpt,
author,
slug,
}) {
return (
<section>
<div className="mb-8 md:mb-16">
<CoverImage
title={title}
responsiveImage={coverImage.responsiveImage}
slug={slug}
/>
</div>
<div className="md:grid md:grid-cols-2 md:col-gap-16 lg:col-gap-8 mb-20 md:mb-28">
<div>
<h3 className="mb-4 text-4xl lg:text-6xl leading-tight">
<Link href="/[...slug]" as={`/posts/${slug}`}>
<a className="hover:underline">{title}</a>
</Link>
</h3>
<div className="mb-4 md:mb-0 text-lg">
<Date dateString={date} />
</div>
</div>
{author && (
<div>
<p className="text-lg leading-relaxed mb-4">{excerpt}</p>
<Avatar name={author.name} picture={author.picture} />
</div>
)}
</div>
</section>
)
}

// The data returned here will be send as `props` to the component
HeroPost.getCustomInitialProps = async function ({ client }) {
const post = await client.getLatestPost()
return post
}
28 changes: 28 additions & 0 deletions examples/cms-agilitycms/components/intro.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { CMS_NAME, CMS_URL } from '../lib/constants'

export default function Intro() {
return (
<section className="flex-col md:flex-row flex items-center md:justify-between mt-16 mb-16 md:mb-12">
<h1 className="text-6xl md:text-8xl font-bold tracking-tighter leading-tight md:pr-8">
Blog.
</h1>
<h4 className="text-center md:text-left text-lg mt-5 md:pl-8">
A statically generated blog example using{' '}
<a
href="https://nextjs.org/"
className="underline hover:text-success duration-200 transition-colors"
>
Next.js
</a>{' '}
and{' '}
<a
href={CMS_URL}
className="underline hover:text-success duration-200 transition-colors"
>
{CMS_NAME}
</a>
.
</h4>
</section>
)
}
16 changes: 16 additions & 0 deletions examples/cms-agilitycms/components/layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Alert from '../components/alert'
import Footer from '../components/footer'
import Meta from '../components/meta'

export default function Layout({ preview, children }) {
return (
<>
<Meta />
<div className="min-h-screen">
<Alert preview={preview} />
<main>{children}</main>
</div>
<Footer />
</>
)
}
18 changes: 18 additions & 0 deletions examples/cms-agilitycms/components/markdown-styles.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.markdown {
@apply text-lg leading-relaxed;
}

.markdown p,
.markdown ul,
.markdown ol,
.markdown blockquote {
@apply my-6;
}

.markdown h2 {
@apply text-3xl mt-12 mb-4 leading-snug;
}

.markdown h3 {
@apply text-2xl mt-8 mb-4 leading-snug;
}
42 changes: 42 additions & 0 deletions examples/cms-agilitycms/components/meta.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import Head from 'next/head'
import { CMS_NAME, HOME_OG_IMAGE_URL } from '../lib/constants'

export default function Meta() {
return (
<Head>
<link
rel="apple-touch-icon"
sizes="180x180"
href="/favicon/apple-touch-icon.png"
/>
<link
rel="icon"
type="image/png"
sizes="32x32"
href="/favicon/favicon-32x32.png"
/>
<link
rel="icon"
type="image/png"
sizes="16x16"
href="/favicon/favicon-16x16.png"
/>
<link rel="manifest" href="/favicon/site.webmanifest" />
<link
rel="mask-icon"
href="/favicon/safari-pinned-tab.svg"
color="#000000"
/>
<link rel="shortcut icon" href="/favicon/favicon.ico" />
<meta name="msapplication-TileColor" content="#000000" />
<meta name="msapplication-config" content="/favicon/browserconfig.xml" />
<meta name="theme-color" content="#000" />
<link rel="alternate" type="application/rss+xml" href="/feed.xml" />
<meta
name="description"
content={`A statically generated blog example using Next.js and ${CMS_NAME}.`}
/>
<meta property="og:image" content={HOME_OG_IMAGE_URL} />
</Head>
)
}
39 changes: 39 additions & 0 deletions examples/cms-agilitycms/components/more-stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import PostPreview from '../components/post-preview'

export default function MoreStories({ title, posts }) {
return (
<section>
<h2 className="mb-8 text-6xl md:text-7xl font-bold tracking-tighter leading-tight">
{title}
</h2>
<div className="grid grid-cols-1 md:grid-cols-2 md:col-gap-16 lg:col-gap-32 row-gap-20 md:row-gap-32 mb-32">
{posts.map((post) => (
<PostPreview
key={post.slug}
title={post.title}
coverImage={post.coverImage}
date={post.date}
author={post.author}
slug={post.slug}
excerpt={post.excerpt}
/>
))}
</div>
</section>
)
}

// The data returned here will be send as `props` to the component
MoreStories.getCustomInitialProps = async function ({
client,
item,
pageInSitemap,
}) {
const postToExcludeContentID = pageInSitemap.contentID ?? -1
const posts = await client.getPostsForMoreStories({ postToExcludeContentID })

return {
title: item.fields.title,
posts,
}
}
12 changes: 12 additions & 0 deletions examples/cms-agilitycms/components/post-body.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import markdownStyles from './markdown-styles.module.css'

export default function PostBody({ content }) {
return (
<div className="max-w-2xl mx-auto">
<div
className={markdownStyles['markdown']}
dangerouslySetInnerHTML={{ __html: content }}
/>
</div>
)
}
Loading