Skip to content

Commit bf22d86

Browse files
authored
Update generate.py
1 parent 1ac2955 commit bf22d86

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

scripts/generate.py

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,35 @@
99
def generate_entry_md(entry, is_plugin=True, index=0):
1010
owner, repo_name = entry['repo'].split('/')
1111
sanitized_name = entry['name'].replace(' ', '%20')
12-
1312
# Title + Badges (only once)
1413
md = f"- ### [{entry['name']}](https://github.com/{entry['repo']}) <br>\n"
15-
md += f" [![Latest Release Date](https://img.shields.io/github/release-date/{entry['repo']}?label=Latest%20Release&color=green)](https://github.com/{entry['repo']}/releases) "
14+
md += f" [![Latest Release Date](https://img.shields.io/github/release-date/{entry['repo']}?label=Latest%20Release&color=green)](https://github.com/{entry['repo']}/releases) "
1615
md += f"[![GitHub Downloads](https://img.shields.io/github/downloads/{entry['repo']}/total)](https://github.com/{entry['repo']}/releases/download/{entry.get('latest_release_tag', 'latest')}/{sanitized_name}.jar)<br>\n"
17-
1816
# MC version + core badge
1917
if is_plugin and 'mc_versions' in entry:
2018
mc_versions = entry['mc_versions'].replace('-', '--').replace('.', '%20')
21-
md += f" ![MC Version](https://img.shields.io/badge/MC%20Version-{mc_versions}-blueviolet)<br>\n"
22-
19+
md += f" ![MC Version](https://img.shields.io/badge/MC%20Version-{mc_versions}-blueviolet)<br>\n"
2320
if is_plugin and entry.get('is_core', False):
24-
md += " ![Core Plugin](https://img.shields.io/badge/Core%20Plugin-blue)<br>\n"
25-
21+
md += " ![Core Plugin](https://img.shields.io/badge/Core%20Plugin-blue)<br>\n"
2622
# Creator
27-
md += f" **Creator**: <img src=\"{entry['creator']['avatar']}\" width=\"20\" height=\"20\"> [{entry['creator']['name']}]({entry['creator']['url']})<br>\n"
28-
23+
md += f" **Creator**: <img src=\"{entry['creator']['avatar']}\" width=\"20\" height=\"20\"> [{entry['creator']['name']}]({entry['creator']['url']})<br>\n"
24+
2925
# Description
3026
cleaned_description = re.sub(r'!\[.*?\]\(.*?\)', '', entry['description'])
31-
md += f" {cleaned_description.strip()}\n\n"
32-
27+
md += f" {cleaned_description.strip()}\n\n"
3328
# Screenshots
3429
if entry.get('screenshots'):
35-
md += " <details>\n <summary>Show Screenshots</summary>\n <p align=\"center\">\n"
30+
md += " <details>\n <summary>Show Screenshots</summary>\n <p align=\"center\">\n"
3631
for ss in entry['screenshots']:
37-
md += f" <img src=\"{ss['url']}\" alt=\"{ss['alt']}\" width=\"{ss.get('width', 250)}\">\n"
38-
md += " </p>\n </details>\n"
39-
32+
# Check if the screenshot is a YouTube thumbnail
33+
youtube_match = re.match(r'https://img.youtube.com/vi/([^/]+)/\d+\.jpg', ss['url'])
34+
if youtube_match:
35+
video_id = youtube_match.group(1)
36+
video_url = f"https://www.youtube.com/watch?v={video_id}"
37+
md += f" <a href=\"{video_url}\" target=\"_blank\"><img src=\"{ss['url']}\" alt=\"{ss['alt']}\" width=\"{ss.get('width', 250)}\"></a>\n"
38+
else:
39+
md += f" <img src=\"{ss['url']}\" alt=\"{ss['alt']}\" width=\"{ss.get('width', 250)}\">\n"
40+
md += " </p>\n </details>\n"
4041
md += "---\n\n"
4142
return md
4243

@@ -50,11 +51,11 @@ def generate_entry_md(entry, is_plugin=True, index=0):
5051
plugin_entries += generate_entry_md(plugin, is_plugin=True, index=i)
5152

5253
# Update Plugins badge count and plugin list section
53-
plugins_content = re.sub(r'\[!\[Plugins\].*?\]\(#plugins-list\)',
54-
f'[![Plugins](https://img.shields.io/badge/Plugins-{len(data.get("plugins", []))}-green)](#plugins-list)',
54+
plugins_content = re.sub(r'\[!\[Plugins\].*?\]\(#plugins-list\)',
55+
f'[![Plugins](https://img.shields.io/badge/Plugins-{len(data.get("plugins", []))}-green)](#plugins-list)',
5556
plugins_content)
56-
plugins_content = re.sub(r'<!--- Plugins Start -->.*<!--- Plugins End -->',
57-
f'<!--- Plugins Start -->\n{plugin_entries}<!--- Plugins End -->',
57+
plugins_content = re.sub(r'<!--- Plugins Start -->.*<!--- Plugins End -->',
58+
f'<!--- Plugins Start -->\n{plugin_entries}<!--- Plugins End -->',
5859
plugins_content, flags=re.DOTALL)
5960

6061
with open('PLUGINS.md', 'w') as f:
@@ -71,11 +72,11 @@ def generate_entry_md(entry, is_plugin=True, index=0):
7172
theme_entries += generate_entry_md(theme, is_plugin=False, index=i)
7273

7374
# Update Themes badge count and theme list section
74-
themes_content = re.sub(r'\[!\[Themes\].*?\]\(#themes-list\)',
75-
f'[![Themes](https://img.shields.io/badge/Themes-{len(themes)}-green)](#themes-list)',
75+
themes_content = re.sub(r'\[!\[Themes\].*?\]\(#themes-list\)',
76+
f'[![Themes](https://img.shields.io/badge/Themes-{len(themes)}-green)](#themes-list)',
7677
themes_content)
77-
themes_content = re.sub(r'<!--- THEMES START -->.*<!--- THEMES END -->',
78-
f'<!--- THEMES START -->\n{theme_entries}<!--- THEMES END -->',
78+
themes_content = re.sub(r'<!--- THEMES START -->.*<!--- THEMES END -->',
79+
f'<!--- THEMES START -->\n{theme_entries}<!--- THEMES END -->',
7980
themes_content, flags=re.DOTALL)
8081

8182
with open('THEMES.md', 'w') as f:

0 commit comments

Comments
 (0)