From cc01d3f82f00e63bf0e84ab97f2015ac3e17b810 Mon Sep 17 00:00:00 2001 From: Chris Morgan Date: Sun, 29 Mar 2020 16:15:51 +0530 Subject: [PATCH] Make live reload work with missing `` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The HTML spec doesn’t require it, and I prefer to omit it. This has been bothering me for ages, but I hadn’t gotten round to fixing it yet. This can cause nominally invalid HTML to be emitted, if `` was omitted but `` was present, but that’s unlikely to happen, and this is for development purposes only, and the right thing will happen anyway in all environments (per browser behaviour and spec). I don’t think this warrants a changelog entry. --- components/site/src/lib.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/components/site/src/lib.rs b/components/site/src/lib.rs index a095e3b7..07a951b6 100644 --- a/components/site/src/lib.rs +++ b/components/site/src/lib.rs @@ -626,15 +626,17 @@ impl Site { } /// Inject live reload script tag if in live reload mode - fn inject_livereload(&self, html: String) -> String { + fn inject_livereload(&self, mut html: String) -> String { if let Some(port) = self.live_reload { - return html.replace( - "", - &format!( - r#""#, - port - ), + let script = format!( + r#""#, + port, ); + if let Some(index) = html.rfind("") { + html.insert_str(index, &script); + } else { + html.push_str(&script); + } } html