mirror of
https://github.com/kremalicious/blog.git
synced 2025-02-14 21:10:25 +01:00
refactor
This commit is contained in:
parent
c271ab750e
commit
ae9030ef6d
@ -9,11 +9,22 @@ const Fraction = require('fraction.js')
|
|||||||
const meta = yaml.load(fs.readFileSync('./content/meta.yml', 'utf8'))
|
const meta = yaml.load(fs.readFileSync('./content/meta.yml', 'utf8'))
|
||||||
const { itemsPerPage } = meta
|
const { itemsPerPage } = meta
|
||||||
|
|
||||||
// Create slug & date for posts from file path values
|
|
||||||
exports.onCreateNode = ({ node, actions, getNode }) => {
|
exports.onCreateNode = ({ node, actions, getNode }) => {
|
||||||
const { createNodeField } = actions
|
const { createNodeField } = actions
|
||||||
|
|
||||||
|
// Markdown files
|
||||||
if (node.internal.type === 'MarkdownRemark') {
|
if (node.internal.type === 'MarkdownRemark') {
|
||||||
|
createMarkdownNodeFields(node, createNodeField, getNode)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Image files
|
||||||
|
if (node.internal.mediaType === 'image/jpeg') {
|
||||||
|
readAndCreateExifFields(node, createNodeField)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create slug & date for posts from file path values
|
||||||
|
const createMarkdownNodeFields = (node, createNodeField, getNode) => {
|
||||||
const fileNode = getNode(node.parent)
|
const fileNode = getNode(node.parent)
|
||||||
const parsedFilePath = path.parse(fileNode.relativePath)
|
const parsedFilePath = path.parse(fileNode.relativePath)
|
||||||
const slugOriginal = createFilePath({ node, getNode })
|
const slugOriginal = createFilePath({ node, getNode })
|
||||||
@ -49,19 +60,17 @@ exports.onCreateNode = ({ node, actions, getNode }) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// exif
|
const readAndCreateExifFields = (node, createNodeField) => {
|
||||||
if (node.internal.mediaType === 'image/jpeg') {
|
|
||||||
fastExif
|
fastExif
|
||||||
.read(node.absolutePath, true)
|
.read(node.absolutePath, true)
|
||||||
.then(exifData => {
|
.then(exifData => {
|
||||||
if (!exifData) return
|
if (!exifData) return
|
||||||
generateExif(exifData, createNodeField, node)
|
createExifFields(exifData, createNodeField, node)
|
||||||
})
|
})
|
||||||
.catch(() => null) // just silently fail when exif can't be extracted
|
.catch(() => null) // just silently fail when exif can't be extracted
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const generateExif = (exifData, createNodeField, node) => {
|
const createExifFields = (exifData, createNodeField, node) => {
|
||||||
const { Model } = exifData.image
|
const { Model } = exifData.image
|
||||||
const {
|
const {
|
||||||
ISO,
|
ISO,
|
||||||
|
@ -9,17 +9,21 @@ import Rss from '../svg/Rss'
|
|||||||
import Jsonfeed from '../svg/Jsonfeed'
|
import Jsonfeed from '../svg/Jsonfeed'
|
||||||
|
|
||||||
const NetworkIcon = ({ link }) => {
|
const NetworkIcon = ({ link }) => {
|
||||||
|
let Icon
|
||||||
|
|
||||||
if (link.includes('twitter')) {
|
if (link.includes('twitter')) {
|
||||||
return <Twitter className={styles.twitter} />
|
Icon = <Twitter className={styles.twitter} />
|
||||||
} else if (link.includes('github')) {
|
} else if (link.includes('github')) {
|
||||||
return <Github className={styles.github} />
|
Icon = <Github className={styles.github} />
|
||||||
} else if (link.includes('facebook')) {
|
} else if (link.includes('facebook')) {
|
||||||
return <Facebook className={styles.facebook} />
|
Icon = <Facebook className={styles.facebook} />
|
||||||
} else if (link.includes('feed.xml')) {
|
} else if (link.includes('feed.xml')) {
|
||||||
return <Rss className={styles.rss} />
|
Icon = <Rss className={styles.rss} />
|
||||||
} else if (link.includes('feed.json')) {
|
} else if (link.includes('feed.json')) {
|
||||||
return <Jsonfeed className={styles.json} />
|
Icon = <Jsonfeed className={styles.json} />
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Icon
|
||||||
}
|
}
|
||||||
|
|
||||||
const IconLinks = ({ links }) => (
|
const IconLinks = ({ links }) => (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user