Skip to content

Commit

Permalink
+Add support for multiple About sections
Browse files Browse the repository at this point in the history
including  documentation update
Fix konstantinmuenster#21
  • Loading branch information
diiigle committed Oct 30, 2023
1 parent 0957a49 commit 19d24af
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 25 deletions.
4 changes: 2 additions & 2 deletions gatsby-theme-portfolio-minimal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ Most section components work the following way: You import and configure the com
The following table shows which section components are available and how they can be configured.
| Section Component | Available Props | Associated Content File |
|--------------------|-----------------------------------------------------------------------------------------------------------|-------------------------------------------------------|
| `AboutSection` | `sectionId` _(required)_ <br/> `heading` _(optional)_ | `*contentRootDir*/sections/about/*yourFile*.md` |
| ------------------ | --------------------------------------------------------------------------------------------------------- | ----------------------------------------------------- |
| `AboutSection` | `sectionId` _(required)_ <br/> `heading` _(optional)_ <br/> `fileName` _(optional, default: "about")_ | `*contentRootDir*/sections/about/*fileName*.md` |
| `ContactSection` | `sectionId` _(required)_ <br/> `heading` _(optional)_ | `*contentRootDir*/sections/contact/*yourFile*.json` |
| `HeroSection` | `sectionId` _(required)_ | `*contentRootDir*/sections/hero/*yourFile*.json` |
| `InterestsSection` | `sectionId` _(required)_ <br/> `heading` _(optional)_ <br/> `fileName` _(optional, default: "interests")_ | `*contentRootDir*/sections/interests/*fileName*.json` |
Expand Down
48 changes: 30 additions & 18 deletions gatsby-theme-portfolio-minimal/src/sections/About/data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,47 @@ import { graphql, useStaticQuery } from 'gatsby';
import { IGatsbyImageData } from 'gatsby-plugin-image';

interface AboutSectionQueryResult {
allAboutMarkdown: {
sections: {
frontmatter: {
imageAlt?: string;
imageSrc?: {
childImageSharp: {
gatsbyImageData: IGatsbyImageData;
allFile: {
aboutFiles: {
name: string;
relativePath: string;
section: {
frontmatter: {
imageAlt?: string;
imageSrc?: {
childImageSharp: {
gatsbyImageData: IGatsbyImageData;
};
};
};
};
html: string;
html: string;
}[];
}[];
};
}

export const useLocalDataSource = (): AboutSectionQueryResult => {
return useStaticQuery(graphql`
query AboutSectionQuery {
allAboutMarkdown: allMarkdownRemark(filter: { fileAbsolutePath: { regex: "/sections/about/" } }) {
sections: nodes {
frontmatter {
imageAlt
imageSrc {
childImageSharp {
gatsbyImageData(width: 400)
query AboutByFilename {
allFile(
filter: { childMarkdownRemark: { id: { ne: null } }, relativePath: { regex: "/sections/about/" } }
) {
aboutFiles: nodes {
name
relativePath
section: children {
... on MarkdownRemark {
frontmatter {
imageAlt
imageSrc {
childImageSharp {
gatsbyImageData(width: 400)
}
}
}
html
}
}
html
}
}
}
Expand Down
15 changes: 10 additions & 5 deletions gatsby-theme-portfolio-minimal/src/sections/About/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,25 @@ import * as classes from './style.module.css';

export function AboutSection(props: PageSection): React.ReactElement {
const response = useLocalDataSource();
const data = response.allAboutMarkdown.sections[0];
const allFiles = response.allFile.aboutFiles;
const fileNameNeedle = props.fileName ? props.fileName : 'about';
const result = allFiles.find((file) => {
return file.name == fileNameNeedle;
});
const section = result ? result.section[0] : allFiles[0].section[0];

return (
<Animation type="fadeUp">
<Section anchor={props.sectionId} heading={props.heading}>
<div className={classes.About}>
<div className={classes.Description} dangerouslySetInnerHTML={{ __html: data.html }} />
{data.frontmatter.imageSrc && (
<div className={classes.Description} dangerouslySetInnerHTML={{ __html: section.html }} />
{section.frontmatter.imageSrc && (
<Animation type="fadeLeft" delay={200}>
<div className={classes.ImageWrapper}>
<GatsbyImage
image={data.frontmatter.imageSrc.childImageSharp.gatsbyImageData}
image={section.frontmatter.imageSrc.childImageSharp.gatsbyImageData}
className={classes.Image}
alt={data.frontmatter.imageAlt || `About Image`}
alt={section.frontmatter.imageAlt || `About Image`}
/>
</div>
</Animation>
Expand Down

0 comments on commit 19d24af

Please sign in to comment.