From b0cd3c3f1334f689448c86e53ded8081780e92e2 Mon Sep 17 00:00:00 2001 From: Kristof Zerbe Date: Fri, 29 Nov 2024 21:14:09 +0100 Subject: [PATCH] Reserve Photos --- .gitignore | 1 + _config.yml | 1 + .../on-generateBefore-get-dynamic-photos.js | 38 ++++++++++++++++++- source/_dynamic/photos-map.md | 2 +- source/_dynamic/photos.md | 2 +- 5 files changed, 41 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index ec869501a4..de014450fb 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ XXX/ HexoCommand* photos_original/ lemmy-test.rest +'--'/ diff --git a/_config.yml b/_config.yml index 2ada9e91c1..a9fccc5388 100644 --- a/_config.yml +++ b/_config.yml @@ -81,6 +81,7 @@ static_dir: static photo_dir: photos pool_dir: pool shed_dir: shed +reserve_dir: reserve public_dir: docs archive_dir: archives tag_dir: archives/tags diff --git a/scripts/events/on-generateBefore-get-dynamic-photos.js b/scripts/events/on-generateBefore-get-dynamic-photos.js index c6950d8274..1adc63e7a8 100644 --- a/scripts/events/on-generateBefore-get-dynamic-photos.js +++ b/scripts/events/on-generateBefore-get-dynamic-photos.js @@ -18,13 +18,14 @@ hexo.on('generateBefore', function() { let pHero = getHeroPhoto(); let pPool = getPoolPhotos(); let pShed = getShedPhotos(); + let pReserve = getReservePhotos(); let pPostPages = getPostAndPagePhotos(); let pDrafts = getDraftPagePhotos(); let pDynamic = getDynamicPagePhotos(); let pAnything = getAnythingPagePhotos(); let pNotes = getNotesPhotos(); - let photos = [...pHero, ...pPool, ...pShed, ...pPostPages, ...pDrafts, ...pDynamic, ...pAnything, ...pNotes] + let photos = [...pHero, ...pPool, ...pReserve, ...pShed, ...pPostPages, ...pDrafts, ...pDynamic, ...pAnything, ...pNotes] .filter(p => (p.name)) //filter out all without photo name .sort((a, b) => a.key.localeCompare(b.key)); @@ -190,6 +191,41 @@ function getPoolPhotos() { /** ================================================================================= */ +function getReservePhotos() { + const config = hexo.config; + + var reserveDir = path.join(_rootDir, config.static_dir, config.reserve_dir); + + let reserve = fs.readdirSync(reserveDir) + .filter(entry => fs.statSync(path.join(reserveDir, entry)).isDirectory()) + .map(entry => ({ key: entry, status: "reserve", file: null })); + + reserve.forEach(entry => { + + let metaFile = path.join(reserveDir, entry.key, "meta.json"); + let metaCreationDate, meta; + if (fs.existsSync(metaFile)) { + metaCreationDate = fs.statSync(metaFile).birthtime; + meta = JSON.parse(fs.readFileSync(metaFile)); + } + + entry.file = entry.key + ".jpg"; + entry.route = entry.key; //meta?.custom.name || entry.key; + entry.name = entry.meta?.ObjectName || entry.key; + entry.article = null; + entry.pathMobile = "/" + path.join(config.reserve_dir, entry.key, "mobile.jpg").replace(/\134/g,"/"); + entry.pathTablet = "/" + path.join(config.reserve_dir, entry.key, "tablet.jpg").replace(/\134/g,"/"); + entry.pathNormal = "/" + path.join(config.reserve_dir, entry.key, "normal.jpg").replace(/\134/g,"/"); + entry.date = metaCreationDate; + entry.meta = meta; + }); + + log.info("-> " + magenta(reserve.length) + " reserve photos"); + return reserve; +} + +/** ================================================================================= */ + function getShedPhotos() { const config = hexo.config; diff --git a/source/_dynamic/photos-map.md b/source/_dynamic/photos-map.md index eaa042076c..d1c7104688 100644 --- a/source/_dynamic/photos-map.md +++ b/source/_dynamic/photos-map.md @@ -6,7 +6,7 @@ photograph: name: Photographers Mosaic keepOutOverview: true date: 2021-08-24 15:56:00 -updated: 2024-11-17 17:19:33 +updated: 2024-11-29 14:51:01 --- Most of the images listed in the collection (and some more out of the shed) contain geo-localisations in the form of GPS coordinates in their metadata. These **{% photo.count %} photos** are pinned on this map. diff --git a/source/_dynamic/photos.md b/source/_dynamic/photos.md index ddfbb82ef9..2afc85311c 100644 --- a/source/_dynamic/photos.md +++ b/source/_dynamic/photos.md @@ -5,7 +5,7 @@ photograph: file: $20-08-Mallorca-7627.jpg name: Photographers Mosaic date: 2021-08-24 15:56:00 -updated: 2024-11-17 17:19:33 +updated: 2024-11-29 14:51:01 ---