Skip to content

Commit e5a711e

Browse files
committed
Merge pull request #126 from IvanKiral/kontent-plugin
Kontent plugin
0 parents  commit e5a711e

Some content is hidden

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

64 files changed

+19407
-0
lines changed

.env.EXAMPLE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
KONTENT_PROJECT_ID=''

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.env*
2+
!.env.EXAMPLE
3+
node_modules
4+
.cache
5+
public
6+
dist
7+
.DS_Store

.prettierignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.cache
2+
public
3+
static
4+
node_modules
5+
.vscode
6+
.idea
7+
post-types.json
8+
taxonomies.json
9+
acf-field-groups.json

.prettierrc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"semi": false
3+
}

LICENSE

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
The BSD Zero Clause License (0BSD)
2+
3+
Copyright (c) 2022 Gatsby Inc.
4+
5+
Permission to use, copy, modify, and/or distribute this software for any
6+
purpose with or without fee is hereby granted.
7+
8+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
9+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
11+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14+
PERFORMANCE OF THIS SOFTWARE.

README.md

Lines changed: 311 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,311 @@
1+
<a href="https://www.gatsbyjs.com">
2+
<img alt="Gatsby" src="https://www.gatsbyjs.com/Gatsby-Monogram.svg" width="60" />
3+
</a>
4+
5+
# Gatsby Starter Kontent.ai Homepage
6+
7+
Create a homepage using Gatsby and Kontent.ai. This starter demonstrates how to use Kontent.ai to build a homepage and can be customized to match your own visual branding.
8+
9+
[View the Demo](https://gatsbykontentaihomepage.gatsbyjs.io/)
10+
11+
**Note:**
12+
This version of the Kontent.ai homepage starter is written in TypeScript. If you want to use Kontent.ai but JavaScript is more your style, there is also a JavaScript version maintained on [GitHub](https://github.com/gatsbyjs/gatsby-starter-kontent-ai-homepage).
13+
14+
## Quick start
15+
16+
To use this starter, you will need a new or existing [Kontent.ai project][] and then you will be asked for your [project id][].
17+
18+
[kontent.ai project]: https://kontent.ai/learn/tutorials/manage-kontent/projects/manage-projects/#a-create-projects
19+
[project id]: https://kontent.ai/learn/tutorials/develop-apps/get-content/get-content-items/#a-1-find-your-project-id
20+
21+
1. **Create a Gatsby site**
22+
23+
Use the Gatsby CLI to get started locally:
24+
25+
```sh repo
26+
npx gatsby new my-homepage https://github.com/gatsbyjs/gatsby-starter-kontent-ai-homepage-ts
27+
```
28+
29+
1. **Create an empty [Kontent.ai project](https://kontent.ai/learn/tutorials/manage-kontent/projects/manage-projects/#a-create-projects)**
30+
31+
1. **Run the Kontent.ai setup script.**
32+
33+
> If you've decided to use a non-empty project, keep in mind that there might occur errors during import. Therefore it is better to use an empty project. The script provides you with an option to clear your project before importing.
34+
35+
From your site's root directory, run:
36+
37+
```sh
38+
cd my-homepage
39+
yarn setup
40+
```
41+
42+
This will run a script to populate your Kontent.ai project with demo content.
43+
44+
1. **Start developing**
45+
46+
In your site directory, start the development server:
47+
48+
```sh
49+
yarn start
50+
```
51+
52+
Your site should now be running at <http://localhost:8000>
53+
54+
1. **Open the source code and start editing**
55+
56+
## Deploy your site
57+
58+
Once your content is available in Kontent.ai, deploy your site to [Gatsby Cloud](https://gatsbyjs.com/products/cloud):
59+
60+
1. Push your local site to a new repo in either GitHub, GitLab, or Bitbucket
61+
1. Log into your [Gatsby Cloud Dashboard][] and click on **Add a site**
62+
1. Use the **Import from a Git repository** option to find your site
63+
1. Add the environment variables from your `.env.production` file to Gatsby Cloud during setup
64+
1. Click **Build site** and your site should start building
65+
66+
For a more detailed walkthrough, see the tutorial on how to [build your site with Gatsby Cloud][tutorial].
67+
68+
[gatsby cloud dashboard]: https://gatsbyjs.com/dashboard
69+
[tutorial]: https://www.gatsbyjs.com/docs/tutorial/part-1/#build-your-site-with-gatsby-cloud
70+
71+
### Deploy without using the CLI
72+
73+
Alternatively, you can deploy this starter directly to Gatsby Cloud.
74+
Note that you will need to set up your content in Kontent.ai manually.
75+
76+
[![Deploy to Gatsby](https://www.gatsbyjs.com/deploynow.png "Deploy to Gatsby")](test)
77+
78+
## Setting up Gatsby Cloud Preview
79+
80+
To use Gatsby Cloud Preview with this site, follow the instructions in the
81+
[Connecting to Kontent.ai](https://support.gatsbyjs.com/hc/en-us/articles/360052324654-Connecting-to-Kontent).
82+
83+
## What's included?
84+
85+
```sh
86+
├── README.md
87+
├── gatsby-config.js
88+
├── gatsby-node.js
89+
├── src
90+
│   ├── components
91+
│   ├── pages
92+
│   ├── colors.css.ts
93+
│   ├── styles.css.ts
94+
│   └── theme.css.ts
95+
└── .env.EXAMPLE
96+
```
97+
98+
1. **`gatsby-config.js`**: [Gatsby config][] file that includes plugins required for this starter.
99+
1. **`gatsby-node.js`**: [Gatsby Node][] config file that creates an abstract data model for the homepage content.
100+
1. **`src/`**: The source directory for the starter, including pages, components, and [Vanilla Extract][] files for styling.
101+
102+
[gatsby config]: https://www.gatsbyjs.com/docs/reference/config-files/gatsby-config/
103+
[gatsby node]: https://www.gatsbyjs.com/docs/reference/config-files/gatsby-node/
104+
[vanilla extract]: https://vanilla-extract.style/
105+
106+
## How to
107+
108+
### Update the color theme
109+
110+
To update the colors used in this starter, edit the `src/colors.css.ts` file.
111+
112+
```.ts
113+
// src/colors.css.ts
114+
export const colors = {
115+
background: "#41d9c5",
116+
text: "#231f20",
117+
primary: "#231f20",
118+
muted: "#2aceb9",
119+
active: "#001d3d",
120+
black: "#000",
121+
}
122+
123+
```
124+
125+
If you'd like to add additional colors, add additional keys to this object.
126+
This file is imported into `src/theme.css.ts` and creates CSS custom properties, that can be imported and used in other `.css.ts` files.
127+
128+
The UI components file `src/components/ui.tsx` imports styles from `src/components/ui.css.ts`. You can see how the theme and color values are being used in this file.
129+
130+
### Add your logo
131+
132+
![Logo](./docs/images/logo.png)
133+
134+
Replace the `src/components/brand-logo.tsx` component with your own brand logo.
135+
If you have an SVG version, it can be rendered inline as a React component, following the example in this file. Note that SVG attributes will need to be camel cased for JSX.
136+
137+
Using an inline SVG for the logo allows it to pick up the colors used in CSS, which is how the logo colors are inverted for the mobile menu.
138+
139+
If you prefer to use an image, use the [`StaticImage`](https://www.gatsbyjs.com/docs/reference/built-in-components/gatsby-plugin-image/#staticimage) component from `gatsby-plugin-image` in place of the SVG in this file.
140+
141+
### Customize headings, buttons, and other styles
142+
143+
![Headings & Buttons](./docs/images/headings-buttons.png)
144+
145+
To further customize the look and feel of the homepage, edit the UI components in `src/components/ui.tsx` and styles in `src/components/ui.css.ts`.
146+
147+
### Customize section components
148+
149+
To customize any of the sections of the homepage, edit the relevant component in `src/components`.
150+
Most of the styles for these components are handled with shared UI components in `src/components/ui.tsx`.
151+
152+
### Create custom section components
153+
154+
To create a new type of section in your homepage, you'll want to create a new section component, using the existing components as an example.
155+
For this example, we'll create a new "Banner" component.
156+
157+
1. First, update your content type in Kontent.ai project
158+
159+
1. In `Content model` section create a new content type and name it "Homepage Banner."
160+
161+
<img src="./images/step-1.png" alt="Step 1" width="700" />
162+
163+
1. Add two fields to your freshly created content type: `Heading` and `Text` – these can be _Text_ types.
164+
165+
<img src="./images/step-2.png" alt="Step 2" width="700" />
166+
167+
1. Find the content type for _Homepage_ in Kontent.ai and adjust the settings for the _Content_ element. Click on settings icon to show configuration for the given element. Under _Allowed content types_, ensure that the _Homepage Banner_ type is checked to make it available as a content type on the Homepage.
168+
169+
<img src="./images/step-3.png" alt="Step 3" width="700" />
170+
<img src="./images/step-4.png" alt="Step 4" width="700" />
171+
172+
1. Navigate to the _Content & assets_ tab to edit the _Homepage_, start a new version of your item and add create a new item with new _Homepage Banner_ content type.
173+
174+
<img src="./images/step-5.png" alt="Step 5" width="500" />
175+
<img src="./images/step-6.png" alt="Step 6" width="500" />
176+
<img src=".s/images/step-7.png" alt="Step 7" width="500" />
177+
178+
1. Update `gatsby-node.js`
179+
180+
Edit your site's `gatsby-node.js` file, adding an interface for `HomepageBanner` and a type that matches your content type in Kontent.ai.
181+
This allows the homepage to query the abstract `HomepageBanner` type.
182+
183+
```js
184+
// in gatsby-node.js
185+
exports.createSchemaCustomization = async ({ actions }) => {
186+
// ...
187+
actions.createTypes(`
188+
interface HomepageBanner implements Node & HomepageBlock {
189+
id: ID!
190+
blocktype: String
191+
heading: String
192+
text: String
193+
}
194+
`)
195+
// ...
196+
actions.createTypes(`
197+
type kontent_item_homepage_banner implements Node & HomepageBanner & HomepageBlock @dontInfer {
198+
id: ID!
199+
blocktype: String @blocktype
200+
heading: String @proxy(from: "elements.heading.value")
201+
text: String @proxy(from: "elements.text.value")
202+
}
203+
`)
204+
// ...
205+
}
206+
```
207+
208+
1. Next, create the Banner component:
209+
210+
```jsx fileExt
211+
// src/components/banner.tsx
212+
import * as React from "react"
213+
import { graphql } from "gatsby"
214+
import { Section, Container, Heading, Text } from "./ui"
215+
216+
export default function Banner(props) {
217+
return (
218+
<Section>
219+
<Container>
220+
<Heading>{props.heading}</Heading>
221+
<Text>{props.text}</Text>
222+
</Container>
223+
</Section>
224+
)
225+
}
226+
227+
export const query = graphql`
228+
fragment HomepageBannerContent on HomepageBanner {
229+
id
230+
heading
231+
text
232+
}
233+
`
234+
```
235+
236+
1. Export the component from `src/components/sections.tsx`
237+
238+
```js fileExt
239+
// src/components/sections.tsx
240+
export { default as HomepageHero } from "./hero"
241+
export { default as HomepageFeature } from "./feature"
242+
export { default as HomepageFeatureList } from "./feature-list"
243+
export { default as HomepageLogoList } from "./logo-list"
244+
export { default as HomepageBenefitList } from "./benefit-list"
245+
export { default as HomepageTestimonialList } from "./testimonial-list"
246+
export { default as HomepageStatList } from "./stat-list"
247+
export { default as HomepageCta } from "./cta"
248+
export { default as HomepageProductList } from "./product-list"
249+
250+
// add export for new component
251+
export { default as HomepageBanner } from "./banner"
252+
```
253+
254+
1. Add the GraphQL query fragment to the query in `src/pages/index.tsx`
255+
256+
```js fileExt
257+
// in src/pages/index.tsx
258+
export const query = graphql`
259+
{
260+
homepage {
261+
id
262+
title
263+
description
264+
image {
265+
id
266+
url
267+
}
268+
blocks: content {
269+
id
270+
blocktype
271+
...HomepageHeroContent
272+
...HomepageFeatureContent
273+
...HomepageFeatureListContent
274+
...HomepageCtaContent
275+
...HomepageLogoListContent
276+
...HomepageTestimonialListContent
277+
...HomepageBenefitListContent
278+
...HomepageStatListContent
279+
...HomepageProductListContent
280+
# New component fragment
281+
...HomepageBannerContent
282+
}
283+
}
284+
}
285+
`
286+
```
287+
288+
## Troubleshooting
289+
290+
### Errors after making changes to the schema
291+
292+
If you've made changes to the `gatsby-node.js` file or changes to the Kontent.ai data model, clear the Gatsby cache before running the develop server:
293+
294+
```sh
295+
yarn clean && yarn start
296+
```
297+
298+
---
299+
300+
## 🎓 Learning Gatsby
301+
302+
Looking for more guidance? Full documentation for Gatsby lives [on the website](https://www.gatsbyjs.com/). Here are some places to start:
303+
304+
- **For most developers, we recommend starting with our [in-depth tutorial for creating a site with Gatsby](https://www.gatsbyjs.com/tutorial/).** It starts with zero assumptions about your level of ability and walks through every step of the process.
305+
- **To dive straight into code samples, head [to our documentation](https://www.gatsbyjs.com/docs/).**
306+
307+
## 💫 Deploy
308+
309+
[Build, Deploy, and Host On The Only Cloud Built For Gatsby](https://www.gatsbyjs.com/cloud/)
310+
311+
Gatsby Cloud is an end-to-end cloud platform specifically built for the Gatsby framework that combines a modern developer experience with an optimized, global edge network.

docs/images/step-1.png

108 KB
Loading

docs/images/step-2.png

225 KB
Loading

docs/images/step-3.png

207 KB
Loading

docs/images/step-4.png

265 KB
Loading

docs/images/step-5.png

271 KB
Loading

docs/images/step-6.png

254 KB
Loading

docs/images/step-7.png

176 KB
Loading

gatsby-browser.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import "@fontsource/dm-sans"
2+
import "@fontsource/dm-sans/500.css"
3+
import "@fontsource/dm-sans/700.css"
4+
import "@fontsource/dm-mono"
5+
import "@fontsource/dm-mono/500.css"

gatsby-config.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
require("dotenv").config({
2+
path: `.env.${process.env.NODE_ENV}`,
3+
})
4+
5+
module.exports = {
6+
siteMetadata: {
7+
siteUrl: "https://gatsbykontent-aihomepage.gatsbyjs.io/",
8+
title: "Gatsby Kontent.ai Homepage Starter",
9+
author: `Gatsby`,
10+
description: "A Gatsby Starter for building homepages with Kontent.ai",
11+
},
12+
plugins: [
13+
{
14+
resolve: `@kontent-ai/gatsby-source`,
15+
options: {
16+
projectId: process.env.KONTENT_PROJECT_ID,
17+
languageCodenames: [`en-US`],
18+
},
19+
},
20+
"gatsby-plugin-sharp",
21+
"gatsby-plugin-image",
22+
"gatsby-transformer-sharp",
23+
"gatsby-plugin-react-helmet",
24+
"gatsby-plugin-vanilla-extract",
25+
{
26+
resolve: "gatsby-plugin-manifest",
27+
options: {
28+
name: "Gatsby Starter Kontent.ai Homepage",
29+
short_name: "Gatsby",
30+
start_url: "/",
31+
background_color: "#41D9C5",
32+
theme_color: "#231F20",
33+
icon: "src/favicon.png",
34+
},
35+
},
36+
],
37+
}

0 commit comments

Comments
 (0)