diff --git a/app/assets/javascripts/discourse/app/index.html b/app/assets/javascripts/discourse/app/index.html index 28558df7ded..65220326aa9 100644 --- a/app/assets/javascripts/discourse/app/index.html +++ b/app/assets/javascripts/discourse/app/index.html @@ -27,6 +27,15 @@
+ {{bootstrap-content-for "hidden-login-form"}} {{bootstrap-content-for "preloaded"}} diff --git a/app/assets/javascripts/discourse/lib/bootstrap-json/index.js b/app/assets/javascripts/discourse/lib/bootstrap-json/index.js index d75ea398fa2..35c42809dd0 100644 --- a/app/assets/javascripts/discourse/lib/bootstrap-json/index.js +++ b/app/assets/javascripts/discourse/lib/bootstrap-json/index.js @@ -20,6 +20,25 @@ function htmlTag(buffer, bootstrap) { buffer.push(``); } +function bareStylesheets(buffer, bootstrap) { + (bootstrap.stylesheets || []).forEach((s) => { + if (s.theme_id) { + return; + } + let attrs = []; + if (s.media) { + attrs.push(`media="${s.media}"`); + } + if (s.target) { + attrs.push(`data-target="${s.target}"`); + } + let link = `\n`; + buffer.push(link); + }); +} + function head(buffer, bootstrap) { if (bootstrap.csrf_token) { buffer.push(``); @@ -72,9 +91,13 @@ function head(buffer, bootstrap) { buffer.push(bootstrap.html.before_head_close); } +function localeScript(buffer, bootstrap) { + buffer.push(``); +} + function beforeScriptLoad(buffer, bootstrap) { buffer.push(bootstrap.html.before_script_load); - buffer.push(``); + localeScript(buffer, bootstrap); (bootstrap.extra_locales || []).forEach((l) => buffer.push(``) ); @@ -119,6 +142,8 @@ const BUILDERS = { "hidden-login-form": hiddenLoginForm, preloaded: preloaded, "body-footer": bodyFooter, + "locale-script": localeScript, + "bare-stylesheets": bareStylesheets, }; function replaceIn(bootstrap, template, id) { @@ -136,11 +161,11 @@ function applyBootstrap(bootstrap, template) { return template; } -function decorateIndex(baseUrl, headers) { +function decorateIndex(assetPath, baseUrl, headers) { // eslint-disable-next-line return new Promise((resolve, reject) => { fs.readFile( - path.join(process.cwd(), "dist", "index.html"), + path.join(process.cwd(), "dist", assetPath), "utf8", (err, template) => { getJSON(`${baseUrl}/bootstrap.json`, null, headers) @@ -190,9 +215,13 @@ module.exports = { } if (!isFile) { + assetPath = "index.html"; + } + + if (assetPath.endsWith("index.html")) { let template; try { - template = await decorateIndex(proxy, req.headers); + template = await decorateIndex(assetPath, proxy, req.headers); } catch (e) { template = ` @@ -201,7 +230,7 @@ module.exports = { `; } - res.send(template); + return res.send(template); } } } finally { diff --git a/app/assets/javascripts/discourse/public/assets/scripts/discourse-boot.js b/app/assets/javascripts/discourse/public/assets/scripts/discourse-boot.js index 903de3dba6a..a4811cab76a 100644 --- a/app/assets/javascripts/discourse/public/assets/scripts/discourse-boot.js +++ b/app/assets/javascripts/discourse/public/assets/scripts/discourse-boot.js @@ -177,6 +177,6 @@ const config = JSON.parse( decodeURIComponent(element.getAttribute("content")) ); - const app = require(`${config.modulePrefix}/app`)["default"].create(config); - app.start(); + const event = new CustomEvent("discourse-booted", { detail: config }); + document.dispatchEvent(event); })(); diff --git a/app/assets/javascripts/discourse/tests/index.html b/app/assets/javascripts/discourse/tests/index.html index 526fa4bef6a..c5213f1b10c 100644 --- a/app/assets/javascripts/discourse/tests/index.html +++ b/app/assets/javascripts/discourse/tests/index.html @@ -27,6 +27,8 @@ } + {{bootstrap-content-for "locale-script"}} + {{bootstrap-content-for "bare-stylesheets"}} {{content-for "body"}}