11# -----------------------------------------------------------
2- # Markdown Generator from plugins-and-themes.yml
2+ # Markdown Generator - plugins-and-themes.yml
33# -----------------------------------------------------------
44#
5- # This script generates and updates :
5+ # This script generates the following markdown files :
66# - PLUGINS.md
77# - THEMES.md
8- # - README.md (badge counts )
8+ # - README.md (badges section only )
99#
10- # It uses the validated data from plugins-and-themes.yml
11- # to build properly formatted markdown entries.
12- #
13- # This script should only be run after validation passes.
10+ # Relies on the validated data from plugins-and-themes.yml.
11+ # Should only be run after validate-yml.py passes.
1412#
1513# Usage:
1614# python scripts/generate.py
2523# -----------------------
2624# Load YAML data
2725# -----------------------
26+
2827with open ('data/plugins-and-themes.yml' , 'r' ) as f :
2928 data = yaml .safe_load (f )
3029
3130# -----------------------
3231# Markdown generator for each plugin/theme entry
3332# -----------------------
33+
3434def generate_entry_md (entry , is_plugin = True , index = 0 ):
3535 owner , repo_name = entry ['repo' ].split ('/' )
3636 sanitized_name = entry ['name' ].replace (' ' , '%20' )
3737
38+ # Plugin name, link, and release/download badges
3839 md = f"- ### [{ entry ['name' ]} ](https://github.com/{ entry ['repo' ]} ) <br>\n "
3940 md += f" [](https://github.com/{ entry ['repo' ]} /releases) "
4041 md += f"[](https://github.com/{ entry ['repo' ]} /releases/download/{ entry .get ('latest_release_tag' , 'latest' )} /{ sanitized_name } .jar)<br>\n "
4142
43+ # MC version and core plugin badge (plugins only)
4244 if is_plugin and 'mc_versions' in entry :
4345 mc_versions = entry ['mc_versions' ].replace ('-' , '--' ).replace ('.' , '%20' )
4446 md += f" <br>\n "
4547 if is_plugin and entry .get ('is_core' , False ):
4648 md += " <br>\n "
4749
50+ # Creator section with avatar
4851 md += f" **Creator**: <img src=\" { entry ['creator' ]['avatar' ]} \" width=\" 20\" height=\" 20\" > [{ entry ['creator' ]['name' ]} ]({ entry ['creator' ]['url' ]} )<br>\n "
4952
53+ # Description (cleaned of embedded images)
5054 cleaned_description = re .sub (r'!\[.*?\]\(.*?\)' , '' , entry ['description' ])
5155 md += f" { cleaned_description .strip ()} \n \n "
5256
57+ # Screenshots section (standard and YouTube thumbnails)
5358 if entry .get ('screenshots' ):
5459 md += " <details>\n <summary>Show Screenshots</summary>\n <p align=\" center\" >\n "
5560 for ss in entry ['screenshots' ]:
5661 youtube_match = re .match (r'https://img\.youtube\.com/vi/([^/]+)/[^/]+\.jpg' , ss ['url' ])
5762 if youtube_match :
5863 video_id = youtube_match .group (1 )
5964 video_url = f"https://www.youtube.com/watch?v={ video_id } "
60- md += f" <a href=\" { video_url } \" target=\" _blank\" ><img src=\" { ss ['url' ]} \" alt=\" { ss [ 'alt' ] } \" width=\" { ss .get ('width' , 250 )} \" ></a>\n "
65+ md += f" <a href=\" { video_url } \" target=\" _blank\" ><img src=\" { ss ['url' ]} \" alt=\" { ss . get ( 'alt' , '' ) } \" width=\" { ss .get ('width' , 250 )} \" ></a>\n "
6166 else :
62- md += f" <img src=\" { ss ['url' ]} \" alt=\" { ss [ 'alt' ] } \" width=\" { ss .get ('width' , 250 )} \" >\n "
67+ md += f" <img src=\" { ss ['url' ]} \" alt=\" { ss . get ( 'alt' , '' ) } \" width=\" { ss .get ('width' , 250 )} \" >\n "
6368 md += " </p>\n </details>\n \n "
6469
6570 md += "---\n \n "
@@ -68,48 +73,68 @@ def generate_entry_md(entry, is_plugin=True, index=0):
6873# -----------------------
6974# Count plugin and theme entries
7075# -----------------------
76+
7177plugin_count = len (data .get ("plugins" , []))
7278theme_count = len (data .get ("themes" , []) or [])
7379
7480# -----------------------
7581# Update PLUGINS.md
7682# -----------------------
83+
7784with open ('PLUGINS.md' , 'r' ) as f :
7885 plugins_content = f .read ()
7986
8087plugin_entries = '' .join (generate_entry_md (p , is_plugin = True , index = i ) for i , p in enumerate (data .get ('plugins' , [])))
81- plugins_content = re .sub (r'\[!\[Plugins\].*?\]\(#plugins-list\)' ,
82- f'[](#plugins-list)' ,
83- plugins_content )
8488
85- plugins_content = re .sub (r'<!--- Plugins Start -->.*<!--- Plugins End -->' ,
86- f'<!--- Plugins Start -->\n { plugin_entries } <!--- Plugins End -->' ,
87- plugins_content , flags = re .DOTALL )
89+ # Update plugin badge count
90+ plugins_content = re .sub (
91+ r'\[!\[Plugins\].*?\]\(#plugins-list\)' ,
92+ f'[](#plugins-list)' ,
93+ plugins_content
94+ )
95+
96+ # Inject plugin entries between comments
97+ plugins_content = re .sub (
98+ r'<!--- Plugins Start -->.*<!--- Plugins End -->' ,
99+ f'<!--- Plugins Start -->\n { plugin_entries } <!--- Plugins End -->' ,
100+ plugins_content ,
101+ flags = re .DOTALL
102+ )
88103
89104with open ('PLUGINS.md' , 'w' ) as f :
90105 f .write (plugins_content )
91106
92107# -----------------------
93108# Update THEMES.md
94109# -----------------------
110+
95111with open ('THEMES.md' , 'r' ) as f :
96112 themes_content = f .read ()
97113
98114theme_entries = '' .join (generate_entry_md (t , is_plugin = False , index = i ) for i , t in enumerate (data .get ('themes' , [])))
99- themes_content = re .sub (r'\[!\[Themes\].*?\]\(#themes-list\)' ,
100- f'[](#themes-list)' ,
101- themes_content )
102115
103- themes_content = re .sub (r'<!--- THEMES START -->.*<!--- THEMES END -->' ,
104- f'<!--- THEMES START -->\n { theme_entries } <!--- THEMES END -->' ,
105- themes_content , flags = re .DOTALL )
116+ # Update theme badge count
117+ themes_content = re .sub (
118+ r'\[!\[Themes\].*?\]\(#themes-list\)' ,
119+ f'[](#themes-list)' ,
120+ themes_content
121+ )
122+
123+ # Inject theme entries between comments
124+ themes_content = re .sub (
125+ r'<!--- THEMES START -->.*<!--- THEMES END -->' ,
126+ f'<!--- THEMES START -->\n { theme_entries } <!--- THEMES END -->' ,
127+ themes_content ,
128+ flags = re .DOTALL
129+ )
106130
107131with open ('THEMES.md' , 'w' ) as f :
108132 f .write (themes_content )
109133
110134# -----------------------
111135# Update badge counts in README.md
112136# -----------------------
137+
113138with open ('README.md' , 'r' ) as f :
114139 readme_original = f .read ()
115140
@@ -127,6 +152,7 @@ def generate_entry_md(entry, is_plugin=True, index=0):
127152 count = 1
128153)
129154
155+ # Only write if changes were made
130156if readme_original != readme_updated :
131157 with open ('README.md' , 'w' ) as f :
132158 f .write (readme_updated )
0 commit comments