Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add project images #15

Merged
merged 6 commits into from
Dec 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/components/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const StyledHeader = styled.header`
padding: 1rem;
position: -webkit-sticky; /* Safari */
position: sticky;
z-index: 1;
top: 0;
width: 100vw;
.left,
Expand Down
1 change: 1 addition & 0 deletions src/components/LayoutAlt.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const StyledHeader = styled.header`
padding: 1rem;
position: -webkit-sticky; /* Safari */
position: sticky;
z-index: 1;
top: 0;
/* width: 100vw; */
display: flex;
Expand Down
6 changes: 4 additions & 2 deletions src/styles/global.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
$primary: #00ffaa;
$background: #9595959b;

body {
display: flex;
width: 100vw;
Expand All @@ -14,11 +17,10 @@ body {
}
a {
text-decoration: none;
color: $primary;
}
}

$primary: #00ffaa;
$background: #9595959b;
/* Works on Firefox */
* {
scrollbar-width: thin;
Expand Down
88 changes: 53 additions & 35 deletions src/styles/project.module.scss
Original file line number Diff line number Diff line change
@@ -1,50 +1,68 @@
main {
padding: 0 1rem;
.backgroundImage {
position: absolute;
margin-left: auto;
margin-right: auto;
top: 0;
width: 100vw;
z-index: -1;
}
section.title {
width: 100%;
display: flex;
text-align: left;
justify-content: flex-start;
align-items: flex-start;
margin-bottom: 2rem;
}
}

article.content {
display: flex;
flex-direction: column;
justify-content: center;
max-width: 800px;
padding: 5px;
text-align: left;

section.heroImageSection {
justify-content: center;
text-align: center;
.heroImage {
display: block;
}
}
section.heroVideoSection {
article.content {
display: flex;
flex-direction: column;
justify-content: center;
text-align: center;
position: relative;
padding-bottom: 56.25%;
padding-top: 35px;
height: 0;
overflow: hidden;
iframe.heroVideo {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
max-width: 800px;
padding: 5px;
text-align: left;

section.heroImageSection {
justify-content: center;
text-align: center;
margin-bottom: 1rem;
.heroImage {
display: block;
}
}
section.heroVideoSection {
display: flex;
justify-content: center;
text-align: center;
position: relative;
padding-bottom: 56.25%;
padding-top: 35px;
height: 0;
overflow: hidden;
iframe.heroVideo {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
}
section.body {
// min-height: 65vh;
padding: 5px 7rem;
// background-color: lightyellow;
}
section.linkedAssets {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
.asset {
margin: 0.5rem 0;
}
}
}
section.body {
min-height: 65vh;
padding: 5px 7rem;
// background-color: lightyellow;
}
}

Expand Down
61 changes: 52 additions & 9 deletions src/templates/project.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @jsx jsx */
import { jsx, Heading, Text } from 'theme-ui'
import { jsx, Heading, Text, useColorMode } from 'theme-ui'
import { graphql } from 'gatsby'
import { BLOCKS, MARKS } from '@contentful/rich-text-types'
import { renderRichText } from 'gatsby-source-contentful/rich-text'
Expand All @@ -14,9 +14,17 @@ export const query = graphql`
query MyQuery($slug: String!) {
contentfulProject(slug: { eq: $slug }) {
title
theme
body {
raw
}
backgroundImage {
gatsbyImageData(
formats: AUTO
layout: CONSTRAINED
placeholder: BLURRED
)
}
heroImage {
gatsbyImageData(
formats: AUTO
Expand All @@ -25,6 +33,14 @@ export const query = graphql`
)
}
heroVideo
mediaAssets {
description
gatsbyImageData(
formats: AUTO
layout: CONSTRAINED
placeholder: BLURRED
)
}
}
}
`
Expand All @@ -33,7 +49,8 @@ const Project = (props) => {
const bodyRichText = props.data.contentfulProject.body
const heroImage = props.data.contentfulProject.heroImage
const heroVideo = props.data.contentfulProject.heroVideo
const backgroundImage = props.data.contentfulProject.heroImage // change to backgroundImage
const backgroundImage = props.data.contentfulProject.backgroundImage
const linkedAssets = props.data.contentfulProject.mediaAssets

const Bold = ({ children }) => <b>{children}</b>

Expand All @@ -43,27 +60,40 @@ const Project = (props) => {
[BLOCKS.HEADING_1]: (node, children) => (
<Heading as="h1">{children}</Heading>
),
[BLOCKS.EMBEDDED_ASSET]: (node) => {
if (node) {
console.log(node.data)
}
// return (
// <GatsbyImage image={getImage(gatsbyImageData)} alt={description} />
// )
},
},
renderMark: {
[MARKS.BOLD]: (text) => <Bold>{text}</Bold>,
},
}

const [colorMode, setColorMode] = useColorMode()
const theme = props.data.contentfulProject.theme
if (theme) {
setColorMode(theme.toLowerCase())
}

return (
<LayoutAlt>
<Seo title={projTitle} />
{backgroundImage && (
<GatsbyImage
className={styles.backgroundImage}
image={getImage(backgroundImage)}
/>
)}
<section className={styles.title}>
<Heading as="h1" variant="styles.H1">
{projTitle}
</Heading>
</section>
{backgroundImage && (
// use gatsby-background-image plugin
<section
className={styles.backgroundImage}
style={{ backgroundImage: `url(${backgroundImage})` }}
/>
)}
<article className={styles.content}>
{heroImage && (
<section className={styles.heroImageSection}>
Expand Down Expand Up @@ -92,6 +122,19 @@ const Project = (props) => {
<section className={styles.body}>
{bodyRichText && renderRichText(bodyRichText, options)}
</section>
{linkedAssets && (
<section className={styles.linkedAssets}>
{linkedAssets.map((asset) => {
return (
<GatsbyImage
className={styles.asset}
image={getImage(asset)}
alt={asset.description}
/>
)
})}
</section>
)}
</article>
</LayoutAlt>
)
Expand Down