File tree Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change 4
4
5
5
import htmlmin
6
6
from jsmin import jsmin
7
+ from cssmin import cssmin
7
8
from sphinx .application import Sphinx
8
9
from sphinx .util .fileutil import copy_asset_file
9
10
@@ -84,9 +85,21 @@ def minify_js_files(app, exception):
84
85
f .truncate ()
85
86
86
87
88
+ def minify_css_files (app , exception ):
89
+ for css in app .builder .css_files :
90
+ fn = os .path .join (app .builder .outdir , css )
91
+ if os .path .isfile (fn ):
92
+ with open (fn , 'r+' ) as f :
93
+ minified_css = cssmin (f .read ())
94
+ f .seek (0 )
95
+ f .write (minified_css )
96
+ f .truncate ()
97
+
98
+
87
99
def setup (app : Sphinx ) -> Dict [str , Any ]:
88
100
app .connect ('builder-inited' , copy_custom_files )
89
101
app .connect ('html-page-context' , insert_sidebar )
90
102
app .connect ('build-finished' , minify_js_files )
103
+ app .connect ('build-finished' , minify_css_files )
91
104
92
105
return {'parallel_read_safe' : True }
Original file line number Diff line number Diff line change 9
9
'sphinx' ,
10
10
'htmlmin' ,
11
11
'jsmin' ,
12
+ 'cssmin' ,
12
13
],
13
14
package_data = {
14
15
'deepmodeling_sphinx' : ['banner.html' ,
You can’t perform that action at this time.
0 commit comments