Skip to content

Commit aa30a05

Browse files
committed
feat: add linking of multiple stories
1 parent fb86c9b commit aa30a05

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

src/eodash_catalog/stac_handling.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import uuid
22
from datetime import datetime, timezone
3+
from urllib.parse import parse_qs, urlparse
34

45
import requests
56
import spdx_lookup as lookup
@@ -321,15 +322,26 @@ def add_collection_information(
321322
roles=["metadata"],
322323
),
323324
)
324-
if collection_config.get("Story"):
325-
collection.add_asset(
326-
"story",
327-
Asset(
328-
href=f'{catalog_config["assets_endpoint"]}/{collection_config["Story"]}',
329-
media_type="text/markdown",
330-
roles=["metadata"],
331-
),
332-
)
325+
if stories := collection_config.get("Stories"):
326+
for story in stories:
327+
if story.startswith("http"):
328+
story_url = story
329+
else:
330+
story_url = f'{catalog_config.get("stories_endpoint")}/{story}'
331+
parsed_url = urlparse(story_url)
332+
# check if it is URL with a query parameter id=story-identifier
333+
if parsed_url.query and len(parse_qs(parsed_url.query).get("id")) > 0:
334+
story_id = parse_qs(parsed_url.query).get("id")[0]
335+
else:
336+
story_id = parsed_url.path.rsplit("/")[-1].replace(".md", "").replace(".MD", "")
337+
collection.add_asset(
338+
story_id,
339+
Asset(
340+
href=story_url,
341+
media_type="text/markdown",
342+
roles=["metadata", "story"],
343+
),
344+
)
333345
if collection_config.get("Image"):
334346
# Check if absolute URL or relative path
335347
if collection_config["Image"].startswith("http"):

0 commit comments

Comments
 (0)