mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2025-01-18 19:00:24 +00:00
0505b36141
implements the first part, working for configured variants; for that, loading of stylesheets was overhauled by now merging all configured variants into one big stylesheet for each output format and loading this instead of one stylesheet per configured variant; previously @media print styles were applied on top of @media screen styles; this is now strictly isolated, which doesn't require styles like neon to revert styles for print anymore; this change was also used to implement the minify parameter, to shrink those generated stylesheets, making them shrink to 66% of their unminified size for the exampleSite; the theme switcher functionality is now completely independend of variant.js; the switch is now handled by in-page javascript which avoids waiting for external scripts to load, so switching can happen as early as possible; switching of themes is now implemented by just setting a data attribute to the html element, were previously a complex mechanism of dynamically loading of variant CSS files was implemented; the call for variant.js was removed in this changeset, making the generator broken and useless; this will be fixed with the next patch;
68 lines
No EOL
4.4 KiB
HTML
68 lines
No EOL
4.4 KiB
HTML
{{- $outputFormat := "html" }}
|
|
{{- with .Store.Get "relearnOutputFormat" }}
|
|
{{- $outputFormat = . }}
|
|
{{- else }}
|
|
{{- warnf "WARNING no key `relearnOutputFormat` found in page store, set one by providing the file `layouts/_default/view/storeOutputFormat.<MYOUTPUTFORMAT>.html` for your self-defined output format; see https://mcshelby.github.io/hugo-theme-relearn/introduction/releasenotes/6/#6-0-0" }}
|
|
{{- end }}
|
|
{{- $assetBusting := partialCached "assetbusting.gotmpl" . }}
|
|
{{- /* https://github.com/filamentgroup/loadCSS/blob/master/README.md#how-to-use */}}
|
|
<link href="{{"css/fontawesome-all.min.css" | relURL}}{{ $assetBusting }}" rel="stylesheet" media="print" onload="this.media='all';this.onload=null;"><noscript><link href="{{"css/fontawesome-all.min.css" | relURL}}{{ $assetBusting }}" rel="stylesheet"></noscript>
|
|
<link href="{{"css/auto-complete.css" | relURL}}{{ $assetBusting }}" rel="stylesheet" media="print" onload="this.media='all';this.onload=null;"><noscript><link href="{{"css/auto-complete.css" | relURL}}{{ $assetBusting }}" rel="stylesheet"></noscript>
|
|
<link href="{{"css/perfect-scrollbar.min.css" | relURL}}{{ $assetBusting }}" rel="stylesheet">
|
|
{{- $themevariants := partialCached "_relearn/themeVariants.gotmpl" . }}
|
|
{{- $minify := not hugo.IsServer }}
|
|
{{- if isset site.Params "minify" }}
|
|
{{- $minify = site.Params.minify }}
|
|
{{- end }}
|
|
{{- $min := cond $minify ".min" "" }}
|
|
<link href="{{(printf "css/theme%s.css" $min) | relURL}}{{ $assetBusting }}" rel="stylesheet">
|
|
<link href="{{(printf "css/format-%s%s.css" $outputFormat $min) | relURL}}{{ $assetBusting }}" rel="stylesheet">
|
|
<script>
|
|
window.relearn = window.relearn || {};
|
|
window.relearn.relBasePath='{{ partial "_relearn/relBasePath.gotmpl" . | safeJS }}';
|
|
window.relearn.relBaseUri='{{ partial "_relearn/relBaseUri.gotmpl" . | safeJS }}';
|
|
window.relearn.absBaseUri='{{ replaceRE "/*$" "" .Site.BaseURL | safeJS }}';
|
|
{{ printf "window.relearn.min = `%s`;" $min | safeJS }}
|
|
window.relearn.disableAnchorCopy={{ printf "%t" (eq .Site.Params.disableAnchorCopy true) | safeJS }};
|
|
window.relearn.disableAnchorScrolling={{ printf "%t" (eq .Site.Params.disableAnchorScrolling true) | safeJS }};
|
|
{{ "// variant stuff" | safeJS }}
|
|
{{- $quotedthemevariants := slice }}
|
|
{{- range $themevariants }}
|
|
{{- $quotedthemevariants = $quotedthemevariants | append (printf "'%s'" .identifier) }}
|
|
{{- end }}
|
|
window.variants && variants.init( [ {{ delimit $quotedthemevariants ", " | safeJS }} ] );
|
|
window.relearn.changeVariant = function(variant) {
|
|
document.documentElement.dataset.rThemeVariant = variant;
|
|
var old_variant = window.localStorage.getItem("R-theme-variant");
|
|
if (old_variant != variant) {
|
|
window.localStorage.setItem("R-theme-variant", variant);
|
|
document.dispatchEvent( new CustomEvent('themeVariantLoaded', { detail: { variant: variant } }) );
|
|
}
|
|
}
|
|
window.relearn.initVariant = function() {
|
|
var variant = window.localStorage.getItem("R-theme-variant") ?? "";
|
|
var el = document.querySelector("#R-select-variant");
|
|
if (variant && el) {
|
|
var options = Array.from(el.options);
|
|
if( options.some(option => option.value == variant) ){
|
|
el.value = variant;
|
|
}
|
|
else {
|
|
variant = options[0]?.value ?? "";
|
|
el.value = variant;
|
|
window.localStorage.setItem("R-theme-variant", variant);
|
|
}
|
|
}
|
|
document.documentElement.dataset.rThemeVariant = variant;
|
|
}
|
|
window.relearn.initVariant();
|
|
{{ "// translations" | safeJS }}
|
|
{{ printf "window.T_Copy_to_clipboard = `%s`;" (T `Copy-to-clipboard`) | safeJS }}
|
|
{{ printf "window.T_Copied_to_clipboard = `%s`;" (T `Copied-to-clipboard`) | safeJS }}
|
|
{{ printf "window.T_Copy_link_to_clipboard = `%s`;" (T `Copy-link-to-clipboard`) | safeJS }}
|
|
{{ printf "window.T_Link_copied_to_clipboard = `%s`;" (T `Link-copied-to-clipboard`) | safeJS }}
|
|
{{ printf "window.T_Reset_view = `%s`;" (T `Reset-view`) | safeJS }}
|
|
{{ printf "window.T_View_reset = `%s`;" (T `View-reset`) | safeJS }}
|
|
{{ printf "window.T_No_results_found = `%s`;" (T "No-results-found") | safeJS }}
|
|
{{ printf "window.T_N_results_found = `%s`;" (T "N-results-found") | safeJS }}
|
|
</script> |