From 9a4a0a490ef9426f3d7f5a9131d932d5dcde331d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20P=2E?= Date: Tue, 24 Mar 2026 19:35:54 +0100 Subject: [PATCH] Remove leading zeros in canvas names (WIP) --- README.md | 12 ++++++------ src/service/FilenameParser.js | 10 +++++++++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 75acce1..8143dd0 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # IIIF Manifest service for the GreekSchools Project -This repository holds the code for a NodeJS/Express service that implements dynamic generation of IIIF manifests, compliant with version 2 of the Presentation API. Support for version 3 should be added in the future. +This repository holds the code for a NodeJS/Express service that implements dynamic generation of IIIF manifests for images produced by the [GreekSchools ERC project](https://greekschools.eu). The service is compliant with version 2 of the Presentation API, support for version 3 should be added in the future. The project uses `yarn` for dependency management and an `.env` file to set environment variables, an example of which can be found in `.env.example`. @@ -8,19 +8,19 @@ The project uses `yarn` for dependency management and an `.env` file to set envi `GreekManifests` requires NodeJS v. >= 20 to be installed on the system, as well as `yarn` as a package manager, which can be installed globally via `npm`: -``` +```shell npm install -g yarn ``` To install the service itself, clone this repository on the target host (replace `` with a suitable path, or remove to install in `./greek-manifests`): -``` +```shell git clone https://git.electricmandarine.cloud/nicolo/greek-manifests ``` then run the following commands from the root folder: -``` +```shell yarn node app.mjs ``` @@ -30,9 +30,9 @@ This will start the [Express](https://expressjs.com) web server, which will rema ## Documentation -Automatic JSDoc documentation for the codebase can be generated by running the following command from the root folder: +Automatic [JSDoc](https://jsdoc.app) documentation for the codebase can be generated by running the following command from the project's root folder: -``` +```shell jsdoc -c jsdoc.json ``` diff --git a/src/service/FilenameParser.js b/src/service/FilenameParser.js index e0c0937..77b580f 100644 --- a/src/service/FilenameParser.js +++ b/src/service/FilenameParser.js @@ -162,7 +162,7 @@ const extractors = { * @param {string} technique * @returns {ParsedMetadata} */ -export function parse (imgFilename, technique) { +export function parse(imgFilename, technique) { return extractors[technique](imgFilename); } /** @@ -180,6 +180,14 @@ export function getCanvasName(imgFilename, technique) { canvasName += imgFilename.split('_')[3].replace(/\..*$/,''); } + // Check if name is of `fr01&02` type... + let names = canvasName.split('&'); + + // Remove leading zeroes everywhere + names = names.map(name => name.replaceAll(/^([a-z]+)?0*(\d+)/ig, '$1$2')); + // Rejoin if needed... + canvasName = names.join('&'); + return canvasName; } /**