Skip to content

Commit

Permalink
feat: new case study template
Browse files Browse the repository at this point in the history
  • Loading branch information
flavioriper committed Dec 1, 2023
1 parent d46c1d7 commit 733561f
Show file tree
Hide file tree
Showing 14 changed files with 515 additions and 165 deletions.
30 changes: 29 additions & 1 deletion gatsby-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,23 @@ const strapiConfig = {
"job-posting",
"product-comparison-page",
"employee",
"case-study",
{
singularName: "case-study",
queryParams: {
populate: {
Logo: {
populate: '*',
},
About: {
populate: {
Topics: {
populate: '*'
}
}
}
}
}
},
],
singleTypes: [],
// remoteFileHeaders: {
Expand Down Expand Up @@ -58,6 +74,18 @@ const rehypeSelectors = {
enableToc: false,
},
},
[`STRAPI_CASE_STUDY_SIDECONTENT_TEXTNODE`]: {
extractor: node => node.SideContent,
pluginOpts: {
enableToc: false,
},
},
[`STRAPI__COMPONENT_CASE_STUDY_CASE_STUDY_ABOUT_DESCRIPTION_TEXTNODE`]: {
extractor: node => node.Description,
pluginOpts: {
enableToc: false,
},
},
}

/**
Expand Down
2 changes: 1 addition & 1 deletion gatsby-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const { createFilePath } = require(`gatsby-source-filesystem`)
const blogPost = path.resolve(`./src/templates/blog-post.tsx`)
const blog = path.resolve(`./src/templates/blog.tsx`)
const comparisonTemplate = path.resolve(`./src/templates/product-comparison.tsx`)
const caseStudyTemplate = path.resolve(`./src/templates/CaseStudy/index.tsx`)
const caseStudyTemplate = path.resolve(`./src/layouts/CaseStudy/index.tsx`)

const connector = path.resolve(`./src/templates/connector.tsx`)
const connection = path.resolve(`./src/templates/connection.tsx`)
Expand Down
File renamed without changes.
File renamed without changes.
38 changes: 38 additions & 0 deletions src/layouts/CaseStudy/Sections/About.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React from "react"

import { ProcessedPost } from '../../../components/BlogPostProcessor'
import { GatsbyImage } from "gatsby-plugin-image"

const Topic = ({ Title, Description, Icon }) => {
return (
<div className="topic">
<div className="icon">
<GatsbyImage
alt={Title}
image={Icon.localFile.childImageSharp.gatsbyImageData}
loading="lazy"
/>
</div>
<div className="content">
<p className="title">{Title}</p>
<p className="description">{Description}</p>
</div>
</div>
)
}

const CaseStudyAbout = ({ Title, Description, Topics }) => {
return (
<div className="about">
<p className="title">{Title}</p>
<div className="topics">
{Topics.map((topic, index) => <Topic key={index} {...topic} />)}
</div>
<div className="description">
<ProcessedPost body={Description.data.childHtmlRehype.html} />
</div>
</div>
)
}

export default CaseStudyAbout
13 changes: 13 additions & 0 deletions src/layouts/CaseStudy/Sections/Body.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from "react"

import { ProcessedPost } from '../../../components/BlogPostProcessor'

const CaseStudyBody = ({ content }) => {
return (
<div className="body">
<ProcessedPost body={content.data.childHtmlRehype.html} />
</div>
)
}

export default CaseStudyBody
13 changes: 13 additions & 0 deletions src/layouts/CaseStudy/Sections/Content.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from "react"

import { ProcessedPost } from '../../../components/BlogPostProcessor'

const CaseStudyContent = ({ content }) => {
return (
<div className="side-content">
<ProcessedPost body={content.data.childHtmlRehype.html} />
</div>
)
}

export default CaseStudyContent
22 changes: 22 additions & 0 deletions src/layouts/CaseStudy/Sections/Hero.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from "react"
import { GatsbyImage } from "gatsby-plugin-image"

const CaseStudyHero = ({ title, description, image }) => {
return (
<header className="above-the-fold">
<div className="content">
<h2>{title}</h2>
<h1>{description}</h1>
</div>
<div className="logo">
<GatsbyImage
alt={title}
image={image}
loading="eager"
/>
</div>
</header>
)
}

export default CaseStudyHero
19 changes: 19 additions & 0 deletions src/layouts/CaseStudy/Wrapper/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from "react"

import Layout from "../../../components/layout"

const CaseStudyWrapper = ({ children }) => {
return (
<Layout headerTheme="light">
<article
className="case-study"
itemScope
itemType="http://schema.org/Article"
>
{children}
</article>
</Layout>
)
}

export default CaseStudyWrapper
111 changes: 111 additions & 0 deletions src/layouts/CaseStudy/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import './style.less'

import React from "react"
import { graphql } from "gatsby"

import dayjs from "dayjs"
import reltime from "dayjs/plugin/relativeTime"

import Header from './Head'
import Wrapper from './Wrapper'

import SectionHero from './Sections/Hero'
import SectionContent from './Sections/Content'
import SectionAbout from './Sections/About'
import SectionBody from './Sections/Body'

dayjs.extend(reltime)

const CaseStudyTemplate = ({ data: { caseStudy, relatedStudies } }) => {
const { Title, Description, Logo, SideContent, About, Body } = caseStudy

return (
<Wrapper>
<SectionHero title={Title} description={Description} image={Logo.localFile.childImageSharp.gatsbyImageData} />
<div className="two-columns">
<SectionContent content={SideContent} />
<SectionAbout {...About} />
</div>
<SectionBody content={Body} />
</Wrapper>
)
}

export default CaseStudyTemplate

export const Head = Header

export const pageQuery = graphql`
query CaseStudyQueryById($id: String!) {
site {
siteMetadata {
siteUrl
}
}
caseStudy: strapiCaseStudy(id: { eq: $id }) {
machineReadablePublishDate: publishedAt(formatString: "YYYY-MM-DD")
Slug
Title
Description
Logo {
localFile {
childImageSharp {
gatsbyImageData(
layout: FULL_WIDTH
placeholder: BLURRED
formats: [AUTO, WEBP, AVIF]
)
meta_img: fixed(width: 500) {
src
}
}
}
}
SideContent {
data {
SideContent
childHtmlRehype {
html
tableOfContents
}
}
}
About {
Title
Description {
data {
Description
childHtmlRehype {
html
tableOfContents
}
}
}
Topics {
Title
Description
Icon {
localFile {
childImageSharp {
gatsbyImageData(
layout: FULL_WIDTH
placeholder: BLURRED
formats: [AUTO, WEBP, AVIF]
)
}
}
}
}
}
Body {
data {
Body
childHtmlRehype {
html
tableOfContents
}
}
}
}
}
`
Loading

0 comments on commit 733561f

Please sign in to comment.