Skip to content

Commit 15cc889

Browse files
fmontesdanestveswezelloidacrarjvelazco
authored
chore(examples): Add dotCMS example (vercel#38214)
<!-- Thanks for opening a PR! Your contribution is much appreciated. In order to make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below. Choose the right checklist for the change that you're making: --> This adds a new example under cms-dotcms/. Is a general-purpose example that should allow developers to undestand how to use next.js with dotCMS apis. ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [x] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have helpful link attached, see `contributing.md` ## Documentation / Examples - [x] Make sure the linting passes by running `pnpm lint` - [x] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples) Co-authored-by: Daniel Esteves <[email protected]> Co-authored-by: Will Ezell <[email protected]> Co-authored-by: Arcadio Quintero A <[email protected]> Co-authored-by: Rafael <[email protected]>
1 parent e0c3d28 commit 15cc889

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+1308
-0
lines changed

examples/cms-agilitycms/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Once you have access to [the environment variables you'll need](#step-15-set-up-
3333
- [Umbraco Heartcore](/examples/cms-umbraco-heartcore)
3434
- [Blog Starter](/examples/blog-starter)
3535
- [Builder.io](/examples/cms-builder-io)
36+
- [DotCMS](/examples/cms-dotcms)
3637
- [Enterspeed](/examples/cms-enterspeed)
3738

3839
## How to use

examples/cms-builder-io/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,5 @@ Alternatively, you can deploy using our template by clicking on the Deploy butto
9797
- [Kontent](/examples/cms-kontent)
9898
- [Ghost](/examples/cms-ghost)
9999
- [Blog Starter](/examples/blog-starter)
100+
- [DotCMS](/examples/cms-dotcms)
100101
- [Enterspeed](/examples/cms-enterspeed)

examples/cms-buttercms/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Once you have access to your Butter API token, you can deploy your Butterized pr
3434
- [Umbraco Heartcore](/examples/cms-umbraco-heartcore)
3535
- [Blog Starter](/examples/blog-starter)
3636
- [Builder.io](/examples/cms-builder-io)
37+
- [DotCMS](/examples/cms-dotcms)
3738
- [Enterspeed](/examples/cms-enterspeed)
3839

3940
## How to use

examples/cms-contentful/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Using the Deploy Button below, you'll deploy the Next.js project as well as conn
3030
- [Umbraco Heartcore](/examples/cms-umbraco-heartcore)
3131
- [Blog Starter](/examples/blog-starter)
3232
- [Builder.io](/examples/cms-builder-io)
33+
- [DotCMS](/examples/cms-dotcms)
3334
- [Enterspeed](/examples/cms-enterspeed)
3435

3536
## How to use

examples/cms-cosmic/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Once you have access to [the environment variables you'll need](#step-3-set-up-e
3030
- [Umbraco Heartcore](/examples/cms-umbraco-heartcore)
3131
- [Blog Starter](/examples/blog-starter)
3232
- [Builder.io](/examples/cms-builder-io)
33+
- [DotCMS](/examples/cms-dotcms)
3334
- [Enterspeed](/examples/cms-enterspeed)
3435

3536
## How to use

examples/cms-datocms/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ This example showcases Next.js's [Static Generation](https://nextjs.org/docs/bas
2424
- [Umbraco Heartcore](/examples/cms-umbraco-heartcore)
2525
- [Blog Starter](/examples/blog-starter)
2626
- [Builder.io](/examples/cms-builder-io)
27+
- [DotCMS](/examples/cms-dotcms)
2728
- [Enterspeed](/examples/cms-enterspeed)
2829

2930
## Deploy your own
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
NEXT_PUBLIC_DOTCMS_HOST=""
2+
NEXT_PREVIEW_SECRET_TOKEN=""
3+
DOTCMS_PREVIEW_SECRET=""

examples/cms-dotcms/.eslintrc.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"root": true,
3+
"extends": "next/core-web-vitals"
4+
}

examples/cms-dotcms/.gitignore

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
/.next/
13+
/out/
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
*.pem
21+
22+
# debug
23+
npm-debug.log*
24+
yarn-debug.log*
25+
yarn-error.log*
26+
27+
# local env files
28+
.env.local
29+
.env.development.local
30+
.env.test.local
31+
.env.production.local
32+
33+
# vercel
34+
.vercel
35+
/.env
36+
37+
# typescript
38+
*.tsbuildinfo

examples/cms-dotcms/README.md

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# A statically generated blog example using Next.js and dotCMS
2+
3+
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.
4+
5+
## Demo
6+
7+
### [https://nextjs-dotcms-blog.vercel.app/](https://nextjs-dotcms-blog.vercel.app/)
8+
9+
## Deploy your own
10+
11+
Using the Deploy Button below, you'll deploy the Next.js project.
12+
13+
[![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)
14+
15+
### Related examples
16+
17+
- [WordPress](/examples/cms-wordpress)
18+
- [DatoCMS](/examples/cms-datocms)
19+
- [Sanity](/examples/cms-sanity)
20+
- [TakeShape](/examples/cms-takeshape)
21+
- [Prismic](/examples/cms-prismic)
22+
- [Strapi](/examples/cms-strapi)
23+
- [Agility CMS](/examples/cms-agilitycms)
24+
- [Cosmic](/examples/cms-cosmic)
25+
- [ButterCMS](/examples/cms-buttercms)
26+
- [Storyblok](/examples/cms-storyblok)
27+
- [GraphCMS](/examples/cms-graphcms)
28+
- [Kontent](/examples/cms-kontent)
29+
- [Ghost](/examples/cms-ghost)
30+
- [Contentful](/examples/cms-contentful)
31+
- [Blog Starter](/examples/blog-starter)
32+
33+
## How to use
34+
35+
Rename `.env.local.example` to `.env.local` and complete the variables:
36+
37+
`NEXT_PUBLIC_DOTCMS_HOST` is the dotCMS host, you can use `https://demo.dotcms.com`
38+
`DOTCMS_TOKEN` for the demo site, you can generate the token using:
39+
40+
```
41+
curl -H "Content-Type:application/json" --insecure -X POST -d '
42+
{ "user":"[email protected]", "password":"admin", "expirationDays": 10 }
43+
' http://demo.dotcms.com:8080/api/v1/authentication/api-token
44+
```
45+
46+
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:
47+
48+
```bash
49+
npx create-next-app --example cms-dotcms cms-dotcms-app
50+
# or
51+
yarn create next-app --example cms-dotcms cms-dotcms-app
52+
# or
53+
pnpm create next-app --example cms-dotcms cms-dotcms-app
54+
```
55+
56+
[![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)
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import Container from './container'
2+
import cn from 'classnames'
3+
import { EXAMPLE_PATH } from '@lib/constants'
4+
5+
export default function Alert({ preview }) {
6+
return (
7+
<div
8+
className={cn('border-b', {
9+
'bg-accent-7 border-accent-7 text-white': preview,
10+
'bg-accent-1 border-accent-2': !preview,
11+
})}
12+
>
13+
<Container>
14+
<div className="py-2 text-center text-sm">
15+
{preview ? (
16+
<>
17+
This is page is a preview.{' '}
18+
<a
19+
href="/api/exit-preview"
20+
className="underline hover:text-cyan duration-200 transition-colors"
21+
>
22+
Click here
23+
</a>{' '}
24+
to exit preview mode.
25+
</>
26+
) : (
27+
<>
28+
The source code for this blog is{' '}
29+
<a
30+
href={`https://github.com/vercel/next.js/tree/canary/examples/${EXAMPLE_PATH}`}
31+
className="underline hover:text-success duration-200 transition-colors"
32+
>
33+
available on GitHub
34+
</a>
35+
.
36+
</>
37+
)}
38+
</div>
39+
</Container>
40+
</div>
41+
)
42+
}
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import DotCmsImage from './dotcms-image'
2+
3+
export default function Avatar({ name, picture }) {
4+
return (
5+
<div className="flex items-center ">
6+
<div className="w-12 h-12 relative mr-4">
7+
{picture?.idPath ? (
8+
<DotCmsImage
9+
src={picture?.idPath}
10+
layout="fill"
11+
className="rounded-full"
12+
alt={name}
13+
/>
14+
) : null}
15+
</div>
16+
<div className="text-xl font-bold">{name}</div>
17+
</div>
18+
)
19+
}
+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import cn from 'classnames'
2+
import DotCmsImage from './dotcms-image'
3+
import Link from 'next/link'
4+
5+
export const Bold = ({ children }) => <strong>{children}</strong>
6+
export const Italic = ({ children }) => <em>{children}</em>
7+
export const Strike = ({ children }) => <s>{children}</s>
8+
export const Underline = ({ children }) => <u>{children}</u>
9+
export const DotLink = ({ attrs: { href, target }, children }) => {
10+
const regEx = /https?:\/\//
11+
12+
return regEx.test(href) ? (
13+
<a href={href} rel="noopener noreferrer" target="_blank">
14+
{children}
15+
</a>
16+
) : (
17+
<Link href={href} target={target || '_self'}>
18+
{children}
19+
</Link>
20+
)
21+
}
22+
23+
const nodeMarks = {
24+
link: DotLink,
25+
bold: Bold,
26+
underline: Underline,
27+
italic: Italic,
28+
strike: Strike,
29+
}
30+
31+
export const TextNode = (props) => {
32+
const { marks = [], text } = props
33+
const mark = marks[0] || { type: '', attrs: {} }
34+
const newProps = { ...props, marks: marks.slice(1) }
35+
const Component = nodeMarks[mark?.type]
36+
37+
if (!Component) {
38+
return text
39+
}
40+
41+
return (
42+
<Component attrs={mark.attrs}>
43+
<TextNode {...newProps} />
44+
</Component>
45+
)
46+
}
47+
48+
export const DotImage = ({ attrs: { textAlign, data } }) => {
49+
const { asset, title } = data
50+
const [imgTitle] = title.split('.')
51+
52+
return (
53+
<DotCmsImage
54+
objectFit="cover"
55+
style={{ textAlign: textAlign }}
56+
width="800"
57+
height="400"
58+
alt={`Cover Image for ${title}`}
59+
className={cn('shadow-small', {
60+
'hover:shadow-medium transition-shadow duration-200': imgTitle,
61+
})}
62+
src={asset}
63+
/>
64+
)
65+
}
66+
67+
export const ListItem = ({ children }) => {
68+
return <li>{children}</li>
69+
}
70+
71+
export const OrderedList = ({ children }) => {
72+
return <ol>{children}</ol>
73+
}
74+
75+
export const Paragraph = ({ children }) => {
76+
return <p>{children}</p>
77+
}
78+
79+
export const BulletList = ({ children }) => {
80+
return <ul>{children}</ul>
81+
}
82+
83+
export const Heading = ({ level, children }) => {
84+
const Tag = `h${level}` as keyof JSX.IntrinsicElements
85+
return <Tag>{children}</Tag>
86+
}
87+
88+
export const BlockQuote = ({ children }) => {
89+
return <blockquote>{children}</blockquote>
90+
}
91+
92+
export const CodeBlock = ({ language, children }) => {
93+
return (
94+
<pre data-language={language}>
95+
<code>{children}</code>
96+
</pre>
97+
)
98+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function Container({ children }) {
2+
return <div className="container mx-auto px-5">{children}</div>
3+
}

0 commit comments

Comments
 (0)