Skip to content

Commit

Permalink
Photo Refactoring meta.json
Browse files Browse the repository at this point in the history
  • Loading branch information
kristofzerbe committed Sep 5, 2023
1 parent f0084ef commit 6901b5a
Show file tree
Hide file tree
Showing 467 changed files with 709 additions and 266 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ db.json
docs/
node_modules/
XXX/
HexoCommand*
HexoCommand*
photos_original/
3 changes: 1 addition & 2 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ description_short: by Kristof Zerbe
language: en
timezone: Europe/Berlin
hero:
file: $main.jpg
file: $19-05 Israel-0228.jpg
name: Sea Wall
link: https://500px.com/photo/1061252063
url: https://kiko.io/images/hero.jpg
icon: https://kiko.io/images/icon-192x192.png
keywords:
Expand Down
83 changes: 83 additions & 0 deletions lib/_once_process_meta_original.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
'use strict';

/**
* node "./lib/_once_process_meta_original.js"
*/

const { red } = require('chalk');

const fs = require("fs");
const path = require("path");

const exifr = require('exifr');
const originalFolder = "../photos_original/temp";
const poolFolder = "../static/pool";
const metaFolder = "../static/photos/meta";

const _currentPath = __dirname;

let _originalFolder = path.join(_currentPath, originalFolder);
let _poolFolder = path.join(_currentPath, poolFolder);
let _metaFolder = path.join(_currentPath, metaFolder);;

const orgFiles = fs.readdirSync(_originalFolder);

// return; //DONT RUN AGAIN!

const jpgFiles = orgFiles
.filter(file => {
return path.extname(file).toLowerCase() === ".jpg";
})
.sort();

if (jpgFiles.length === 0) return;

jpgFiles.forEach((file) => {

const imgFile = path.join(_originalFolder, file);

const folder = file.replace(path.extname(file), '');

let metaFile;

const existingPoolFolder = path.join(_poolFolder, folder);
if (fs.existsSync(existingPoolFolder)) {
metaFile = path.join(existingPoolFolder, "meta.json");
} else {
metaFile = path.join(_metaFolder, folder + ".json");
}

exifr.parse(imgFile, { xmp: true, iptc: true }).then(output => {

const custom = {
"custom": {
"name": folder,
"links": [
{
"site": "500px",
"url": ""
},
{
"site": "pixelfed",
"url": ""
}
]
}
};

const meta = { ...custom, ...output };

let msg = "Meta Data parsed for '" + file + " -> " + meta.ObjectName + "' -> " + metaFile;
if (meta.ObjectName === undefined) {
console.log(red(msg));
} else {
console.log(msg);
}

fs.writeFile(metaFile, JSON.stringify(meta), err => {
if (err) { console.error(err); }
});

});

});
5 changes: 3 additions & 2 deletions lib/_run_pool-photo-generator.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

const PoolPhotoGenerator = require("../lib/pool-photo-generator.cjs").PoolPhotoGenerator;

const inboundFolder = "../new_photos";
const inboundFolder = "../photos_new";
const originalFolder = "../photos_original";
const poolFolder = "../static/pool";

const generator = new PoolPhotoGenerator(inboundFolder, poolFolder);
const generator = new PoolPhotoGenerator(inboundFolder, originalFolder, poolFolder);
generator.generate();
51 changes: 39 additions & 12 deletions lib/pool-photo-generator.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,29 @@ sharp.cache(false); //prevents keeping source file open
const _currentPath = __dirname;

let _inboundFolder;
let _originalFolder;
let _poolFolder;

