Move imageMeta to field on top level File object to solve deprecation warning
This commit is contained in:
parent
2c407ee41f
commit
039df7958c
@ -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,8 +164,9 @@ 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);
|
||||||
|
console.log('edges', edges[0].node.fields.imageMeta);
|
||||||
|
|
||||||
edges.forEach(({ node }, index) => {
|
edges.forEach(({ node }, index) => {
|
||||||
const nextImage = index === edges.length - 1
|
const nextImage = index === edges.length - 1
|
||||||
@ -178,8 +175,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 +183,8 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
|
|||||||
nextImage,
|
nextImage,
|
||||||
prevImage,
|
prevImage,
|
||||||
},
|
},
|
||||||
});
|
};
|
||||||
|
console.log('page', page);
|
||||||
|
createPage(page);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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');
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
|
||||||
# }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user