From 184078231f950ed454449f5a9f49cf39739817c0 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Wed, 12 Sep 2018 22:36:50 +0200 Subject: [PATCH] exif fixes --- gatsby-node.js | 13 ++++--------- package.json | 1 + src/components/molecules/PostMeta.module.scss | 1 - 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/gatsby-node.js b/gatsby-node.js index 68308fd8..ca24f560 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -4,6 +4,7 @@ const yaml = require('js-yaml') const { createFilePath } = require('gatsby-source-filesystem') const { paginate } = require('gatsby-awesome-pagination') const fastExif = require('fast-exif') +const { Fraction } = require('fractional') const meta = yaml.load(fs.readFileSync('./content/meta.yml', 'utf8')) const { itemsPerPage } = meta @@ -60,11 +61,6 @@ exports.onCreateNode = ({ node, actions, getNode }) => { } } -const getFraction = decimal => { - for (var denominator = 1; (decimal * denominator) % 1 !== 0; denominator++); - return { numerator: decimal * denominator, denominator: denominator } -} - const generateExif = (exifData, createNodeField, node) => { const { Model } = exifData.image const { @@ -75,14 +71,13 @@ const generateExif = (exifData, createNodeField, node) => { ExposureBiasValue } = exifData.exif - const shutterspeedNumerator = getFraction(ExposureTime).numerator - const shutterspeedDenominator = getFraction(ExposureTime).denominator + const { numerator, denominator } = new Fraction(ExposureTime) const exposureShortened = parseFloat(ExposureBiasValue.toFixed(2)) - const model = Model + const model = `${Model}` const iso = `ISO ${ISO}` const fstop = `ƒ ${FNumber}` - const shutterspeed = `${shutterspeedNumerator}/${shutterspeedDenominator}s` + const shutterspeed = `${numerator}/${denominator}s` const focalLength = `${FocalLength}mm` let exposure diff --git a/package.json b/package.json index 89563e15..946b406a 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ ], "dependencies": { "fast-exif": "^1.0.1", + "fractional": "^1.0.0", "gatsby": "^2.0.0-rc.21", "gatsby-awesome-pagination": "^0.1.1", "gatsby-image": "^2.0.0-rc.2", diff --git a/src/components/molecules/PostMeta.module.scss b/src/components/molecules/PostMeta.module.scss index 8ca48462..7a7a9b80 100644 --- a/src/components/molecules/PostMeta.module.scss +++ b/src/components/molecules/PostMeta.module.scss @@ -36,7 +36,6 @@ ///////////////////////////////////// .type { - margin-bottom: $spacer / 2; text-align: center; a {