Merge branch 'move-imageMeta-fields'

This commit is contained in:
Chuck Dries 2021-07-11 21:24:01 -07:00
commit 4473d1a331
8 changed files with 773 additions and 636 deletions

View File

@ -98,7 +98,7 @@ function transformMetaToNodeData(exifData, iptcData, vibrantData, imagePath) {
} }
} }
const vibrant = processColors(vibrantData, imagePath); const vibrant = vibrantData ? processColors(vibrantData, imagePath) : null;
return { return {
@ -111,22 +111,20 @@ function transformMetaToNodeData(exifData, iptcData, vibrantData, imagePath) {
} }
exports.onCreateNode = async function ({ node, getNode, actions }) { exports.onCreateNode = async function ({ node, actions }) {
const { createNodeField } = actions; const { createNodeField } = actions;
if (node.internal.type === 'ImageSharp') { if (node.internal.type === 'File' && node.sourceInstanceName === 'gallery') {
const parent = getNode(node.parent); const file = await readFile(node.absolutePath);
const file = await readFile(parent.absolutePath);
const iptcData = iptc(file); const iptcData = iptc(file);
const exifData = await read(parent.absolutePath); const exifData = await read(node.absolutePath);
const vibrantData = await Vibrant.from(parent.absolutePath) const vibrantData = await Vibrant.from(node.absolutePath)
.quality(2) .quality(3)
.getPalette(); .getPalette();
createNodeField({ createNodeField({
node, node,
name: 'imageMeta', name: 'imageMeta',
value: transformMetaToNodeData(exifData, iptcData, vibrantData, parent.absolutePath), value: transformMetaToNodeData(exifData, iptcData, vibrantData, node.absolutePath),
}); });
} }
}; };
@ -145,11 +143,9 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
node { node {
relativePath, relativePath,
base, base,
childImageSharp { fields {
fields { imageMeta {
imageMeta { dateTaken
dateTaken
}
} }
} }
} }
@ -168,7 +164,7 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
// new Date(R.path(['node', 'childImageSharp', 'fields', 'imageMeta', 'dateTaken'], a)).getTime() - new Date(R.path(['node', 'childImageSharp', 'fields', 'imageMeta', 'dateTaken'],b)).getTime(); // new Date(R.path(['node', 'childImageSharp', 'fields', 'imageMeta', 'dateTaken'], a)).getTime() - new Date(R.path(['node', 'childImageSharp', 'fields', 'imageMeta', 'dateTaken'],b)).getTime();
const edges = R.sort(R.descend((edge) => const edges = R.sort(R.descend((edge) =>
new Date(R.path(['node', 'childImageSharp', 'fields', 'imageMeta', 'dateTaken'], edge))), new Date(R.path(['node', 'fields', 'imageMeta', 'dateTaken'], edge))),
galleryImages.data.allFile.edges); galleryImages.data.allFile.edges);
edges.forEach(({ node }, index) => { edges.forEach(({ node }, index) => {
@ -178,8 +174,7 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
const prevImage = index === 0 const prevImage = index === 0
? null ? null
: edges[index - 1].node.base; : edges[index - 1].node.base;
const page = {
createPage({
path: `photogallery/${node.base}`, path: `photogallery/${node.base}`,
component: galleryImageTemplate, component: galleryImageTemplate,
context: { context: {
@ -187,6 +182,7 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
nextImage, nextImage,
prevImage, prevImage,
}, },
}); };
createPage(page);
}); });
}; };

View File