class PoolPhotoGenerator {

/**
* Contructor of PoolPhotoGenerator
* @param {String} inboundFolder
* @param {String} originalFolder
* @param {String} poolFolder
*/
constructor(inboundFolder, poolFolder) {
constructor(inboundFolder, originalFolder, poolFolder) {

_inboundFolder = path.join(_currentPath, inboundFolder);
_originalFolder = path.join(_currentPath, originalFolder);
_poolFolder = path.join(_currentPath, poolFolder);

if (!fs.existsSync(_inboundFolder)) {
throw "Inbound folder not found"
}
if (!fs.existsSync(_originalFolder)) {
throw "Original folder not found"
}
if (!fs.existsSync(_poolFolder)) {
throw "Pool folder not found"
}
Expand Down Expand Up @@ -59,15 +65,35 @@ class PoolPhotoGenerator {
const imgFile = path.join(_inboundFolder, file);

if (fs.existsSync(imgFile)) {
const newPhotoFolder = path.join(_poolFolder, file.replace(path.extname(file), ''));
fs.mkdirSync(newPhotoFolder);

// read TITLE from IPTC and write to meta.txt, plus new line
const iptcMeta = exifr.parse(imgFile, { iptc: true }).then(output => {
let title = output.ObjectName || "No Title";
console.log('IPTC data parsed for new pool photo', gray(file), "-> Title:" , magenta(title));

fs.writeFile(path.join(newPhotoFolder, "meta.txt"), title +"\n", err => {
const folder = file.replace(path.extname(file), '');
const newPhotoFolder = path.join(_poolFolder, folder);
if (!fs.existsSync(newPhotoFolder)) fs.mkdirSync(newPhotoFolder);

// parse meta data and write to json file
const processMeta = exifr.parse(imgFile, { xmp: true, iptc: true }).then(output => {

const custom = {
"custom": {
"name": folder,
"file": file,
"links": [
{
"platform": "500px",
"url": ""
},
{
"platform": "pixelfed",
"url": ""
}
]
}
};

const meta = { ...custom, ...output };

console.log('Meta data parsed and stored for new pool photo', gray(file));

fs.writeFile(path.join(newPhotoFolder, "meta.json"), JSON.stringify(meta), err => {
if (err) { console.error(err); }
});
});
Expand All @@ -77,9 +103,10 @@ class PoolPhotoGenerator {
const createTablet = self.createImageVariant(imgFile, path.join(newPhotoFolder, "tablet.jpg"), 768);
const createNormal = self.createImageVariant(imgFile, path.join(newPhotoFolder, "normal.jpg"), 1280);

Promise.all([iptcMeta, createMobile, createTablet, createNormal])
Promise.all([processMeta, createMobile, createTablet, createNormal]) //
.then(() => {
fs.unlinkSync(imgFile); // delete original image
//fs.unlinkSync(imgFile); // delete original image
fs.renameSync(imgFile, path.join(_originalFolder, file)); // move image
});
}
});
Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion scaffolds/discovery.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ date: {{ date }}
photograph:
file:
name:
link:
socialmedia: /static/images/social-media/{{ slug }}.png
series: Discoveries
categories:
Expand Down
1 change: 0 additions & 1 deletion scaffolds/draft.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ date: {{ date }}
photograph:
file:
name:
link:
socialmedia: /static/images/social-media/{{ slug }}.png
series:
project:
Expand Down
1 change: 0 additions & 1 deletion scaffolds/golem.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ date: {{ date }}
photograph:
file:
name:
link:
socialmedia: /static/images/social-media/{{ slug }}.png
series: Golem
golem:
Expand Down
2 changes: 1 addition & 1 deletion scaffolds/page.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
title: {{ title }}
date: {{ date }}
photograph:
file:
file:
---
1 change: 0 additions & 1 deletion scaffolds/post.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ date: {{ date }}
photograph:
file:
name:
link:
socialmedia: /static/images/social-media/{{ slug }}.png
series:
project:
Expand Down
1 change: 0 additions & 1 deletion scaffolds/preset.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ date: {{ date }}
photograph:
file:
name:
link:
socialmedia: /static/images/social-media/{{ slug }}.png
series: Lightroom Presets
categories:
Expand Down
1 change: 0 additions & 1 deletion scaffolds/project.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ date: {{ date }}
photograph:
file:
name:
link:
socialmedia: /static/images/social-media/{{ slug }}.png
project:
categories:
Expand Down
1 change: 0 additions & 1 deletion scaffolds/step-by-step.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ date: {{ date }}
photograph:
file:
name:
link:
socialmedia: /static/images/social-media/{{ slug }}.png
series: Step By Step
categories:
Expand Down
5 changes: 3 additions & 2 deletions scripts/on-ready-generate-pool-photos.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ const PoolPhotoGenerator = require("../lib/pool-photo-generator.cjs").PoolPhotoG

hexo.on("ready", function() {

const inboundFolder = "../new_photos";
const inboundFolder = "../photos_new";
const originalFolder = "../photos_original";
const poolFolder = "../static/pool";

const generator = new PoolPhotoGenerator(inboundFolder, poolFolder);
const generator = new PoolPhotoGenerator(inboundFolder, originalFolder, poolFolder);
generator.generate();

});
3 changes: 1 addition & 2 deletions source/404/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ title: 404
date: 2020-09-23 12:31:40
permalink: 404.html
photograph:
file: $404.jpg
file: $D50_5119.jpg
name: Brake
link: 'https://500px.com/photo/1038382604'
---
I don't know how you ended up here, but you have jumped over the edge of this blog. Maybe it's the end of the internet and you can power off your machine now...

Expand Down
4 changes: 2 additions & 2 deletions source/_anything/project/hexo-console-webmention.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
title: Hexo Console Webmention
permalink: /projects/hexo-console-webmention
photograph:
file: $projects.jpg
file: $19-05 Israel-0245.jpg
name: Ancient Mosaic
link: 'https://500px.com/photo/1057290585'
---

**Hexo Console Webmention** is a console command for [Hexo](https://hexo.io/) to send Webmentions from your blog to others. It utilizes the work of [Remy Sharp](https://remysharp.com/2019/06/18/send-outgoing-webmentions), who wrote a JS library to parse a URL for sending Webmentions to linked Blogs. It is mainly used at [**webmention.app**](https://webmention.app/)
Expand Down
4 changes: 2 additions & 2 deletions source/_anything/project/hexo-generator-anything.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
title: Hexo Generator Anything
permalink: /projects/hexo-generator-anything
photograph:
file: $projects.jpg
file: $19-05 Israel-0245.jpg
name: Ancient Mosaic
link: 'https://500px.com/photo/1057290585'
---

**Hexo Generator Anything** is a plugin for [Hexo](https://hexo.io/) to generate index pages from custom front matter variables.
Expand Down
4 changes: 2 additions & 2 deletions source/_anything/project/hexo-tag-plugins.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
title: Hexo Tag Plugins
permalink: /projects/hexo-tag-plugins
photograph:
file: $projects.jpg
file: $19-05 Israel-0245.jpg
name: Ancient Mosaic
link: 'https://500px.com/photo/1057290585'
---

**Hexo Tag Plugins** is a collection of [Tag Plugins for Hexo](https://hexo.io/docs/tag-plugins.html) I have created for this blog. Some of them are quite simple, others are more complex, but overall maybe helpful for you.
Expand Down
4 changes: 2 additions & 2 deletions source/_anything/project/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Projects
permalink: /projects
photograph:
file: $projects.jpg
file: $19-05 Israel-0245.jpg
name: Ancient Mosaic
link: 'https://500px.com/photo/1057290585'
---
4 changes: 2 additions & 2 deletions source/_anything/project/social-media-image-generator.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
title: Social Media Image Generator
permalink: /projects/social-media-image-generator
photograph:
file: $projects.jpg
file: $19-05 Israel-0245.jpg
name: Ancient Mosaic
link: 'https://500px.com/photo/1057290585'
---

**Social Media Image Generator** is a script to generate social media images for blog posts. It utilizes [Puppeteer](https://github.com/puppeteer/puppeteer) for running a headless Chromium to take a screenshot of a temporary created HTML file, which is generated with your posts Frontmatter information and a referenced photograph.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ subtitle: Implementing a self updating client/server environment
photograph:
file: 19-07 Schottland-0490.jpg
name: Fishermans Home
link: 'https://500px.com/photo/1022777507/Fishermans-Home-by-Kristof-Zerbe/'
hidden: true
---
Deploying .NET clients (WPF or WinForms) under Windows is usually easy, because copying the assemblies is enough, if the client machines have installed the required .NET framework. You can use specialized software packages like [Octopus Deploy](https://octopus.com/), which in the best case integrate into your build pipeline ... or you write your own mechanism to let update the clients itself.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ date: 2023-07-06 21:57:37
photograph:
file: D50_7117.jpg
name: Into A Huddle
link: https://500px.com/photo/1045390520
socialmedia: /static/images/social-media/Creating-a-flipping-Contact-Card-with-QR-Code.png
categories:
- UI/UX
Expand Down
1 change: 0 additions & 1 deletion source/_drafts/Discoveries-Workflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ date: 2023-08-20 15:28:29
photograph:
file: 23-05 Holland-0580.jpg
name: Analog Treasures
link: https://500px.com/photo/1073875596
socialmedia: /static/images/social-media/Discoveries-Workflow.png
series: Step By Step
categories:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ date: 2022-01-19 15:36:59
photograph:
file: DSC_6371-HDR.jpg
name: Lonely Lock
link: 'https://500px.com/photo/83252729/Lonely-Lock-by-Kristof-Zerbe/'
categories:
- Misc
tags:
Expand Down
3 changes: 1 addition & 2 deletions source/_dynamic/console.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ title: Console
date: 2023-02-15 11:43:00
permalink: /console
photograph:
file: $console.jpg
file: $22-08 Bretagne-Jersey-0048.jpg
name: Golden Lamp
link: https://500px.com/photo/1056125387/golden-lamp-by-kristof-zerbe/
---

This page is not yet ready ...
Expand Down
Loading

0 comments on commit 6901b5a

Please sign in to comment.