sort gallery by Vibrant hue
This commit is contained in:
parent
479d3d661e
commit
82419df7b1
@ -4,7 +4,7 @@ const chroma = require("chroma-js");
|
|||||||
const chalk = require("chalk");
|
const chalk = require("chalk");
|
||||||
const R = require("ramda");
|
const R = require("ramda");
|
||||||
const exifr = require("exifr");
|
const exifr = require("exifr");
|
||||||
const sharp = require('sharp');
|
const sharp = require("sharp");
|
||||||
|
|
||||||
const badContrast = (color1, color2) => chroma.contrast(color1, color2) < 4.5;
|
const badContrast = (color1, color2) => chroma.contrast(color1, color2) < 4.5;
|
||||||
|
|
||||||
@ -102,11 +102,13 @@ function processColors(vibrantData, imagePath) {
|
|||||||
|
|
||||||
function transformMetaToNodeData(metaData, vibrantData, imagePath) {
|
function transformMetaToNodeData(metaData, vibrantData, imagePath) {
|
||||||
const vibrant = vibrantData ? processColors(vibrantData, imagePath) : null;
|
const vibrant = vibrantData ? processColors(vibrantData, imagePath) : null;
|
||||||
|
let dominantHue = vibrantData.Vibrant.getHsl()[0] * 360;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
dateTaken: metaData.DateTimeOriginal,
|
dateTaken: metaData.DateTimeOriginal,
|
||||||
meta: metaData,
|
meta: metaData,
|
||||||
vibrant,
|
vibrant,
|
||||||
|
dominantHue,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,13 +120,15 @@ exports.onCreateNode = async function ({ node, actions }) {
|
|||||||
xmp: true,
|
xmp: true,
|
||||||
// icc: true
|
// icc: true
|
||||||
});
|
});
|
||||||
|
|
||||||
const resizedImage = await sharp(node.absolutePath)
|
const resizedImage = await sharp(node.absolutePath)
|
||||||
.resize({
|
.resize({
|
||||||
width: 3000,
|
width: 3000,
|
||||||
height: 3000,
|
height: 3000,
|
||||||
fit: 'inside'
|
fit: "inside",
|
||||||
})
|
})
|
||||||
.toBuffer()
|
.toBuffer();
|
||||||
|
|
||||||
const vibrantData = await Vibrant.from(resizedImage)
|
const vibrantData = await Vibrant.from(resizedImage)
|
||||||
.quality(1)
|
.quality(1)
|
||||||
.getPalette();
|
.getPalette();
|
||||||
@ -132,7 +136,11 @@ exports.onCreateNode = async function ({ node, actions }) {
|
|||||||
createNodeField({
|
createNodeField({
|
||||||
node,
|
node,
|
||||||
name: "imageMeta",
|
name: "imageMeta",
|
||||||
value: transformMetaToNodeData(metaData, vibrantData, node.absolutePath),
|
value: transformMetaToNodeData(
|
||||||
|
metaData,
|
||||||
|
vibrantData,
|
||||||
|
node.absolutePath
|
||||||
|
),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -145,7 +145,7 @@ const GalleryImage = ({ data, pageContext }) => {
|
|||||||
<GatsbyImage
|
<GatsbyImage
|
||||||
alt={name}
|
alt={name}
|
||||||
className={classnames(
|
className={classnames(
|
||||||
"border-4 border-muted-light",
|
"border-4 border-vibrant",
|
||||||
zoom ? "cursor-zoom-out" : "cursor-zoom-in"
|
zoom ? "cursor-zoom-out" : "cursor-zoom-in"
|
||||||
)}
|
)}
|
||||||
image={getImage(image)}
|
image={getImage(image)}
|
||||||
|
@ -17,7 +17,6 @@ const MasonryGallery = ({
|
|||||||
);
|
);
|
||||||
|
|
||||||
const { breakpoint } = useBreakpoint(breakpoints, "sm");
|
const { breakpoint } = useBreakpoint(breakpoints, "sm");
|
||||||
console.log("🚀 ~ file: MasonryGallery.js ~ line 20 ~ breakpoint", breakpoint)
|
|
||||||
|
|
||||||
const scrollIntoView = React.useCallback(() => {
|
const scrollIntoView = React.useCallback(() => {
|
||||||
if (!window.location.hash) {
|
if (!window.location.hash) {
|
||||||
@ -34,7 +33,7 @@ const MasonryGallery = ({
|
|||||||
// hacky but it works for now
|
// hacky but it works for now
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
scrollIntoView();
|
scrollIntoView();
|
||||||
}, 100)
|
}, 100);
|
||||||
}, [scrollIntoView]);
|
}, [scrollIntoView]);
|
||||||
|
|
||||||
const aspectRatios = React.useMemo(
|
const aspectRatios = React.useMemo(
|
||||||
|
@ -45,10 +45,10 @@ const GalleryPage = ({ data }) => {
|
|||||||
<div className="mx-auto">
|
<div className="mx-auto">
|
||||||
<MasonryGallery
|
<MasonryGallery
|
||||||
aspectsByBreakpoint={{
|
aspectsByBreakpoint={{
|
||||||
sm: 3.6,
|
sm: 3,
|
||||||
md: 4,
|
md: 4,
|
||||||
lg: 5,
|
lg: 4,
|
||||||
xl: 6.1,
|
xl: 5,
|
||||||
}}
|
}}
|
||||||
images={images}
|
images={images}
|
||||||
/>
|
/>
|
||||||
@ -62,7 +62,7 @@ export const query = graphql`
|
|||||||
query GalleryPageQuery {
|
query GalleryPageQuery {
|
||||||
allFile(
|
allFile(
|
||||||
filter: { sourceInstanceName: { eq: "gallery" } }
|
filter: { sourceInstanceName: { eq: "gallery" } }
|
||||||
sort: { order: DESC, fields: fields___imageMeta___dateTaken }
|
sort: { fields: fields___imageMeta___dominantHue, order: DESC }
|
||||||
) {
|
) {
|
||||||
edges {
|
edges {
|
||||||
node {
|
node {
|
||||||
@ -72,10 +72,15 @@ export const query = graphql`
|
|||||||
fluid {
|
fluid {
|
||||||
aspectRatio
|
aspectRatio
|
||||||
}
|
}
|
||||||
gatsbyImageData(layout: CONSTRAINED, height: 550)
|
gatsbyImageData(
|
||||||
|
layout: CONSTRAINED
|
||||||
|
height: 550
|
||||||
|
placeholder: DOMINANT_COLOR
|
||||||
|
)
|
||||||
}
|
}
|
||||||
fields {
|
fields {
|
||||||
imageMeta {
|
imageMeta {
|
||||||
|
dominantHue
|
||||||
dateTaken
|
dateTaken
|
||||||
meta {
|
meta {
|
||||||
ObjectName
|
ObjectName
|
||||||
|
Loading…
x
Reference in New Issue
Block a user