Skip to content

Commit

Permalink
extract slice to layout
Browse files Browse the repository at this point in the history
  • Loading branch information
Ondřej Chrastina committed Jan 23, 2023
1 parent 222743a commit cfb3a5b
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 40 deletions.
2 changes: 1 addition & 1 deletion site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@kontent-ai/gatsby-starter-kontent-hello-world",
"private": true,
"description": "A simplified bare-bones testing site for Gatsby",
"version": "0.1.0",
"version": "0.1.1",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
18 changes: 8 additions & 10 deletions site/src/components/footer.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import React from "react";
import { graphql } from 'gatsby';

const Footer = ({data}) => {
return (
<footer style={{"padding-top": "16px"}}>
<p>This footer is created using Slice API</p>
<p>Author: {data.author.elements.name.value}</p>
const Footer = ({ data }) => {
return (
<footer style={{ paddingTop: "16px" }}>
<p>This footer is created using Slice API</p>
<p>Author: {data.author.elements.name.value}</p>
</footer>
)
)
}

export default Footer

export const query = graphql`
{
author: kontentItemAuthor {
Expand All @@ -21,7 +23,3 @@ export const query = graphql`
}
}
`



export default Footer
9 changes: 9 additions & 0 deletions site/src/components/layout.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.page {
display: flex;
min-height: 100vh;
flex-direction: column;
}

.content {
flex: 1;
}
14 changes: 14 additions & 0 deletions site/src/components/layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Slice } from "gatsby";
import React from "react";
import "./layout.css"

export const Layout = ({ children }) => {
return (
<div className="page">
<div className="content">
{children}
</div>
<Slice alias="footer" />
</div >
)
}
14 changes: 7 additions & 7 deletions site/src/pages/articles.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from "react"
import { graphql, Slice } from "gatsby"
import { graphql } from "gatsby"
import { Layout } from "../components/layout";

const Articles = (props) => {
const { data } = props;
Expand Down Expand Up @@ -40,12 +41,11 @@ const Articles = (props) => {
);
});
return (
<>
<div style={{ display: "flex", flexWrap: "wrap" }}>
{articles}
</div>
<Slice alias="footer"></Slice>
</>
<Layout>
<div style={{ display: "flex", flexWrap: "wrap" }}>
{articles}
</div>
</Layout>
)
}

Expand Down
8 changes: 4 additions & 4 deletions site/src/pages/author.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from "react"
import { graphql, Slice } from "gatsby"
import { graphql } from "gatsby"
import { stringify } from "qs"
import { ImageElement, getGatsbyImageData } from "@kontent-ai/gatsby-components"
import { ImageUrlTransformationBuilder } from "@kontent-ai/delivery-sdk"
import { Layout } from "../components/layout"

const Author = ({ data }) => {
if (!data.author.elements.avatar_image.value.length) {
Expand Down Expand Up @@ -39,7 +40,7 @@ const Author = ({ data }) => {
const imageGatsbyData = getGatsbyImageData(imageData)

return (
<>
<Layout>
<header>
<h1>{data.author.elements.name.value}</h1>
</header>
Expand Down Expand Up @@ -141,8 +142,7 @@ const Author = ({ data }) => {
}

</article>
<Slice alias="footer"></Slice>
</>
</Layout>
)
}

Expand Down
36 changes: 18 additions & 18 deletions site/src/pages/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import React from "react"
import { RichTextElement } from "@kontent-ai/gatsby-components"
import { Link, Slice } from "gatsby"

const Index = () => {
return (
<>
<RichTextElement value="<div>Hello Kontent.ai!</div>" />
<ul>
<li><Link to="author">Image resolution example</Link></li>
<li><Link to="articles">Article listing example</Link></li>
</ul>
<Slice alias="footer"></Slice>
</>
)
}

export default Index;
import React from "react"
import { RichTextElement } from "@kontent-ai/gatsby-components"
import { Link } from "gatsby"
import { Layout } from "../components/layout"

const Index = () => {
return (
<Layout>
<RichTextElement value="<div>Hello Kontent.ai!</div>" />
<ul>
<li><Link to="author">Image resolution example</Link></li>
<li><Link to="articles">Article listing example</Link></li>
</ul>
</Layout>
)
}

export default Index;

0 comments on commit cfb3a5b

Please sign in to comment.