Skip to content

Commit ed4c4e9

Browse files
committed
import cover images for tools
1 parent fcbfbd9 commit ed4c4e9

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

.github/scripts/import-approved-experiment.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -511,13 +511,17 @@ def build_frontmatter_for_showcase(title: str, sections: dict, issue: dict, cove
511511
return lines
512512

513513

514-
def build_frontmatter_for_tools(title: str, sections: dict, issue: dict, image_items):
514+
def build_frontmatter_for_tools(
515+
title: str, sections: dict, issue: dict, image_items, cover_image: str = ""
516+
):
515517
lines = []
516518
lines.append("---")
517519
lines.append(f'title: {yaml_scalar(title)}')
518520
lines.append(f'date: {yaml_scalar(section_date_or_fallback(issue))}')
519521
lines.append("draft: false")
520522
lines.append('tool_type: "Tool"')
523+
if cover_image:
524+
lines.append(f'cover_image: {yaml_scalar(cover_image)}')
521525

522526
tags = split_list(get_field_value(sections, "tags"))
523527
if tags:
@@ -640,12 +644,10 @@ def process_content_entry(issue, sections, entry_type: str, issue_number: int, i
640644
print("No files were created due to download issues.")
641645
return []
642646

643-
downloaded_cover = None
644-
if entry_type == "showcase":
645-
downloaded_cover = collect_downloaded_cover(collect_cover_urls(sections))
646-
if not downloaded_cover:
647-
print("No cover image found for showcase issue, skipping import.")
648-
return []
647+
downloaded_cover = collect_downloaded_cover(collect_cover_urls(sections))
648+
if not downloaded_cover:
649+
print("No cover image found for content issue, skipping import.")
650+
return []
649651

650652
if not content_root.exists():
651653
content_root.mkdir(parents=True, exist_ok=True)
@@ -667,7 +669,7 @@ def process_content_entry(issue, sections, entry_type: str, issue_number: int, i
667669
with cover_path.open("wb") as cover_file:
668670
cover_file.write(downloaded_cover["data"])
669671
created_files.append(cover_path)
670-
cover_image_url = f"/images/showcase/{slug}/{cover_path.name}"
672+
cover_image_url = f"/images/{'showcase' if entry_type == 'showcase' else 'showcase-tools'}/{slug}/{cover_path.name}"
671673

672674
images_urls = []
673675
for idx, media in enumerate(downloaded_media, start=1):
@@ -692,7 +694,7 @@ def process_content_entry(issue, sections, entry_type: str, issue_number: int, i
692694
)
693695
else:
694696
frontmatter_lines = build_frontmatter_for_tools(
695-
title, sections, issue, images_urls
697+
title, sections, issue, images_urls, cover_image_url
696698
)
697699

698700
create_markdown_page(

0 commit comments

Comments
 (0)