Skip to content
Snippets Groups Projects
Commit 2bebae61 authored by Tovo Ramontalambo's avatar Tovo Ramontalambo Committed by Julien MARGAIL
Browse files

Feat/sections

parent 6b8f5613
No related branches found
No related tags found
No related merge requests found
...@@ -3,5 +3,32 @@ ...@@ -3,5 +3,32 @@
* *
* See: https://www.gatsbyjs.com/docs/node-apis/ * See: https://www.gatsbyjs.com/docs/node-apis/
*/ */
const path = require("path")
exports.onPreInit = () => console.log("Loaded gatsby-theme-onegeo"); exports.onPreInit = () => console.log("Loaded gatsby-theme-onegeo")
exports.createPages = async function ({ actions, graphql }) {
const { data } = await graphql(`
query getPages {
directus {
pages(limit: 1) {
sections {
id
}
content
id
title
slug
}
}
}
`)
data.directus.pages.forEach((page) => {
actions.createPage({
path: `/${page.slug}`,
component: path.join(__dirname, "src", "templates", "Page.tsx"),
context: { ...page },
})
})
}
...@@ -224,4 +224,9 @@ interface ISection { ...@@ -224,4 +224,9 @@ interface ISection {
} }
export function Section(props: ISection): JSX.Element export function Section(props: ISection): JSX.Element
interface ISections {
ids: string[]
}
export function Sections(props: ISections): JSX.Element
declare module "@onegeo/gatsby-theme-onegeo" declare module "@onegeo/gatsby-theme-onegeo"
...@@ -46,3 +46,6 @@ export { default as Header } from "./src/components/Header" ...@@ -46,3 +46,6 @@ export { default as Header } from "./src/components/Header"
// Section components // Section components
export { default as Section } from "./src/components/Section" export { default as Section } from "./src/components/Section"
// Section components
export { default as Sections } from "./src/components/Sections"
import React from "react"
import Section from "./Section"
interface ISections {
ids: string[]
}
const Sections = (props: ISections) => {
const { ids } = props
return (
<div>
{ids.map((id) => {
return <Section key={id} id={id} />
})}
</div>
)
}
export default Sections
import React, { ReactElement } from "react" import React, { ReactElement } from "react"
import { Content,Link } from "@onegeo/gatsby-theme-onegeo" import { Content, Link } from "@onegeo/gatsby-theme-onegeo"
function index(): ReactElement { function index(): ReactElement {
return ( return (
...@@ -29,6 +29,8 @@ function index(): ReactElement { ...@@ -29,6 +29,8 @@ function index(): ReactElement {
<Link to="/doc/footer">Footer</Link> <Link to="/doc/footer">Footer</Link>
<br></br> <br></br>
<Link to="/doc/section">Section</Link> <Link to="/doc/section">Section</Link>
<br></br>
<Link to="/doc/sections">Sections</Link>
</div> </div>
</Content> </Content>
) )
......
import React, { ReactElement } from "react"
import { Link } from "gatsby"
import { Sections, Content } from "@onegeo/gatsby-theme-onegeo"
function section(): ReactElement {
return (
<Content>
<div className="prose">
<Link to="/doc">Retour</Link>
<h1>Sections</h1>
<h2>Props</h2>
<div className="mockup-code">
<pre>
<code>
{`
interface ISections {
ids: string[]
}
`}
</code>
</pre>
</div>
<h2>Example</h2>
</div>
<Sections ids={["1", "2", "3"]} />
</Content>
)
}
export default section
import React from "react"
import { PageProps } from "gatsby"
import { Sections } from "@onegeo/gatsby-theme-onegeo"
interface ISection {
id: string
}
interface IPageContext {
id: string
title: string
content: string
slug: string
sections: ISection[] | []
}
const PageTemplate = (props: PageProps<null, IPageContext>) => {
const {
pageContext: { sections, title, content },
} = props
const idsSections = sections.map((section) => section.id)
return (
<div>
{title && <h1 className="text-3xl font-extrabold">{title}</h1>}
{content && (
<div
className="text-lg leading-8 py-4 text-justify"
dangerouslySetInnerHTML={{ __html: content }}
></div>
)}
{idsSections.length > 0 && <Sections ids={idsSections} />}
</div>
)
}
export default PageTemplate
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment