mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2025-01-18 10:50: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) {
|
if (variant != this.customvariantname) {
|
||||||
window.localStorage.setItem(window.relearn.absBaseUri + '/customvariant', variant);
|
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 + '/variant', this.customvariantname);
|
||||||
window.localStorage.setItem(window.relearn.absBaseUri + '/customvariantstylesheet', stylesheet);
|
window.localStorage.setItem(window.relearn.absBaseUri + '/customvariantstylesheet', stylesheet);
|
||||||
this.updateCustomVariantStyles(stylesheet);
|
this.updateCustomVariantStyles(stylesheet);
|
||||||
|
@ -182,19 +182,24 @@ var variants = {
|
||||||
// CSS download
|
// CSS download
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
|
||||||
generateStylesheet: function () {
|
generateStylesheet: function (variant) {
|
||||||
var customvariantbase = window.localStorage.getItem(window.relearn.absBaseUri + '/customvariant') ?? window.localStorage.getItem(window.relearn.absBaseUri + '/variant');
|
var style = null;
|
||||||
var base_style = this.findLoadedStylesheet('R-format-style', [':root:not([data-r-output-format="print"])[data-r-theme-variant="' + customvariantbase + '"]']);
|
if (variant != this.customvariantname) {
|
||||||
if (!base_style) {
|
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');
|
alert('There is nothing to be generated as auto mode variants will be generated by Hugo');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
var variant = this.customvariantname;
|
style = this.findLoadedStylesheet('R-variant-styles-' + variant, [':root:not([data-r-output-format="print"])[data-r-theme-variant="' + variant + '"]']);
|
||||||
var custom_style = this.findLoadedStylesheet('R-variant-styles-' + variant, [':root:not([data-r-output-format="print"])[data-r-theme-variant="' + variant + '"]']);
|
if (!style) {
|
||||||
if (!custom_style) {
|
var customvariantbase = window.localStorage.getItem(window.relearn.absBaseUri + '/customvariant');
|
||||||
variant = customvariantbase;
|
style = this.findLoadedStylesheet('R-format-style', [':root:not([data-r-output-format="print"])[data-r-theme-variant="' + customvariantbase + '"]']);
|
||||||
custom_style = base_style;
|
if (!style) {
|
||||||
|
alert('There is nothing to be generated as auto mode variants will be generated by Hugo');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var style =
|
var style =
|
||||||
|
@ -204,7 +209,7 @@ var variants = {
|
||||||
' */\n' +
|
' */\n' +
|
||||||
this.variantvariables.reduce(
|
this.variantvariables.reduce(
|
||||||
function (a, e) {
|
function (a, e) {
|
||||||
return a + this.generateColorVariable(e, custom_style);
|
return a + this.generateColorVariable(e, style);
|
||||||
}.bind(this),
|
}.bind(this),
|
||||||
''
|
''
|
||||||
) +
|
) +
|
||||||
|
@ -229,7 +234,7 @@ var variants = {
|
||||||
var variant = window.localStorage.getItem(window.relearn.absBaseUri + '/variant');
|
var variant = window.localStorage.getItem(window.relearn.absBaseUri + '/variant');
|
||||||
var customvariantbase = window.localStorage.getItem(window.relearn.absBaseUri + '/customvariant');
|
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.');
|
alert('You already have changes based on the "' + customvariantbase + '" variant. Please proceed editing the custom variant, reset your changes or ignore this message.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -278,6 +283,10 @@ var variants = {
|
||||||
resetVariant: function () {
|
resetVariant: function () {
|
||||||
var customvariant = window.localStorage.getItem(window.relearn.absBaseUri + '/customvariant');
|
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?')) {
|
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 + '/customvariant');
|
||||||
window.localStorage.removeItem(window.relearn.absBaseUri + '/customvariantstylesheet');
|
window.localStorage.removeItem(window.relearn.absBaseUri + '/customvariantstylesheet');
|
||||||
window.localStorage.setItem(window.relearn.absBaseUri + '/variant', customvariant);
|
window.localStorage.setItem(window.relearn.absBaseUri + '/variant', customvariant);
|
||||||
|
@ -290,10 +299,11 @@ var variants = {
|
||||||
},
|
},
|
||||||
|
|
||||||
getStylesheet: function () {
|
getStylesheet: function () {
|
||||||
var style = this.generateStylesheet();
|
var variant = window.localStorage.getItem(window.relearn.absBaseUri + '/variant');
|
||||||
|
var style = this.generateStylesheet(variant);
|
||||||
if (style) {
|
if (style) {
|
||||||
console.log(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