mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2025-01-18 02:40:24 +00:00
variantgenerator: always download the selected variant #757
This commit is contained in:
parent
5208766085
commit
b6ba7c20f2
2 changed files with 29 additions and 19 deletions
|
@ -1 +1 @@
|
|||
7.1.1+d159c08b16e0c832bf9c69f4f1abd462795ce747
|
||||
7.1.1+5208766085455f22d233fc14c948a1522e5d805e
|
|
@ -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) {
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
} 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');
|
||||
}
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in a new issue