mirror of
https://github.com/imfing/hextra.git
synced 2025-07-01 09:47:15 -04:00

* 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.
104 lines
4.2 KiB
HTML
104 lines
4.2 KiB
HTML
<head>
|
||
<meta charset="utf-8" />
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||
{{- $noindex := .Params.noindex | default false -}}
|
||
{{ if and (hugo.IsProduction) (not $noindex) -}}
|
||
<meta name="robots" content="index, follow" />
|
||
{{ else -}}
|
||
<meta name="robots" content="noindex, nofollow" />
|
||
{{ end -}}
|
||
{{ partialCached "favicons.html" . -}}
|
||
<title>
|
||
{{- if .IsHome -}}
|
||
{{ .Site.Title -}}
|
||
{{ else -}}
|
||
{{ with .Title }}{{ . }} –{{ end -}}
|
||
{{ .Site.Title -}}
|
||
{{ end -}}
|
||
</title>
|
||
<meta name="description" content="{{ partial "utils/page-description.html" . }}" />
|
||
|
||
{{- with .Params.canonical -}}
|
||
<link rel="canonical" href="{{ . }}" itemprop="url" />
|
||
{{- else -}}
|
||
<link rel="canonical" href="{{ .Permalink }}" itemprop="url" />
|
||
{{- end -}}
|
||
|
||
{{- partial "opengraph.html" . -}}
|
||
{{- template "_internal/schema.html" . -}}
|
||
{{- template "_internal/twitter_cards.html" . -}}
|
||
|
||
{{- $mainCss := resources.Get "css/compiled/main.css" -}}
|
||
{{- $customCss := resources.Get "css/custom.css" -}}
|
||
{{- $variablesCss := resources.Get "css/variables.css" | resources.ExecuteAsTemplate "css/variables.css" . -}}
|
||
|
||
{{- if and (not hugo.IsProduction) (eq hugo.Environment "theme") }}
|
||
{{- $devStyles := resources.Get "css/styles.css" | postCSS (dict "inlineImports" true) }}
|
||
<link href="{{ $devStyles.RelPermalink }}" rel="stylesheet" />
|
||
{{- else }}
|
||
{{- if hugo.IsProduction }}
|
||
{{- $styles := slice $variablesCss $mainCss $customCss | resources.Concat "css/compiled/main.css" | minify | fingerprint }}
|
||
<link rel="preload" href="{{ $styles.RelPermalink }}" as="style" integrity="{{ $styles.Data.Integrity }}" />
|
||
<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 }}
|
||
|
||
|
||
<!-- Google Analytics -->
|
||
{{- if and hugo.IsProduction .Site.Config.Services.GoogleAnalytics.ID }}
|
||
<link rel="preconnect" href="https://www.googletagmanager.com" crossorigin />
|
||
{{ partial "google-analytics.html" . -}}
|
||
{{- end }}
|
||
|
||
<script>
|
||
/* Initialize light/dark mode */
|
||
const defaultTheme = '{{ site.Params.theme.default | default `system`}}';
|
||
|
||
const setDarkTheme = () => {
|
||
document.documentElement.classList.add("dark");
|
||
document.documentElement.style.colorScheme = "dark";
|
||
}
|
||
const setLightTheme = () => {
|
||
document.documentElement.classList.remove("dark");
|
||
document.documentElement.style.colorScheme = "light";
|
||
}
|
||
|
||
if ("color-theme" in localStorage) {
|
||
localStorage.getItem("color-theme") === "dark" ? setDarkTheme() : setLightTheme();
|
||
} else {
|
||
defaultTheme === "dark" ? setDarkTheme() : setLightTheme();
|
||
if (defaultTheme === "system") {
|
||
window.matchMedia("(prefers-color-scheme: dark)").matches ? setDarkTheme() : setLightTheme();
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<!-- KaTeX-->
|
||
{{ $noop := .WordCount -}}
|
||
{{ if .Page.Store.Get "hasMath" -}}
|
||
<!-- TODO: make url configurable -->
|
||
{{ $katexBaseUrl := "https://cdn.jsdelivr.net/npm/katex@latest/dist" }}
|
||
{{ $katexCssUrl := printf "%s/katex%s.css" $katexBaseUrl (cond hugo.IsProduction ".min" "") -}}
|
||
{{ $katexFontPattern := "url(fonts/" }}
|
||
{{ $katexFontSubstituted := printf "url(%s/fonts/" $katexBaseUrl }}
|
||
|
||
{{ with try (resources.GetRemote $katexCssUrl) -}}
|
||
{{ with .Err -}}
|
||
{{ errorf "Could not retrieve KaTeX css file from %s. Reason: %s." $katexCssUrl . -}}
|
||
{{ else with.Value -}}
|
||
{{ $katexCssContent := strings.Replace .Content $katexFontPattern $katexFontSubstituted }}
|
||
{{ with resources.FromString (printf "css/katex%s.css" (cond hugo.IsProduction ".min" "")) $katexCssContent -}}
|
||
<link rel="stylesheet" href="{{- .RelPermalink -}}" integrity="{{- . | fingerprint -}}" crossorigin="anonymous" />
|
||
{{ end -}}
|
||
{{ end -}}
|
||
{{ end -}}
|
||
{{ end -}}
|
||
|
||
{{ partial "custom/head-end.html" . -}}
|
||
</head>
|