From c1580905a9c100adc9d35f7ddae568a71790b611 Mon Sep 17 00:00:00 2001 From: Pete Gadomski Date: Mon, 28 Oct 2024 10:38:10 -0600 Subject: [PATCH] fix: order the catalogs Fixes #5 --- app/catalog.json | 17 ++++++++++------- config.toml | 3 +++ src/lib.rs | 10 ++++++++++ 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/app/catalog.json b/app/catalog.json index 873ae4d..02286be 100644 --- a/app/catalog.json +++ b/app/catalog.json @@ -9,21 +9,24 @@ "rel": "child", "type": "application/json", "title": "Microsoft Planetary Computer", - "heystac:id": "microsoft-pc" + "heystac:id": "microsoft-pc", + "heystac:index": 0 }, { - "href": "https://landsatlook.usgs.gov/stac-server", + "href": "https://earth-search.aws.element84.com/v1", "rel": "child", "type": "application/json", - "title": "USGS Landsat", - "heystac:id": "usgs-landsat" + "title": "Earth Search by Element 84", + "heystac:id": "earth-search-aws", + "heystac:index": 1 }, { - "href": "https://earth-search.aws.element84.com/v1", + "href": "https://landsatlook.usgs.gov/stac-server", "rel": "child", "type": "application/json", - "title": "Earth Search by Element 84", - "heystac:id": "earth-search-aws" + "title": "USGS Landsat", + "heystac:id": "usgs-landsat", + "heystac:index": 2 } ] } \ No newline at end of file diff --git a/config.toml b/config.toml index d86eb9b..4d2ea1c 100644 --- a/config.toml +++ b/config.toml @@ -1,11 +1,14 @@ [catalogs.microsoft-pc] href = "https://planetarycomputer.microsoft.com/api/stac/v1" title = "Microsoft Planetary Computer" +index = 0 [catalogs.earth-search-aws] href = "https://earth-search.aws.element84.com/v1" title = "Earth Search by Element 84" +index = 1 [catalogs.usgs-landsat] href = "https://landsatlook.usgs.gov/stac-server" title = "USGS Landsat" +index = 2 diff --git a/src/lib.rs b/src/lib.rs index 6790bfa..ba4ebd7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,6 +20,7 @@ pub struct Config { struct CatalogConfig { href: String, title: String, + index: usize, } impl Config { @@ -37,8 +38,17 @@ impl Config { Link::child(&catalog_config.href).title(Some(catalog_config.title.clone())); link.additional_fields .insert("heystac:id".into(), id.as_str().into()); + link.additional_fields + .insert("heystac:index".into(), catalog_config.index.into()); catalog.links.push(link); } + catalog.links.sort_by_key(|c| { + c.additional_fields + .get("heystac:index") + .unwrap() + .as_i64() + .unwrap() + }); let file = File::create(path)?; serde_json::to_writer_pretty(file, &catalog).map_err(Error::from) }