1
0
mirror of https://github.com/kremalicious/blog.git synced 2024-11-15 01:25:28 +01:00

new photo script tweaks

This commit is contained in:
Matthias Kretschmann 2020-03-04 19:54:17 +01:00
parent 480ba0335e
commit 6fe627f0fc
Signed by: m
GPG Key ID: 606EEEF3C479A91F

View File

@ -57,37 +57,41 @@ async function getExif(imagePath) {
async function createPhotoPost() { async function createPhotoPost() {
const photo = process.argv[3] const photo = process.argv[3]
const exifData = await getExif(photo) try {
title = exifData.iptc.object_name || exifData.iptc.title const exifData = await getExif(photo)
titleSlug = slugify(title, { lower: true }) title = exifData.iptc.object_name || exifData.iptc.title
date = new Date(exifData.exif.DateTimeOriginal).toISOString() titleSlug = slugify(title, { lower: true })
const dateShort = date.slice(0, 10) date = new Date(exifData.exif.DateTimeOriginal).toISOString()
const description = exifData.iptc.caption const dateShort = date.slice(0, 10)
const fileName = `${dateShort}-${titleSlug}` const description = exifData.iptc.caption
const postPhoto = `${photosPath}/${fileName}.md` const fileName = `${dateShort}-${titleSlug}`
const postPhoto = `${photosPath}/${fileName}.md`
const newContentsPhoto = templatePhoto const newContentsPhoto = templatePhoto
.split('TITLE') .split('TITLE')
.join(title) .join(title)
.split('SLUG') .split('SLUG')
.join(titleSlug) .join(titleSlug)
.split('DATE_LONG') .split('DATE_LONG')
.join(date) .join(date)
.split('DATE_SHORT') .split('DATE_SHORT')
.join(dateShort) .join(dateShort)
.split('DESCRIPTION') .split('DESCRIPTION')
.join(description) .join(description)
// copy photo file in place // copy photo file in place
fs.copyFile(photo, `${photosPath}/${fileName}.jpg`, err => { fs.copyFile(photo, `${photosPath}/${fileName}.jpg`, err => {
if (err) spinner.fail(`Error copying photo file: ${err}`) if (err) spinner.fail(`Error copying photo file: ${err}`)
}) })
// create photo post file // create photo post file
fs.appendFile(postPhoto, newContentsPhoto, err => { fs.appendFile(postPhoto, newContentsPhoto, err => {
if (err) spinner.fail(`Error creating photo post: ${err}`) if (err) spinner.fail(`Error creating photo post: ${err}`)
spinner.succeed(`New photo post '${title}' as '${fileName}.md' created.`) spinner.succeed(`New photo post '${title}' as '${fileName}.md' created.`)
}) })
} catch (error) {
console.error(error.message)
}
} }
if (isPhoto) { if (isPhoto) {