From dc6d8cdaca9b92d7efa303b9bb935be6dfae8d64 Mon Sep 17 00:00:00 2001 From: Wentao Kuang Date: Mon, 16 Jan 2023 16:28:18 +1300 Subject: [PATCH] fix(cli): Remove the special charactors from title to the imagery name. (#2643) * Remove the special charactors from title to the imagery name. * Remove all the non non character letter in the imagery name. --- packages/cli/src/cli/__tests__/util.test.ts | 3 +++ packages/cli/src/cli/util.ts | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/cli/__tests__/util.test.ts b/packages/cli/src/cli/__tests__/util.test.ts index 0b5cbaef2..1c55ac481 100644 --- a/packages/cli/src/cli/__tests__/util.test.ts +++ b/packages/cli/src/cli/__tests__/util.test.ts @@ -9,5 +9,8 @@ o.spec('util', () => { o(nameImageryTitle('Palmerston.north / urban 2016-17 12.125')).equals('palmerston-north_urban_2016-17_12-125'); o(nameImageryTitle('Manawatū urban 2016-17 12.125m')).equals('manawatu_urban_2016-17_12-125m'); o(nameImageryTitle('ĀāĒēĪīŌōŪū urban 2016-17 12.125m')).equals('aaeeiioouu_urban_2016-17_12-125m'); + o(nameImageryTitle('Marlborough / Wellington 0.75m SNC50451 (2004-2005)')).equals( + 'marlborough_wellington_0-75m_snc50451_2004-2005', + ); }); }); diff --git a/packages/cli/src/cli/util.ts b/packages/cli/src/cli/util.ts index d9e89cec7..4ca5d76e8 100644 --- a/packages/cli/src/cli/util.ts +++ b/packages/cli/src/cli/util.ts @@ -149,5 +149,9 @@ export async function prepareUrl(job: CogStacJob): Promise { * 'Tasman rural 2018-19 0.3m' => 'tasman_rural_2018-19_0-3m' */ export function nameImageryTitle(title: string): string { - return slugify(title.replace(/\.+/g, '-'), { replacement: '_', lower: true, trim: true }); + return slugify(title.replace(/\.+/g, '-'), { + replacement: '_', + lower: true, + trim: true, + }).replace(/[^\w-_]/gi, ''); }