mirror of
https://github.com/kremalicious/blog.git
synced 2024-12-23 01:30:01 +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 { itemsPerPage } = meta
|
||||
|
||||
// Create slug & date for posts from file path values
|
||||
exports.onCreateNode = ({ node, actions, getNode }) => {
|
||||
const { createNodeField } = actions
|
||||
|
||||
// Markdown files
|
||||
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 parsedFilePath = path.parse(fileNode.relativePath)
|
||||
const slugOriginal = createFilePath({ node, getNode })
|
||||
@ -49,19 +60,17 @@ exports.onCreateNode = ({ node, actions, getNode }) => {
|
||||
})
|
||||
}
|
||||
|
||||
// exif
|
||||
if (node.internal.mediaType === 'image/jpeg') {
|
||||
const readAndCreateExifFields = (node, createNodeField) => {
|
||||
fastExif
|
||||
.read(node.absolutePath, true)
|
||||
.then(exifData => {
|
||||
if (!exifData) return
|
||||
generateExif(exifData, createNodeField, node)
|
||||
createExifFields(exifData, createNodeField, node)
|
||||
})
|
||||
.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 {
|
||||
ISO,
|
||||
|
@ -9,17 +9,21 @@ import Rss from '../svg/Rss'
|
||||
import Jsonfeed from '../svg/Jsonfeed'
|
||||
|
||||
const NetworkIcon = ({ link }) => {
|
||||
let Icon
|
||||
|
||||
if (link.includes('twitter')) {
|
||||
return <Twitter className={styles.twitter} />
|
||||
Icon = <Twitter className={styles.twitter} />
|
||||
} else if (link.includes('github')) {
|
||||
return <Github className={styles.github} />
|
||||
Icon = <Github className={styles.github} />
|
||||
} else if (link.includes('facebook')) {
|
||||
return <Facebook className={styles.facebook} />
|
||||
Icon = <Facebook className={styles.facebook} />
|
||||
} else if (link.includes('feed.xml')) {
|
||||
return <Rss className={styles.rss} />
|
||||
Icon = <Rss className={styles.rss} />
|
||||
} else if (link.includes('feed.json')) {
|
||||
return <Jsonfeed className={styles.json} />
|
||||
Icon = <Jsonfeed className={styles.json} />
|
||||
}
|
||||
|
||||
return Icon
|
||||
}
|
||||
|
||||
const IconLinks = ({ links }) => (
|
||||
|
Loading…
Reference in New Issue
Block a user