mirror of
https://github.com/hugo-fixit/FixIt.git
synced 2026-08-24 15:28:57 +00:00
41 lines
1.8 KiB
HTML
41 lines
1.8 KiB
HTML
{{- /* Echarts support for code fences extended and shortcodes. */ -}}
|
|
{{- $width := .Options.width | default "100%" -}}
|
|
{{- $height := .Options.height | default "30rem" -}}
|
|
{{- $js := .Options.js | default false -}}
|
|
{{- $async := .Options.async | default false -}}
|
|
{{- $data := .Options.data -}}
|
|
{{- $file := .Options.file -}}
|
|
{{- $attrs := printf `style="width: %v; height: %v;"` $width $height -}}
|
|
<div class="echarts" {{ $attrs | safeHTMLAttr }}></div>
|
|
{{- $content := strings.TrimSpace .Inner -}}
|
|
{{- if $js | or (hasSuffix $file ".js") -}}
|
|
{{- with dict "Path" $file "Resources" .Resources | partial "function/resource.html" }}
|
|
{{- $content = .Content -}}
|
|
{{- end }}
|
|
{{- if hugo.IsProduction -}}
|
|
{{- $content = replaceRE `[\s]+` " " $content -}}
|
|
{{- end -}}
|
|
{{- if not $content -}}
|
|
{{- warnf "ECharts: JS Code is empty, executing in file %s" $.Position -}}
|
|
{{- end -}}
|
|
<template data-fmt="js" data-async="{{ $async }}">{{ $content | safeJS }}</template>
|
|
{{- else -}}
|
|
{{ with $data }}
|
|
{{- $content = index site.Data.echarts (printf "%v.%v" . page.Language) | default (index site.Data.echarts .) -}}
|
|
{{- if not $content -}}
|
|
{{- warnf "ECharts: data not found, please ensure the data file \"data/echarts/%s.{json|yml|yaml|toml}\" exists." . -}}
|
|
{{- end -}}
|
|
{{- else -}}
|
|
{{- with dict "Path" $file "Resources" .Resources | partial "function/resource.html" }}
|
|
{{- $content = .Content -}}
|
|
{{- else with $file -}}
|
|
{{- warnf "ECharts: no such data file: %s" . -}}
|
|
{{- end -}}
|
|
{{- $content = $content | transform.Unmarshal -}}
|
|
{{- end -}}
|
|
{{- if not $content -}}
|
|
{{- warnf "ECharts: option is empty, executing in file %s" $.Position -}}
|
|
{{- end -}}
|
|
<template>{{ $content | jsonify }}</template>
|
|
{{- end -}}
|