mirror of
https://github.com/imfing/hextra.git
synced 2025-08-23 06:26:44 -04:00
fix: CSS loading logic for production and theme dev environments (#691)
* fix: CSS loading logic for production and theme dev environments - Updated the CSS loading logic to differentiate between production and theme environments. * fix: streamline CSS loading logic for production and development environments - Refactored the CSS loading logic to ensure proper handling of stylesheets in both production and development modes. - Consolidated the CSS concatenation and minification process for production, while simplifying the development loading process. * fix: simplify development CSS loading in head partial - Updated the CSS loading logic in head.html to streamline the process for development environments by renaming the variable for clarity and ensuring proper handling of stylesheets.
This commit is contained in:
@@ -32,15 +32,20 @@
|
|||||||
{{- $customCss := resources.Get "css/custom.css" -}}
|
{{- $customCss := resources.Get "css/custom.css" -}}
|
||||||
{{- $variablesCss := resources.Get "css/variables.css" | resources.ExecuteAsTemplate "css/variables.css" . -}}
|
{{- $variablesCss := resources.Get "css/variables.css" | resources.ExecuteAsTemplate "css/variables.css" . -}}
|
||||||
|
|
||||||
{{- if hugo.IsProduction }}
|
{{- if and (not hugo.IsProduction) (eq hugo.Environment "theme") }}
|
||||||
{{- $styles := slice $variablesCss $mainCss $customCss | resources.Concat "css/compiled/main.css" | minify | fingerprint }}
|
{{- $devStyles := resources.Get "css/styles.css" | postCSS (dict "inlineImports" true) }}
|
||||||
<link rel="preload" href="{{ $styles.RelPermalink }}" as="style" integrity="{{ $styles.Data.Integrity }}" />
|
<link href="{{ $devStyles.RelPermalink }}" rel="stylesheet" />
|
||||||
<link href="{{ $styles.RelPermalink }}" rel="stylesheet" integrity="{{ $styles.Data.Integrity }}" />
|
|
||||||
{{- else }}
|
{{- else }}
|
||||||
{{- $styles := resources.Get "css/styles.css" | postCSS (dict "inlineImports" true) }}
|
{{- if hugo.IsProduction }}
|
||||||
<link href="{{ $styles.RelPermalink }}" rel="stylesheet" />
|
{{- $styles := slice $variablesCss $mainCss $customCss | resources.Concat "css/compiled/main.css" | minify | fingerprint }}
|
||||||
<link href="{{ $variablesCss.RelPermalink }}" rel="stylesheet" />
|
<link rel="preload" href="{{ $styles.RelPermalink }}" as="style" integrity="{{ $styles.Data.Integrity }}" />
|
||||||
<link href="{{ $customCss.RelPermalink }}" rel="stylesheet" />
|
<link href="{{ $styles.RelPermalink }}" rel="stylesheet" integrity="{{ $styles.Data.Integrity }}" />
|
||||||
|
{{- else }}
|
||||||
|
{{- $styles := resources.Get "css/compiled/main.css" -}}
|
||||||
|
<link href="{{ $styles.RelPermalink }}" rel="stylesheet" />
|
||||||
|
<link href="{{ $variablesCss.RelPermalink }}" rel="stylesheet" />
|
||||||
|
<link href="{{ $customCss.RelPermalink }}" rel="stylesheet" />
|
||||||
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|
||||||
|
|
||||||
@@ -77,11 +82,11 @@
|
|||||||
{{ $noop := .WordCount -}}
|
{{ $noop := .WordCount -}}
|
||||||
{{ if .Page.Store.Get "hasMath" -}}
|
{{ if .Page.Store.Get "hasMath" -}}
|
||||||
<!-- TODO: make url configurable -->
|
<!-- TODO: make url configurable -->
|
||||||
{{ $katexBaseUrl := "https://cdn.jsdelivr.net/npm/katex@latest/dist" }}
|
{{ $katexBaseUrl := "https://cdn.jsdelivr.net/npm/katex@latest/dist" }}
|
||||||
{{ $katexCssUrl := printf "%s/katex%s.css" $katexBaseUrl (cond hugo.IsProduction ".min" "") -}}
|
{{ $katexCssUrl := printf "%s/katex%s.css" $katexBaseUrl (cond hugo.IsProduction ".min" "") -}}
|
||||||
{{ $katexFontPattern := "url(fonts/" }}
|
{{ $katexFontPattern := "url(fonts/" }}
|
||||||
{{ $katexFontSubstituted := printf "url(%s/fonts/" $katexBaseUrl }}
|
{{ $katexFontSubstituted := printf "url(%s/fonts/" $katexBaseUrl }}
|
||||||
|
|
||||||
{{ with try (resources.GetRemote $katexCssUrl) -}}
|
{{ with try (resources.GetRemote $katexCssUrl) -}}
|
||||||
{{ with .Err -}}
|
{{ with .Err -}}
|
||||||
{{ errorf "Could not retrieve KaTeX css file from %s. Reason: %s." $katexCssUrl . -}}
|
{{ errorf "Could not retrieve KaTeX css file from %s. Reason: %s." $katexCssUrl . -}}
|
||||||
|
Reference in New Issue
Block a user