@@ -123,6 +123,12 @@ def add_assets(self):
123123 # 确保目标目录存在
124124 os .makedirs (os .path .dirname (dst_path ), exist_ok = True )
125125 shutil .copy2 (src_path , dst_path )
126+
127+ # 复制 sw.js 到根目录(PWA 需要 Service Worker 在根目录)
128+ sw_src = os .path .join (ASSETS_DIR , 'sw.js' )
129+ sw_dst = os .path .join (self .base_directory , 'sw.js' )
130+ if os .path .exists (sw_src ):
131+ shutil .copy2 (sw_src , sw_dst )
126132
127133
128134 def create_library_home (self ):
@@ -384,6 +390,8 @@ def cleanup(self):
384390 print (f"Cleaned up book: { book_info ['title' ]} , path: { middle_dir } " )
385391 if os .path .exists (os .path .join (self .output_dir , "index.html" )):
386392 os .remove (os .path .join (self .output_dir , "index.html" ))
393+ if os .path .exists (os .path .join (self .output_dir , "sw.js" )):
394+ os .remove (os .path .join (self .output_dir , "sw.js" ))
387395 if os .path .exists (os .path .join (self .output_dir , "assets" )):
388396 shutil .rmtree (os .path .join (self .output_dir , "assets" ), ignore_errors = True )
389397 if os .path .exists (os .path .join (self .output_dir , "book" )):
0 commit comments