Skip to content

Commit

Permalink
fix(cli): Remove the special charactors from title to the imagery nam…
Browse files Browse the repository at this point in the history
…e. (#2643)

* Remove the special charactors from title to the imagery name.

* Remove all the non non character letter in the imagery name.
  • Loading branch information
Wentao-Kuang authored Jan 16, 2023
1 parent 4683358 commit dc6d8cd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/cli/src/cli/__tests__/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
);
});
});
6 changes: 5 additions & 1 deletion packages/cli/src/cli/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,9 @@ export async function prepareUrl(job: CogStacJob): Promise<string> {
* '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, '');
}

0 comments on commit dc6d8cd

Please sign in to comment.