Files
FixIt/layouts/_partials/function/js-build.html
T
Cell 76f809794f refactor(assets): simplify template pipeline and resource handling
- Simplify `resources.Get` calls to string paths in script pipeline
  callers (plugin/script.html handles resources.Get internally)
- Refactor js-build.html to use $defaultOptions merge pattern matching
  style.html's ToCSS handling for better readability
- Refactor style.html ToCSS with $defaultOptions merge pattern and
  automatic targetPath generation from resource name
- Remove redundant custom $options dicts for targetPath that match
  the new default behavior
- Update partial docs for script.html and style.html
2026-05-29 21:55:09 +08:00

29 lines
996 B
HTML

{{- /*
Build and minify a JS resource with unified behavior.
@param {resource.Resource} .Resource Hugo resource to process
@param {Object|Boolean} [.Build] true for defaults, dict for custom options, false/omit to skip js.Build
@param {Boolean} [.Minify] extra minify flag; final minify is Minify OR Build.minify
@return {resource.Resource}
*/ -}}
{{- $resource := .Resource -}}
{{- $minify := .Minify -}}
{{- with .Build -}}
{{- $defaultOptions := dict
"targetPath" (replaceRE `\.(template\.)?ts$` ".js" $resource.Name)
"sourceMap" (cond hugo.IsDevelopment "linked" "none")
"minify" hugo.IsProduction
-}}
{{- $options := . -}}
{{- if eq . true -}}
{{- $options = dict -}}
{{- end -}}
{{- $options = $options | merge $defaultOptions -}}
{{- $resource = $resource | js.Build $options -}}
{{- $minify = $minify | or (index $options "minify") -}}
{{- end -}}
{{- if $minify -}}
{{- $resource = $resource | minify -}}
{{- end -}}
{{- return $resource -}}