@@ -68,8 +68,18 @@ pub(crate) fn rewrite_lol(
68
68
element!( "body" , body_handler) ,
69
69
// Append `vendored.css` before `rustdoc.css`, so that the duplicate copy of
70
70
// `normalize.css` will be overridden by the later version.
71
+ //
72
+ // Later rustdoc has `#mainThemeStyle` that could be used, but pre-2018 docs
73
+ // don't have this:
74
+ //
75
+ // https://github.com/rust-lang/rust/commit/003b2bc1c65251ec2fc80b78ed91c43fb35402ec
76
+ //
77
+ // Pre-2018 rustdoc also didn't have the resource suffix, but docs.rs was using a fork
78
+ // that had implemented it already then, so we can assume the css files are
79
+ // `<some path>/rustdoc-<some suffix>.css` and use the `-` to distinguish from the
80
+ // `rustdoc.static` path.
71
81
element!(
72
- "link[rel='stylesheet'][href*='rustdoc']" ,
82
+ "link[rel='stylesheet'][href*='rustdoc- ']" ,
73
83
|rustdoc_css: & mut Element | {
74
84
rustdoc_css. before( & tera_vendored_css, ContentType :: Html ) ;
75
85
Ok ( ( ) )
@@ -95,3 +105,50 @@ pub(crate) fn rewrite_lol(
95
105
96
106
Ok ( buffer)
97
107
}
108
+
109
+ #[ cfg( test) ]
110
+ mod test {
111
+ use crate :: test:: wrapper;
112
+
113
+ #[ test]
114
+ fn rewriting_only_injects_css_once ( ) {
115
+ wrapper ( |env| {
116
+ env. fake_release ( )
117
+ . name ( "testing" )
118
+ . version ( "0.1.0" )
119
+ // A somewhat representative rustdoc html file from 2016
120
+ . rustdoc_file_with ( "2016/index.html" , br#"
121
+ <html>
122
+ <head>
123
+ <meta charset="utf-8">
124
+ <link rel="stylesheet" type="text/css" href="../../../rustdoc-20160728-1.12.0-nightly-54c0dcfd6.css">
125
+ <link rel="stylesheet" type="text/css" href="../../../main-20160728-1.12.0-nightly-54c0dcfd6.css">
126
+ </head>
127
+ </html>
128
+ "# )
129
+ // A somewhat representative rustdoc html file from late 2022
130
+ . rustdoc_file_with ( "2022/index.html" , br#"
131
+ <html>
132
+ <head>
133
+ <meta charset="utf-8">
134
+ <link rel="preload" as="font" type="font/woff2" crossorigin="" href="/-/rustdoc.static/SourceSerif4-Regular-1f7d512b176f0f72.ttf.woff2">
135
+ <link rel="stylesheet" href="/-/rustdoc.static/normalize-76eba96aa4d2e634.css">
136
+ <link rel="stylesheet" href="/-/rustdoc.static/rustdoc-eabf764633b9d7be.css" id="mainThemeStyle">
137
+ <link rel="stylesheet" disabled="" href="/-/rustdoc.static/dark-e2f4109f2e82e3af.css">
138
+ <script src="/-/rustdoc.static/storage-d43fa987303ecbbb.js"></script>
139
+ <noscript><link rel="stylesheet" href="/-/rustdoc.static/noscript-13285aec31fa243e.css"></noscript>
140
+ </head>
141
+ </html>
142
+ "# )
143
+ . create ( ) ?;
144
+
145
+ let output = env. frontend ( ) . get ( "/testing/0.1.0/2016/" ) . send ( ) ?. text ( ) ?;
146
+ assert_eq ! ( output. matches( r#"href="/-/static/vendored.css"# ) . count( ) , 1 ) ;
147
+
148
+ let output = env. frontend ( ) . get ( "/testing/0.1.0/2022/" ) . send ( ) ?. text ( ) ?;
149
+ assert_eq ! ( output. matches( r#"href="/-/static/vendored.css"# ) . count( ) , 1 ) ;
150
+
151
+ Ok ( ( ) )
152
+ } ) ;
153
+ }
154
+ }
0 commit comments