-
Notifications
You must be signed in to change notification settings - Fork 27.3k
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
Add dotCMS example #38214
Merged
Merged
Add dotCMS example #38214
Changes from all commits
Commits
Show all changes
79 commits
Select commit
Hold shift + click to select a range
cd8ea4d
feat: init dotCMS example with basic query
danestves 0df52f5
feat: working home with queries from dotCMS
danestves da88e62
feat: queries for single post
danestves 6b6dac2
fix: removing unused dotcms package
danestves b73f214
feat: using the errors inside the fetchAPI
danestves 54806ff
feat: document the functions inside api
danestves 45f0c3c
feat: removing docs images
danestves ab1f6bb
fix: flter for posts and more posts
danestves 6005fc9
Merge branch 'vercel:canary' into canary
danestves 47ba508
feat: adding prose styles for paragraphs
danestves 17e70d2
feat: spacing for more posts and avatar validation
danestves da48bf8
Merge branch 'vercel:canary' into canary
danestves a80e2aa
feat: add gradient placeholder for non image
danestves 06ed80b
Merge branch 'vercel:canary' into canary
danestves 16a1de9
Merge branch 'vercel:canary' into canary
wezell 200408d
Merge branch 'vercel:canary' into canary
fmontes 49a5d60
Merge branch 'vercel:canary' into canary
fmontes a53e88e
Merge branch 'vercel:canary' into canary
fmontes 8ad33b3
Merge branch 'vercel:canary' into canary
fmontes c91c187
Merge branch 'vercel:canary' into canary
oidacra 9e7cd7c
add example use dotCMS with Next.js
oidacra 1339109
fix comments
oidacra fb46bd8
Merge branch 'vercel:canary' into canary
fmontes c3a0696
fix use again Vercel Image component
oidacra ec63dd2
small fixes
oidacra 6defbc9
Merge pull request #1 from dotCMS/add-example-use-dotcms-nextjs
fmontes 28f972b
fix conflicts
oidacra 453c59a
Merge pull request #2 from dotCMS/add-example-use-dotcms-nextjs
oidacra 5efaac3
Render block field using inline components
fmontes fac1d5c
Round 2
fmontes acc9cd3
dotCMS/core#22070 Update the render storyblock field system
fmontes cc9ffed
Fix code block
fmontes e7e7d71
Fix code block
fmontes 042dda8
dotCMS/core#22063 Move the content to <PostBody /> component
fmontes 4da7ad0
Merge pull request #7 from dotCMS/issue-22063
oidacra 565f8c1
fix column gap to hero post component
oidacra 66fc8af
fix related query
oidacra 4fd807d
fix image componet
oidacra e3b179b
Some clean up and fixes
fmontes 5cd0994
Fix the media queries
fmontes 1f17909
dotCMS/core#22062 Fix Visual glitches
fmontes 40735cc
Merge branch 'vercel:canary' into canary
fmontes 51ba1a9
Merge branch 'vercel:canary' into canary
fmontes fa16963
Merge branch 'vercel:canary' into canary
fmontes bc7381c
Merge branch 'vercel:canary' into canary
fmontes 53a22d6
Update to next 12.2
fmontes dce7c49
Merge branch 'canary' into canary
fmontes 7a1517d
Merge branch 'canary' into canary
fmontes bc4ba84
Merge branch 'canary' into canary
fmontes 7be6d7f
Merge branch 'canary' into canary
fmontes a46a79c
Code review feedback
fmontes a50a2da
Add typescript
fmontes 102b61c
Convert to typescript
fmontes 075c63e
Merge branch 'canary' into canary
fmontes ce8e415
Merge branch 'canary' into canary
fmontes b578970
Merge branch 'canary' into canary
fmontes f256ad6
Merge branch 'canary' into canary
fmontes 3bc5edd
Add typescript related files to .gitignore
fmontes 73c4dae
Remove import react
fmontes 4cffb02
Run lint
fmontes ef07dfe
Add .env.local doc in the readme
fmontes 8db342a
Merge branch 'canary' into canary
fmontes c06f9f8
Merge branch 'canary' into canary
fmontes 33bfff2
Merge branch 'canary' into canary
fmontes e3444b4
Merge branch 'canary' into canary
fmontes 5aacbd4
Merge branch 'canary' into canary
fmontes 7d74cc8
Merge branch 'canary' into canary
fmontes a87a60c
Merge branch 'canary' into canary
fmontes 9a6bb60
Merge branch 'canary' into canary
fmontes 5d47c53
Merge branch 'canary' into canary
fmontes 8afe0e2
Update to next 12.3.0
fmontes efefadc
Update to next 12.3.0
fmontes a2f9d4b
Merge branch 'canary' into canary
fmontes eb65639
fix dependencies & paths
rjvelazco d9028f6
Merge branch 'vercel:canary' into canary
fmontes 926cd65
Merge branch 'vercel:canary' into canary
fmontes e646954
run lint-fix
rjvelazco e6f899c
clean up
rjvelazco 8bd48f2
Merge branch 'canary' into canary
fmontes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
NEXT_PUBLIC_DOTCMS_HOST="" | ||
NEXT_PREVIEW_SECRET_TOKEN="" | ||
DOTCMS_PREVIEW_SECRET="" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"root": true, | ||
"extends": "next/core-web-vitals" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,38 @@ | ||||||||||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||||||||||||
|
||||||||||||
# dependencies | ||||||||||||
/node_modules | ||||||||||||
/.pnp | ||||||||||||
.pnp.js | ||||||||||||
|
||||||||||||
# testing | ||||||||||||
/coverage | ||||||||||||
|
||||||||||||
# next.js | ||||||||||||
/.next/ | ||||||||||||
/out/ | ||||||||||||
|
||||||||||||
# production | ||||||||||||
/build | ||||||||||||
|
||||||||||||
# misc | ||||||||||||
.DS_Store | ||||||||||||
*.pem | ||||||||||||
|
||||||||||||
# debug | ||||||||||||
npm-debug.log* | ||||||||||||
yarn-debug.log* | ||||||||||||
yarn-error.log* | ||||||||||||
|
||||||||||||
# local env files | ||||||||||||
.env.local | ||||||||||||
.env.development.local | ||||||||||||
.env.test.local | ||||||||||||
.env.production.local | ||||||||||||
Comment on lines
+28
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
|
||||||||||||
# vercel | ||||||||||||
.vercel | ||||||||||||
/.env | ||||||||||||
fmontes marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||
|
||||||||||||
# typescript | ||||||||||||
*.tsbuildinfo | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# A statically generated blog example using Next.js and dotCMS | ||
|
||
This example showcases Next.js's [Static Generation](https://nextjs.org/docs/basic-features/pages) feature using [dotCMS](https://dotcms.com/) as the data source. | ||
|
||
## Demo | ||
|
||
### [https://nextjs-dotcms-blog.vercel.app/](https://nextjs-dotcms-blog.vercel.app/) | ||
|
||
## Deploy your own | ||
|
||
Using the Deploy Button below, you'll deploy the Next.js project. | ||
|
||
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https%3A%2F%2Fgithub.com%2FdotCMS%2Fnext.js%2Ftree%2Fcanary%2Fexamples%2Fcms-dotcms&project-name=nextjs-dotcms-blog&repository-name=nextjs-dotcms-blog&demo-title=Next.js+Blog&demo-description=Static+blog+with+multiple+authors+using+Preview+Mode&demo-url=https%3A%2F%2Fnext-blog-dotcms.vercel.app%2F) | ||
|
||
### Related examples | ||
|
||
- [WordPress](/examples/cms-wordpress) | ||
- [DatoCMS](/examples/cms-datocms) | ||
- [Sanity](/examples/cms-sanity) | ||
- [TakeShape](/examples/cms-takeshape) | ||
- [Prismic](/examples/cms-prismic) | ||
- [Strapi](/examples/cms-strapi) | ||
- [Agility CMS](/examples/cms-agilitycms) | ||
- [Cosmic](/examples/cms-cosmic) | ||
- [ButterCMS](/examples/cms-buttercms) | ||
- [Storyblok](/examples/cms-storyblok) | ||
- [GraphCMS](/examples/cms-graphcms) | ||
- [Kontent](/examples/cms-kontent) | ||
- [Ghost](/examples/cms-ghost) | ||
- [Contentful](/examples/cms-contentful) | ||
- [Blog Starter](/examples/blog-starter) | ||
|
||
## How to use | ||
|
||
fmontes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Rename `.env.local.example` to `.env.local` and complete the variables: | ||
|
||
`NEXT_PUBLIC_DOTCMS_HOST` is the dotCMS host, you can use `https://demo.dotcms.com` | ||
`DOTCMS_TOKEN` for the demo site, you can generate the token using: | ||
|
||
``` | ||
curl -H "Content-Type:application/json" --insecure -X POST -d ' | ||
{ "user":"[email protected]", "password":"admin", "expirationDays": 10 } | ||
' http://demo.dotcms.com:8080/api/v1/authentication/api-token | ||
``` | ||
|
||
Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init), [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/), or [pnpm](https://pnpm.io) to bootstrap the example: | ||
|
||
```bash | ||
npx create-next-app --example cms-dotcms cms-dotcms-app | ||
# or | ||
yarn create next-app --example cms-dotcms cms-dotcms-app | ||
# or | ||
pnpm create next-app --example cms-dotcms cms-dotcms-app | ||
``` | ||
|
||
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https%3A%2F%2Fgithub.com%2Fvercel%2Fnext.js%2Ftree%2Fcanary%2Fexamples%2Fcms-dotcms&project-name=nextjs-dotcms-blog&repository-name=nextjs-dotcms-blog&demo-title=Next.js+Blog&demo-description=Static+blog+with+multiple+authors+using+Preview+Mode&demo-url=https%3A%2F%2Fnext-blog-dotcms.vercel.app%2F) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/vercel/next.js/tree/canary/examples/${EXAMPLE_PATH}`} | ||
className="underline hover:text-success duration-200 transition-colors" | ||
> | ||
available on GitHub | ||
</a> | ||
. | ||
</> | ||
)} | ||
</div> | ||
</Container> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import DotCmsImage from './dotcms-image' | ||
|
||
export default function Avatar({ name, picture }) { | ||
return ( | ||
<div className="flex items-center "> | ||
<div className="w-12 h-12 relative mr-4"> | ||
{picture?.idPath ? ( | ||
<DotCmsImage | ||
src={picture?.idPath} | ||
layout="fill" | ||
className="rounded-full" | ||
alt={name} | ||
/> | ||
) : null} | ||
</div> | ||
<div className="text-xl font-bold">{name}</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import cn from 'classnames' | ||
import DotCmsImage from './dotcms-image' | ||
import Link from 'next/link' | ||
|
||
export const Bold = ({ children }) => <strong>{children}</strong> | ||
export const Italic = ({ children }) => <em>{children}</em> | ||
export const Strike = ({ children }) => <s>{children}</s> | ||
export const Underline = ({ children }) => <u>{children}</u> | ||
export const DotLink = ({ attrs: { href, target }, children }) => { | ||
const regEx = /https?:\/\// | ||
|
||
return regEx.test(href) ? ( | ||
<a href={href} rel="noopener noreferrer" target="_blank"> | ||
{children} | ||
</a> | ||
) : ( | ||
<Link href={href} target={target || '_self'}> | ||
{children} | ||
</Link> | ||
) | ||
} | ||
|
||
const nodeMarks = { | ||
link: DotLink, | ||
bold: Bold, | ||
underline: Underline, | ||
italic: Italic, | ||
strike: Strike, | ||
} | ||
|
||
export const TextNode = (props) => { | ||
const { marks = [], text } = props | ||
const mark = marks[0] || { type: '', attrs: {} } | ||
const newProps = { ...props, marks: marks.slice(1) } | ||
const Component = nodeMarks[mark?.type] | ||
|
||
if (!Component) { | ||
return text | ||
} | ||
|
||
return ( | ||
<Component attrs={mark.attrs}> | ||
<TextNode {...newProps} /> | ||
</Component> | ||
) | ||
} | ||
|
||
export const DotImage = ({ attrs: { textAlign, data } }) => { | ||
const { asset, title } = data | ||
const [imgTitle] = title.split('.') | ||
|
||
return ( | ||
<DotCmsImage | ||
objectFit="cover" | ||
style={{ textAlign: textAlign }} | ||
width="800" | ||
height="400" | ||
alt={`Cover Image for ${title}`} | ||
className={cn('shadow-small', { | ||
'hover:shadow-medium transition-shadow duration-200': imgTitle, | ||
})} | ||
src={asset} | ||
/> | ||
) | ||
} | ||
|
||
export const ListItem = ({ children }) => { | ||
return <li>{children}</li> | ||
} | ||
|
||
export const OrderedList = ({ children }) => { | ||
return <ol>{children}</ol> | ||
} | ||
|
||
export const Paragraph = ({ children }) => { | ||
return <p>{children}</p> | ||
} | ||
|
||
export const BulletList = ({ children }) => { | ||
return <ul>{children}</ul> | ||
} | ||
|
||
export const Heading = ({ level, children }) => { | ||
const Tag = `h${level}` as keyof JSX.IntrinsicElements | ||
return <Tag>{children}</Tag> | ||
} | ||
|
||
export const BlockQuote = ({ children }) => { | ||
return <blockquote>{children}</blockquote> | ||
} | ||
|
||
export const CodeBlock = ({ language, children }) => { | ||
return ( | ||
<pre data-language={language}> | ||
<code>{children}</code> | ||
</pre> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove this file.