@@ -83,16 +83,39 @@ def do_GET(self):
8383 return
8484 # Handle extensionless URLs (e.g., /about -> /about.html)
8585 import os
86+
8687 original_path = self .path
87-
88+
8889 # Skip rewriting for files with extensions, directories, or static assets
89- if original_path and not original_path .endswith (('.html' , '.css' , '.js' , '.png' , '.jpg' , '.jpeg' , '.gif' , '.svg' , '.ico' , '.json' , '.xml' )) and not original_path .endswith ('/' ):
90+ if (
91+ original_path
92+ and not original_path .endswith (
93+ (
94+ ".html" ,
95+ ".css" ,
96+ ".js" ,
97+ ".png" ,
98+ ".jpg" ,
99+ ".jpeg" ,
100+ ".gif" ,
101+ ".svg" ,
102+ ".ico" ,
103+ ".json" ,
104+ ".xml" ,
105+ )
106+ )
107+ and not original_path .endswith ("/" )
108+ ):
90109 # Check if .html version exists
91- html_path = original_path + '.html' if not original_path .endswith ('/' ) else original_path + 'index.html'
92- file_path = os .path .join (output_dir , html_path .lstrip ('/' ))
110+ html_path = (
111+ original_path + ".html"
112+ if not original_path .endswith ("/" )
113+ else original_path + "index.html"
114+ )
115+ file_path = os .path .join (output_dir , html_path .lstrip ("/" ))
93116 if os .path .exists (file_path ) and os .path .isfile (file_path ):
94117 self .path = html_path
95-
118+
96119 super ().do_GET ()
97120
98121 def log_message (self , format , * args ):
@@ -117,35 +140,35 @@ def shutdown_server():
117140 if is_shutting_down .is_set ():
118141 return
119142 is_shutting_down .set ()
120-
143+
121144 print ("\n Shutting down server..." )
122145 shutdown_event .set ()
123-
146+
124147 # Close socket immediately to break serve_forever() loop
125148 try :
126149 httpd .socket .close ()
127150 except Exception :
128151 pass
129-
152+
130153 # Stop file watcher
131154 try :
132155 observer .stop ()
133156 observer .join (timeout = 0.5 )
134157 except Exception :
135158 pass
136-
159+
137160 # Shutdown server
138161 try :
139162 httpd .shutdown ()
140163 except Exception :
141164 pass
142-
165+
143166 # Close server socket
144167 try :
145168 httpd .server_close ()
146169 except Exception :
147170 pass
148-
171+
149172 print ("✓ Server stopped" )
150173
151174 def signal_handler (sig , frame ):
@@ -158,7 +181,7 @@ def signal_handler(sig, frame):
158181 threading .Thread (target = shutdown_server , daemon = True ).start ()
159182
160183 signal .signal (signal .SIGINT , signal_handler )
161- if hasattr (signal , ' SIGTERM' ):
184+ if hasattr (signal , " SIGTERM" ):
162185 signal .signal (signal .SIGTERM , signal_handler )
163186
164187 try :
0 commit comments