A platform for community discussion. Free, open, simple.
FEATURE: maintain preview theme, while previewing
Samba15273d3fd2
diff --git a/app/assets/javascripts/discourse/initializers/live-development.js.es6 b/app/assets/javascripts/discourse/initializers/live-development.js.es6index c6dba5fdfcf..de482647b35 100644--- a/app/assets/javascripts/discourse/initializers/live-development.js.es6+++ b/app/assets/javascripts/discourse/initializers/live-development.js.es6@@ -7,6 +7,28 @@ export default {initialize(container) {const messageBus = container.lookup('message-bus:main');+ if (window.history && window.location.search.indexOf("?preview_theme_key=") === 0) {+ // force preview theme key to always be carried along+ const themeKey = window.location.search.slice(19).split('&')[0];+ if (themeKey.match(/^[a-z0-9-]+$/i)) {+ const patchState = function(f) {+ const patched = window.history[f];++ window.history[f] = function(stateObj, name, url) {+ if (url.indexOf("preview_theme_key=") === -1) {+ const joiner = url.indexOf("?") === -1 ? "?" : "&";+ url = `${url}${joiner}preview_theme_key=${themeKey}`;+ }++ return patched.call(window.history, stateObj, name, url);+ };+ };+ patchState("replaceState");+ patchState("pushState");+ }++ }+// Custom header changes$('header.custom').each(function() {const header = $(this);diff --git a/app/controllers/admin/themes_controller.rb b/app/controllers/admin/themes_controller.rbindex 77fb2009d1c..99b4caa3bd7 100644--- a/app/controllers/admin/themes_controller.rb+++ b/app/controllers/admin/themes_controller.rb@@ -7,8 +7,7 @@ class Admin::ThemesController < Admin::AdminControllerdef preview@theme = Theme.find(params[:id])-- redirect_to path("/"), flash: { preview_theme_key: @theme.key }+ redirect_to path("/?preview_theme_key=#{@theme.key}")enddef upload_assetdiff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rbindex e02d7343368..f2a7b475012 100644--- a/app/controllers/application_controller.rb+++ b/app/controllers/application_controller.rb@@ -315,7 +315,7 @@ class ApplicationController < ActionController::Baseresolve_safe_modereturn if request.env[NO_CUSTOM]- theme_key = flash[:preview_theme_key]+ theme_key = request[:preview_theme_key]user_option = current_user&.user_option