From b6ba7c20f2882e8a1467fae0b0fc51a220a1717b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Weber?= Date: Sun, 8 Dec 2024 01:43:49 +0100 Subject: [PATCH] variantgenerator: always download the selected variant #757 --- layouts/partials/version.txt | 2 +- static/js/variant.js | 46 ++++++++++++++++++++++-------------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/layouts/partials/version.txt b/layouts/partials/version.txt index 899005027d..c05bb2e7dd 100644 --- a/layouts/partials/version.txt +++ b/layouts/partials/version.txt @@ -1 +1 @@ -7.1.1+d159c08b16e0c832bf9c69f4f1abd462795ce747 \ No newline at end of file +7.1.1+5208766085455f22d233fc14c948a1522e5d805e \ No newline at end of file diff --git a/static/js/variant.js b/static/js/variant.js index 29a072ca02..c644d779cc 100644 --- a/static/js/variant.js +++ b/static/js/variant.js @@ -98,7 +98,7 @@ var variants = { if (variant != this.customvariantname) { window.localStorage.setItem(window.relearn.absBaseUri + '/customvariant', variant); } - var stylesheet = this.generateStylesheet(); + var stylesheet = this.generateStylesheet(this.customvariantname); window.localStorage.setItem(window.relearn.absBaseUri + '/variant', this.customvariantname); window.localStorage.setItem(window.relearn.absBaseUri + '/customvariantstylesheet', stylesheet); this.updateCustomVariantStyles(stylesheet); @@ -182,19 +182,24 @@ var variants = { // CSS download // ------------------------------------------------------------------------ - generateStylesheet: function () { - var customvariantbase = window.localStorage.getItem(window.relearn.absBaseUri + '/customvariant') ?? window.localStorage.getItem(window.relearn.absBaseUri + '/variant'); - var base_style = this.findLoadedStylesheet('R-format-style', [':root:not([data-r-output-format="print"])[data-r-theme-variant="' + customvariantbase + '"]']); - if (!base_style) { - alert('There is nothing to be generated as auto mode variants will be generated by Hugo'); - return; - } - - var variant = this.customvariantname; - var custom_style = this.findLoadedStylesheet('R-variant-styles-' + variant, [':root:not([data-r-output-format="print"])[data-r-theme-variant="' + variant + '"]']); - if (!custom_style) { - variant = customvariantbase; - custom_style = base_style; + generateStylesheet: function (variant) { + var style = null; + if (variant != this.customvariantname) { + style = this.findLoadedStylesheet('R-format-style', [':root:not([data-r-output-format="print"])[data-r-theme-variant="' + variant + '"]']); + if (!style) { + alert('There is nothing to be generated as auto mode variants will be generated by Hugo'); + return; + } + } else { + style = this.findLoadedStylesheet('R-variant-styles-' + variant, [':root:not([data-r-output-format="print"])[data-r-theme-variant="' + variant + '"]']); + if (!style) { + var customvariantbase = window.localStorage.getItem(window.relearn.absBaseUri + '/customvariant'); + style = this.findLoadedStylesheet('R-format-style', [':root:not([data-r-output-format="print"])[data-r-theme-variant="' + customvariantbase + '"]']); + if (!style) { + alert('There is nothing to be generated as auto mode variants will be generated by Hugo'); + return; + } + } } var style = @@ -204,7 +209,7 @@ var variants = { ' */\n' + this.variantvariables.reduce( function (a, e) { - return a + this.generateColorVariable(e, custom_style); + return a + this.generateColorVariable(e, style); }.bind(this), '' ) + @@ -229,7 +234,7 @@ var variants = { var variant = window.localStorage.getItem(window.relearn.absBaseUri + '/variant'); var customvariantbase = window.localStorage.getItem(window.relearn.absBaseUri + '/customvariant'); - if (customvariantbase && customvariantbase != variant) { + if (customvariantbase && this.customvariantname != variant) { alert('You already have changes based on the "' + customvariantbase + '" variant. Please proceed editing the custom variant, reset your changes or ignore this message.'); return; } @@ -278,6 +283,10 @@ var variants = { resetVariant: function () { var customvariant = window.localStorage.getItem(window.relearn.absBaseUri + '/customvariant'); if (customvariant && confirm('You have made changes to your custom variant. Are you sure you want to reset all changes?')) { + var variant = window.localStorage.getItem(window.relearn.absBaseUri + '/variant'); + if (variant != this.customvariantname) { + customvariant = variant; + } window.localStorage.removeItem(window.relearn.absBaseUri + '/customvariant'); window.localStorage.removeItem(window.relearn.absBaseUri + '/customvariantstylesheet'); window.localStorage.setItem(window.relearn.absBaseUri + '/variant', customvariant); @@ -290,10 +299,11 @@ var variants = { }, getStylesheet: function () { - var style = this.generateStylesheet(); + var variant = window.localStorage.getItem(window.relearn.absBaseUri + '/variant'); + var style = this.generateStylesheet(variant); if (style) { console.log(style); - this.download(style, 'text/css', 'theme-' + this.customvariantname + '.css'); + this.download(style, 'text/css', 'theme-' + variant + '.css'); } },