Skip to content

Commit

Permalink
ci: add the hb/assets/css-resource partial (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
razonyang committed Jan 25, 2024
1 parent ac34624 commit eed7546
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 50 deletions.
53 changes: 53 additions & 0 deletions layouts/partials/hb/assets/css-resource.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{{- $dirs := slice "" }}
{{/* Check if there is RTL site. */}}
{{- if where site.Sites "Language.LanguageDirection" "rtl" }}
{{- $dirs = $dirs | append "rtl" }}
{{- end }}
{{- $page := . }}
{{- $params := $page.Site.Params }}
{{- $context := dict
"params" $params
}}
{{- $res := false }}
{{- $bundle := default "hb" $params.hb.css_bundle_name }}
{{- range $dir := $dirs }}
{{- $rtl := eq $dir "rtl" }}
{{- $suffix := cond $rtl ".rtl" "" }}
{{/* SCSS options. */}}
{{- $options := dict
"targetPath" (printf "css/%s%s.css" $bundle $suffix)
"enableSourceMap" hugo.IsProduction
"vars" site.Params.hb.styles
}}
{{- if hugo.IsProduction }}
{{- $options = merge $options (dict
"outputStyle" "compressed")
}}
{{- end }}
{{/* Load style template. */}}
{{- $tmpl := resources.Get "hb/scss/index.tmpl.scss" }}
{{/* Compile SCSS. The target path MUST begin with "hb/scss/*" for resolving SASS/SCSS modules. */}}
{{- $style := $tmpl | resources.ExecuteAsTemplate (printf "hb/scss/index%s.scss" $suffix) $context }}
{{- if partialCached "hb/functions/debug" . }}
{{- warnf "[hb] %s:\n%s\n" $style.Name $style.Content }}
{{- end }}
{{- $style = $style | toCSS $options }}
{{- $postCSSOpts := dict
"use" (cond $rtl "rtlcss" "")
}}
{{- $style = $style | resources.PostCSS $postCSSOpts }}
{{- if hugo.IsProduction }}
{{- $style = $style | fingerprint | resources.PostProcess }}
{{- end -}}
{{/* Precache both of LTR and RTL CSS bundles. */}}
{{- partial "base/partial-if-exists" (dict
"Name" "pwa/functions/precache.html"
"Context" (dict "Page" $page "URL" $style.RelPermalink)
)
}}
{{- if eq $dir $page.Site.Language.LanguageDirection }}
{{- $res = $style }}
{{- break }}
{{- end }}
{{- end }}
{{- return $res }}
52 changes: 2 additions & 50 deletions layouts/partials/hb/assets/css.html
Original file line number Diff line number Diff line change
@@ -1,50 +1,2 @@
{{- $dirs := slice "" }}
{{/* Check if there is RTL site. */}}
{{- if where site.Sites "Language.LanguageDirection" "rtl" }}
{{- $dirs = $dirs | append "rtl" }}
{{- end }}
{{- $page := . }}
{{- $params := $page.Site.Params }}
{{- $context := dict
"params" $params
}}
{{- $bundle := default "hb" $params.hb.css_bundle_name }}
{{- range $dir := $dirs }}
{{- $rtl := eq $dir "rtl" }}
{{- $suffix := cond $rtl ".rtl" "" }}
{{/* SCSS options. */}}
{{- $options := dict
"targetPath" (printf "css/%s%s.css" $bundle $suffix)
"enableSourceMap" hugo.IsProduction
"vars" site.Params.hb.styles
}}
{{- if hugo.IsProduction }}
{{- $options = merge $options (dict
"outputStyle" "compressed")
}}
{{- end }}
{{/* Load style template. */}}
{{- $tmpl := resources.Get "hb/scss/index.tmpl.scss" }}
{{/* Compile SCSS. The target path MUST begin with "hb/scss/*" for resolving SASS/SCSS modules. */}}
{{- $style := $tmpl | resources.ExecuteAsTemplate (printf "hb/scss/index%s.scss" $suffix) $context }}
{{- if partialCached "hb/functions/debug" . }}
{{- warnf "[hb] %s:\n%s\n" $style.Name $style.Content }}
{{- end }}
{{- $style = $style | toCSS $options }}
{{- $postCSSOpts := dict
"use" (cond $rtl "rtlcss" "")
}}
{{- $style = $style | resources.PostCSS $postCSSOpts }}
{{- if hugo.IsProduction }}
{{- $style = $style | fingerprint | resources.PostProcess }}
{{- end -}}
{{/* Precache both of LTR and RTL CSS bundles. */}}
{{- partial "base/partial-if-exists" (dict
"Name" "pwa/functions/precache.html"
"Context" (dict "Page" $page "URL" $style.RelPermalink)
)
}}
{{- if eq $dir $page.Site.Language.LanguageDirection }}
<link href="{{ $style.RelPermalink }}" rel="stylesheet" />
{{- end }}
{{- end }}
{{- $style := partial "hb/assets/css-resource" . }}
<link href="{{ $style.RelPermalink }}" rel="stylesheet" />

0 comments on commit eed7546

Please sign in to comment.