@ -68,7 +68,6 @@ const GalleryImage = ({ data, pageContext }) => {
const vibrant = getVibrant(image, true); const vibrant = getVibrant(image, true);
const orientationClasses = ar > 1 ? 'flex-col mx-auto' : 'portrait:mx-auto landscape:mx-5 landscape:flex-row-reverse portrait:flex-col'; const orientationClasses = ar > 1 ? 'flex-col mx-auto' : 'portrait:mx-auto landscape:mx-5 landscape:flex-row-reverse portrait:flex-col';
console.log(ar, orientationClasses);
const shutterSpeed = React.useMemo(() => getShutterFractionFromExposureTime(meta.exif.ExposureTime || 0), [meta]); const shutterSpeed = React.useMemo(() => getShutterFractionFromExposureTime(meta.exif.ExposureTime || 0), [meta]);
const dateTaken = React.useMemo(() => new Date(meta.dateTaken), [meta]); const dateTaken = React.useMemo(() => new Date(meta.dateTaken), [meta]);
return (<> return (<>
@ -158,24 +157,24 @@ export const query = graphql`
# placeholder: TRACED_SVG # placeholder: TRACED_SVG
height: 2160 height: 2160
) )
fields { }
imageMeta { fields {
dateTaken imageMeta {
iptc { dateTaken
caption iptc {
object_name caption
keywords object_name
city keywords
province_or_state city
} province_or_state
exif { }
FNumber exif {
ExposureTime FNumber
ISO ExposureTime
} ISO
vibrant { }
...VibrantColors vibrant {
} ...VibrantColors
} }
} }
} }

View File

@ -11,7 +11,6 @@ const MasonryGallery = ({ images, itemsPerRow: itemsPerRowByBreakpoint }) => {
const breakpoints = React.useMemo(() => const breakpoints = React.useMemo(() =>
R.pick(R.keys(itemsPerRowByBreakpoint), themeBreakpoints) R.pick(R.keys(itemsPerRowByBreakpoint), themeBreakpoints)
, [itemsPerRowByBreakpoint]); , [itemsPerRowByBreakpoint]);
console.log(breakpoints);
const { breakpoint } = useBreakpoint(breakpoints, 'sm'); const { breakpoint } = useBreakpoint(breakpoints, 'sm');

View File

@ -1,7 +1,7 @@
import { graphql } from 'gatsby'; import { graphql } from 'gatsby';
export const VibrantColorsFragment = graphql` export const VibrantColorsFragment = graphql`
fragment VibrantColors on ImageSharpFieldsImageMetaVibrant { fragment VibrantColors on FileFieldsImageMetaVibrant {
DarkMuted DarkMuted
DarkVibrant DarkVibrant
LightMuted LightMuted

View File

@ -175,13 +175,8 @@ const IndexPage = ({ data: { allFile: { edges } } }) => {
export const query = graphql` export const query = graphql`
{ {
allFile( allFile(
filter: { filter: { sourceInstanceName: {eq: "gallery"} }
sourceInstanceName: {eq: "gallery"}, sort: {order: DESC, fields: fields___imageMeta___dateTaken}
# images that don't work well
# base: {nin: ["DSC06517.jpg"]}
# childrenImageSharp: {elemMatch: {fluid: {aspectRatio: {lte: 1.3}}}}
},
sort: {order: DESC, fields: childrenImageSharp___fields___imageMeta___dateTaken}
) { ) {
edges { edges {
node { node {
@ -196,11 +191,11 @@ export const query = graphql`
placeholder: NONE placeholder: NONE
breakpoints: [750, 1080, 1366, 1920, 2560] breakpoints: [750, 1080, 1366, 1920, 2560]
) )
fields { }
imageMeta { fields {
vibrant { imageMeta {
...VibrantColors vibrant {
} ...VibrantColors
} }
} }
} }

View File

@ -56,33 +56,26 @@ export const query = graphql`
query GalleryPageQuery { query GalleryPageQuery {
allFile( allFile(
filter: { sourceInstanceName: { eq: "gallery" } } filter: { sourceInstanceName: { eq: "gallery" } }
sort: {order: DESC, fields: childrenImageSharp___fields___imageMeta___dateTaken} sort: {order: DESC, fields: fields___imageMeta___dateTaken}
) { ) {
edges { edges {
node { node {
relativePath, relativePath
base, base
childImageSharp{ childImageSharp{
fluid { fluid {
aspectRatio aspectRatio
}, }
gatsbyImageData( gatsbyImageData(
layout: CONSTRAINED, layout: CONSTRAINED
height: 550 height: 550
) )
fields { }
imageMeta { fields {
dateTaken imageMeta {
iptc { dateTaken
# caption iptc {
object_name object_name
}
# exif {
# FNumber
# ExposureTime
# ShutterSpeedValue
# ISO
# }
} }
} }
} }

View File

@ -1,6 +1,6 @@
// import kebabCase from 'lodash/kebabCase'; // import kebabCase from 'lodash/kebabCase';
export const getMeta = (image) => image.childImageSharp.fields.imageMeta; export const getMeta = (image) => image.fields.imageMeta;
export const getName = (image) => getMeta(image)?.iptc.object_name || image.base; export const getName = (image) => getMeta(image)?.iptc.object_name || image.base;
@ -39,12 +39,12 @@ const gcd = (a, b) => {
export const getShutterFractionFromExposureTime = (exposureTime) => { export const getShutterFractionFromExposureTime = (exposureTime) => {
let fraction = exposureTime; let fraction = exposureTime;
var len = fraction.toString().length - 2; const len = fraction.toString().length - 2;
var denominator = Math.pow(10, len); let denominator = Math.pow(10, len);
var numerator = fraction * denominator; let numerator = fraction * denominator;
var divisor = gcd(numerator, denominator); const divisor = gcd(numerator, denominator);
numerator /= divisor; numerator /= divisor;
denominator /= divisor; denominator /= divisor;

1277
yarn.lock

File diff suppressed because it is too large Load Diff