mirror of
https://github.com/hugo-fixit/FixIt.git
synced 2026-08-24 15:28:57 +00:00
66 lines
2.8 KiB
HTML
66 lines
2.8 KiB
HTML
{{- /*
|
|
ECharts rendering partial for code fences extended syntax and shortcode usage.
|
|
- Skips rendering when MarkupScope is home.
|
|
- Supports chart options from inline content, data key, or resource file.
|
|
- Supports JavaScript template mode via js/file options.
|
|
@param {Object} [.Options] render options from shortcode or code fence attributes
|
|
@param {String} [.Options.width] chart container width (default: 100%)
|
|
@param {String} [.Options.height] chart container height (default: 30rem)
|
|
@param {Boolean} [.Options.js] whether to treat content as JS option builder
|
|
@param {Boolean} [.Options.async] whether JS template executes asynchronously
|
|
@param {String} [.Options.data] key of data source under data/echarts
|
|
@param {String} [.Options.file] local resource path for js/json/yaml/toml source
|
|
@param {String} [.Inner] inline chart option content
|
|
@param {Object} [.Page] current page context
|
|
*/ -}}
|
|
|
|
{{- if ne hugo.Context.MarkupScope "home" -}}
|
|
|
|
{{- $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="diagram-container">
|
|
{{- dict "Label" "Copy ECharts code" | partial "plugin/diagram-copy-btn.html" -}}
|
|
<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 hugo.Data.echarts (printf "%v.%v" . page.Language) | default (index hugo.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 -}}
|
|
</div>
|
|
|
|
{{- .Page.Store.Set "hasEcharts" true -}}
|
|
|
|
{{- end -}}
|