Skip to content

Commit

Permalink
+Add support for multiple Projects sections
Browse files Browse the repository at this point in the history
including  documentation update
Fix konstantinmuenster#21
  • Loading branch information
diiigle committed Oct 26, 2023
1 parent 612358e commit 4211f14
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 46 deletions.
26 changes: 26 additions & 0 deletions example-site/content/sections/projects/more_projects.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"projects": [
{
"visible": true,
"category": "🧰 EXTENDABLE LAYOUT",
"title": "Multiple Project sections!",
"description": "You can now use more than one projects/*.json file to define separate Projects sections. Photo by Kelly Sikkema on Unsplash.",
"tags": ["Custom Sections", "Easy-2-Use"],
"image": {
"src": "../../images/kelly-sikkema-Hl3LUdyKRic-unsplash.jpg",
"alt": "Extendable Layout"
},
"links": [
{
"type": "github",
"url": "https://github.com/konstantinmuenster/gatsby-starter-portfolio-minimal-theme"
}
]
}
],
"button": {
"visible": true,
"label": "Test it now",
"url": "https://github.com/konstantinmuenster/gatsby-theme-portfolio-minimal"
}
}
1 change: 1 addition & 0 deletions example-site/src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default function IndexPage() {
<AboutSection sectionId="about" heading="About Portfolio Minimal" />
<InterestsSection sectionId="details" heading="Details" />
<ProjectsSection sectionId="features" heading="Built-in Features" />
<ProjectsSection sectionId="more-features" heading="Advanced Features" fileName="more_projects"/>
<ContactSection sectionId="github" heading="Issues?" />
</Page>
</>
Expand Down
17 changes: 9 additions & 8 deletions gatsby-theme-portfolio-minimal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ content
│ └── imprint.md # has to be Markdown
│ └── projects
│ └── projects.json # has to be JSON
| └── more_projects.json # has to be JSON
```
#### `settings.json` File
Expand Down Expand Up @@ -270,14 +271,14 @@ 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` |
| `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)_ | `*contentRootDir*/sections/interests/*yourFile*.json` |
| `LegalSection` | `sectionId` _(required)_ <br/> `heading` _(optional)_ | `*contentRootDir*/sections/legal/*yourFile*.md` |
| `ProjectsSection` | `sectionId` _(required)_ <br/> `heading` _(optional)_ | `*contentRootDir*/sections/projects/*yourFile*.json` |
| Section Component | Available Props | Associated Content File |
|--------------------|----------------------------------------------------------------------------------------------------------|-------------------------------------------------------|
| `AboutSection` | `sectionId` _(required)_ <br/> `heading` _(optional)_ | `*contentRootDir*/sections/about/*yourFile*.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)_ | `*contentRootDir*/sections/interests/*yourFile*.json` |
| `LegalSection` | `sectionId` _(required)_ <br/> `heading` _(optional)_ | `*contentRootDir*/sections/legal/*yourFile*.md` |
| `ProjectsSection` | `sectionId` _(required)_ <br/> `heading` _(optional)_ <br/> `fileName` _(optional, default: "projects")_ | `*contentRootDir*/sections/projects/*fileName*.json` |
#### Utility Components
Expand Down
76 changes: 43 additions & 33 deletions gatsby-theme-portfolio-minimal/src/sections/Projects/data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,61 @@ import { graphql, useStaticQuery } from 'gatsby';
import { Project } from '../../components/Project';

interface ProjectsSectionQueryResult {
allProjectsJson: {
sections: {
button: {
label: string;
url: string;
visible: boolean;
};
projects: Project[];
allFile: {
projectFiles: {
name: string;
relativePath: string;
section: {
button: {
label: string;
url: string;
visible: boolean;
};
projects: Project[];
}[];
}[];
};
}

export const useLocalDataSource = (): ProjectsSectionQueryResult => {
return useStaticQuery(graphql`
query ProjectsSectionQuery {
allProjectsJson {
sections: nodes {
button {
label
url
visible
}
projects {
category
description
image {
alt
linkTo
src {
childImageSharp {
gatsbyImageData(width: 400)
query ProjectsByFilename {
allFile(filter: {childProjectsJson: {id: {ne: null}}}) {
projectFiles: nodes {
name
relativePath
section: children {
... on ProjectsJson {
button {
label
url
visible
}
projects {
category
description
image {
alt
linkTo
src {
childImageSharp {
gatsbyImageData(width: 400)
}
}
objectFit
}
objectFit
}
links {
type
url
links {
type
url
}
tags
title
visible
}
tags
title
visible
}
}
}
}
}
`);
};
13 changes: 8 additions & 5 deletions gatsby-theme-portfolio-minimal/src/sections/Projects/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,26 @@ import * as classes from './style.module.css';

export function ProjectsSection(props: PageSection): React.ReactElement {
const response = useLocalDataSource();
const data = response.allProjectsJson.sections[0];
const allFiles = response.allFile.projectFiles;
const fileNameNeedle = props.fileName ? props.fileName : "projects";
const result = allFiles.find((file) => { return file.name == fileNameNeedle;});
const section = result ? result.section[0] : allFiles[0].section[0];

return (
<Animation type="fadeIn">
<Section anchor={props.sectionId} heading={props.heading}>
<Slider additionalClasses={[classes.Projects]}>
{data.projects.map((project, key) => {
{section.projects.map((project, key) => {
return project.visible ? <Project key={key} index={key} data={project} /> : null;
})}
</Slider>
{data.button !== undefined && data.button.visible !== false && (
{section.button !== undefined && section.button.visible !== false && (
<Animation className={classes.MoreProjects} type="fadeIn">
<Button
type={ButtonType.LINK}
externalLink={true}
url={data.button.url}
label={data.button.label}
url={section.button.url}
label={section.button.label}
/>
</Animation>
)}
Expand Down
1 change: 1 addition & 0 deletions gatsby-theme-portfolio-minimal/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface ImageObject {
interface PageSection {
sectionId: string;
heading?: string;
fileName?: string;
}

interface GatsbyNodeHelpers {
Expand Down

0 comments on commit 4211f14

Please sign in to comment.