Add gallery to gatsby index

This commit is contained in:
2021-05-30 23:02:32 -07:00
parent b3fd881c6e
commit 46419a1559
13 changed files with 699 additions and 139 deletions

View File

@@ -1,82 +1,9 @@
import * as React from "react"
import { graphql } from 'gatsby'
import { GatsbyImage, getImage } from "gatsby-plugin-image"
// styles
const pageStyles = {
color: "#232129",
padding: 96,
fontFamily: "-apple-system, Roboto, sans-serif, serif",
}
const headingStyles = {
marginTop: 0,
marginBottom: 64,
maxWidth: 320,
}
const headingAccentStyles = {
color: "#663399",
}
const paragraphStyles = {
marginBottom: 48,
}
const codeStyles = {
color: "#8A6534",
padding: 4,
backgroundColor: "#FFF4DB",
fontSize: "1.25rem",
borderRadius: 4,
}
const listStyles = {
marginBottom: 96,
paddingLeft: 0,
}
const listItemStyles = {
fontWeight: 300,
fontSize: 24,
maxWidth: 560,
marginBottom: 30,
}
const linkStyle = {
color: "#8954A8",
fontWeight: "bold",
fontSize: 16,
verticalAlign: "5%",
}
const docLinkStyle = {
...linkStyle,
listStyleType: "none",
marginBottom: 24,
}
const descriptionStyle = {
color: "#232129",
fontSize: 14,
marginTop: 10,
marginBottom: 0,
lineHeight: 1.25,
}
const docLink = {
text: "Documentation",
url: "https://www.gatsbyjs.com/docs/",
color: "#8954A8",
}
const badgeStyle = {
color: "#fff",
backgroundColor: "#088413",
border: "1px solid #088413",
fontSize: 11,
fontWeight: "bold",
letterSpacing: 1,
borderRadius: 4,
padding: "4px 6px",
display: "inline-block",
position: "relative",
top: -2,
marginLeft: 10,
lineHeight: 1,
}
import "../styles/gallery.scss"
import "../styles/index.scss"
// data
const links = [
@@ -126,53 +53,30 @@ const links = [
]
// markup
const IndexPage = () => {
const IndexPage = ({ data }) => {
const images = React.useMemo(() => data.allFile.edges.map(edge => edge.node, [data]))
console.log('images', images)
return (
<main style={pageStyles}>
<main >
<title>Home Page</title>
<h1 style={headingStyles}>
<h1 >
Congratulations
<br />
<span style={headingAccentStyles}> you just made a Gatsby site! </span>
<span > you just made a Gatsby site! </span>
<span role="img" aria-label="Party popper emojis">
🎉🎉🎉
</span>
</h1>
<p style={paragraphStyles}>
Edit <code style={codeStyles}>src/pages/index.js</code> to see this page
update in real-time.{" "}
<span role="img" aria-label="Sunglasses smiley emoji">
😎
</span>
</p>
<ul style={listStyles}>
<li style={docLinkStyle}>
<a
style={linkStyle}
href={`${docLink.url}?utm_source=starter&utm_medium=start-page&utm_campaign=minimal-starter`}
>
{docLink.text}
</a>
</li>
{links.map(link => (
<li key={link.url} style={{ ...listItemStyles, color: link.color }}>
<span>
<a
style={linkStyle}
href={`${link.url}?utm_source=starter&utm_medium=start-page&utm_campaign=minimal-starter`}
>
{link.text}
</a>
{link.badge && (
<span style={badgeStyle} aria-label="New Badge">
NEW!
</span>
)}
<p style={descriptionStyle}>{link.description}</p>
</span>
</li>
))}
</ul>
<div className="gallery">
{images.map(image => {
console.log('imag', image)
// const file = data.allFile
// console.log(fileName)
// return <></>
return <GatsbyImage key={image.base} image={getImage(image)} alt={image.base} />;
})}
</div>
<img
alt="Gatsby G Logo"
src="data:image/svg+xml,%3Csvg width='24' height='24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M12 2a10 10 0 110 20 10 10 0 010-20zm0 2c-3.73 0-6.86 2.55-7.75 6L14 19.75c3.45-.89 6-4.02 6-7.75h-5.25v1.5h3.45a6.37 6.37 0 01-3.89 4.44L6.06 9.69C7 7.31 9.3 5.63 12 5.63c2.13 0 4 1.04 5.18 2.65l1.23-1.06A7.959 7.959 0 0012 4zm-8 8a8 8 0 008 8c.04 0 .09 0-8-8z' fill='%23639'/%3E%3C/svg%3E"
@@ -181,4 +85,20 @@ const IndexPage = () => {
)
}
export const query = graphql`
query HomePageGallery {
allFile(filter: {
sourceInstanceName: { eq: "gallery" }}) {
edges {
node {
relativePath,
base,
childImageSharp{
gatsbyImageData(width: 400)
}
}
}
}
}`;
export default IndexPage

View File

@@ -0,0 +1,29 @@
.gallery {
width: 100%;
aspect-ratio: 5/3;
background: black;
display: flex;
overflow-x: scroll;
scroll-snap-type: x mandatory;
padding: 2em 0;
scroll-padding: 3em;
// &::before {
// content: ".";
// background: linear-gradient(-90deg, rgba(0, 0, 0, 0) 10%, rgba(0, 0, 04, 1) 100%);
// display: block;
// width: 120px;
// position: absolute;
// top: 0;
// left: 0;
// height: 100%;
// }
.gatsby-image-wrapper {
aspect-ratio: 3/2;
flex-shrink: 0;
// height: 280px;
// width: 350px;
scroll-snap-align: start;
margin-left: 2em;
}
}

View File

@@ -0,0 +1,3 @@
* {
box-sizing: border-box;
}