@@ -9,6 +9,7 @@ const HtmlWebpackPlugin = require("html-webpack-plugin");
9
9
const CopyPlugin = require ( "copy-webpack-plugin" ) ;
10
10
const OptimizeCssAssetsPlugin = require ( "optimize-css-assets-webpack-plugin" ) ;
11
11
const TerserPlugin = require ( "terser-webpack-plugin" ) ;
12
+ const dedent = require ( "dedent" ) ;
12
13
13
14
//
14
15
// Paths for various assets (sources and destinations)
@@ -29,57 +30,57 @@ const vendorPaths = {
29
30
// Cache-busting Jinja2 macros (`webpack-macros.html`) used in `layout.html`
30
31
//
31
32
function macroTemplate ( { compilation } ) {
32
- console . log ( Object . keys ( compilation . assets ) ) ;
33
- const indexes = Object . keys ( compilation . assets ) . filter (
34
- ( file ) => file . indexOf ( "/pydata-sphinx-theme." ) != - 1
35
- ) ;
36
- const css = indexes . filter ( ( file ) => file . endsWith ( ".css" ) ) ;
37
- const js = indexes . filter ( ( file ) => file . endsWith ( ".js" ) ) ;
33
+ const hash = compilation . hash ;
34
+ const css_files = [ "styles/theme.css" , "styles/pydata-sphinx-theme.css" ] ;
35
+ const js_files = [ "scripts/pydata-sphinx-theme.js" ] ;
38
36
39
- const stylesheet = ( css ) => {
40
- return `\
41
- <link href="{{ pathto('_static/styles/theme.css', 1) }}" rel="stylesheet">
42
- <link href="{{ pathto('_static/${ css } ', 1) }}" rel="stylesheet">` ;
43
- } ;
37
+ function stylesheet ( css ) {
38
+ return `<link href="{{ pathto('_static/${ css } ', 1) }}?digest=${ hash } " rel="stylesheet">` ;
39
+ }
44
40
45
- const preload = ( js ) => {
46
- return `<link rel="preload" as="script" href="{{ pathto('_static/${ js } ', 1) }}">` ;
47
- } ;
41
+ function preload ( js ) {
42
+ return `<link rel="preload" as="script" href="{{ pathto('_static/${ js } ', 1) }}?digest= ${ hash } ">` ;
43
+ }
48
44
49
- const script = ( js ) => {
50
- return `<script src="{{ pathto('_static/${ js } ', 1) }}"></script>` ;
51
- } ;
45
+ function script ( js ) {
46
+ return `<script src="{{ pathto('_static/${ js } ', 1) }}?digest= ${ hash } "></script>` ;
47
+ }
52
48
53
- return `<!-- these macros are generated by "yarn build:production". do not edit by hand. -->
54
- {% macro head_pre_icons() %}
55
- <link rel="stylesheet"
56
- href="{{ pathto('_static/vendor/fontawesome/${
57
- vendorVersions . fontAwesome
58
- } /css/all.min.css', 1) }}">
59
- <link rel="preload" as="font" type="font/woff2" crossorigin
60
- href="{{ pathto('_static/vendor/fontawesome/${
61
- vendorVersions . fontAwesome
62
- } /webfonts/fa-solid-900.woff2', 1) }}">
63
- <link rel="preload" as="font" type="font/woff2" crossorigin
64
- href="{{ pathto('_static/vendor/fontawesome/${
65
- vendorVersions . fontAwesome
66
- } /webfonts/fa-brands-400.woff2', 1) }}">
67
- {% endmacro %}
49
+ return dedent ( `\
50
+ <!--
51
+ All these macros are auto-generated and must **NOT** be edited by hand.
52
+ See the webpack.config.js file, to learn more about how this is generated.
53
+ -->
54
+ {% macro head_pre_icons() %}
55
+ <link rel="stylesheet"
56
+ href="{{ pathto('_static/vendor/fontawesome/${
57
+ vendorVersions . fontAwesome
58
+ } /css/all.min.css', 1) }}">
59
+ <link rel="preload" as="font" type="font/woff2" crossorigin
60
+ href="{{ pathto('_static/vendor/fontawesome/${
61
+ vendorVersions . fontAwesome
62
+ } /webfonts/fa-solid-900.woff2', 1) }}">
63
+ <link rel="preload" as="font" type="font/woff2" crossorigin
64
+ href="{{ pathto('_static/vendor/fontawesome/${
65
+ vendorVersions . fontAwesome
66
+ } /webfonts/fa-brands-400.woff2', 1) }}">
67
+ {% endmacro %}
68
68
69
- {% macro head_pre_fonts() %}
70
- {% endmacro %}
69
+ {% macro head_pre_fonts() %}
70
+ {% endmacro %}
71
71
72
- {% macro head_pre_bootstrap() %}
73
- ${ css . map ( stylesheet ) . join ( "\n" ) }
74
- {% endmacro %}
72
+ {% macro head_pre_bootstrap() %}
73
+ ${ css_files . map ( stylesheet ) . join ( "\n " ) }
74
+ {% endmacro %}
75
75
76
- {% macro head_js_preload() %}
77
- ${ js . map ( preload ) . join ( "\n" ) }
78
- {% endmacro %}
76
+ {% macro head_js_preload() %}
77
+ ${ js_files . map ( preload ) . join ( "\n " ) }
78
+ {% endmacro %}
79
79
80
- {% macro body_post() %}
81
- ${ js . map ( script ) . join ( "\n" ) }
82
- {% endmacro %}` ;
80
+ {% macro body_post() %}
81
+ ${ js_files . map ( script ) . join ( "\n " ) }
82
+ {% endmacro %}
83
+ ` ) ;
83
84
}
84
85
85
86
module . exports = {
0 commit comments