From 6c2f92da185e0c6cae95e628f81e6110cd698753 Mon Sep 17 00:00:00 2001 From: MJacred Date: Tue, 31 Jan 2023 17:15:47 +0100 Subject: [PATCH] Allow merging website's custom styling with theme --- README.md | 6 ++++++ exampleSite/config.yaml | 1 + layouts/partials/css.html | 36 ++++++++++++++++++++++++++---------- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 434fb519..825e5059 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,12 @@ Visual * layouts/partials/javascript.html will fetch and insert it in each page including this partial (as of now: `baseof.html`, `single.html`) +### Custom Javascript + +* Write custom sass file in your `assets` folder and declare the path in config file using `params.customCSS` + * The styling will be merged with this theme + + ### Content Shortcodes [Hugo Docs](https://gohugo.io/content-management/shortcodes/) diff --git a/exampleSite/config.yaml b/exampleSite/config.yaml index 2a5549dc..f1617fdf 100644 --- a/exampleSite/config.yaml +++ b/exampleSite/config.yaml @@ -354,6 +354,7 @@ params: # ------------------------------------------ customJS: - "js/main.js" + customCSS: "/css/style.sass" # ------------------------------------------ # Theme Color Palette # ------------------------------------------ diff --git a/layouts/partials/css.html b/layouts/partials/css.html index 0982d0d3..8b460132 100644 --- a/layouts/partials/css.html +++ b/layouts/partials/css.html @@ -1,17 +1,33 @@ -{{- $inServerMode := .Site.IsServer }} -{{- $sass := "style.sass" }} -{{- $cssTarget := "css/style.css" }} -{{- $cssOpts := cond ($inServerMode) (dict "targetPath" $cssTarget "enableSourceMap" true "transpiler" "libsass" "vars" site.Params.style) (dict "targetPath" $cssTarget "outputStyle" "compressed" "transpiler" "libsass" "vars" site.Params.style) }} - +{{- $inServerMode := .Site.IsServer }} + +{{- $inviCSSTarget := "css/style.css" }} +{{ if .Site.Params.customCSS }} + {{- $inviCSSTarget = "css/temp_invi_style.css" }} +{{- end }} +{{- $inviCSSOpts := cond ($inServerMode) + (dict "targetPath" $inviCSSTarget "enableSourceMap" true "transpiler" "libsass" "vars" site.Params.style) + (dict "targetPath" $inviCSSTarget "outputStyle" "compressed" "transpiler" "libsass" "vars" site.Params.style) +}} +{{- $inviSass := resources.Get "style.sass" | toCSS $inviCSSOpts }} +{{- $cssResource := $inviSass }} +{{ with .Site.Params.customCSS }} + {{- $customCSSTarget := "css/temp_custom_style.css" }} + {{- $customCSSOpts := cond ($inServerMode) + (dict "targetPath" $customCSSTarget "enableSourceMap" true "transpiler" "libsass" "vars" site.Params.style) + (dict "targetPath" $customCSSTarget "outputStyle" "compressed" "transpiler" "libsass" "vars" site.Params.style) + }} + {{- $customSass := resources.Get . | toCSS $customCSSOpts }} + {{- $cssResource = slice $inviSass $customSass | resources.Concat "css/style.css" }} +{{- end }} {{- if $inServerMode }} -{{- $css := resources.Get $sass | toCSS $cssOpts }} - + {{- $css := $cssResource }} + {{- else }} -{{- $css := resources.Get $sass | toCSS $cssOpts | minify | fingerprint }} - + {{- $css := $cssResource | minify }} + {{- end }} - +