Feat: add data and file params support for timeline shortcode (#595)

This commit is contained in:
Cell
2025-04-29 16:26:03 +08:00
committed by GitHub
parent 9c8c0b6dee
commit d1d3ed2954
3 changed files with 35 additions and 5 deletions
@@ -1 +1,7 @@
{{- dict "Options" .Attributes "Inner" .Inner | partial "plugin/timeline.html" -}}
{{- dict
"Options" .Attributes
"Inner" .Inner
"Resources" .Page.Resources
"Position" .Position
| partial "plugin/timeline.html"
-}}
+19 -3
View File
@@ -4,16 +4,32 @@
{{- $animation := .Options.animation | default false -}}
{{- $size := .Options.size | default "medium" -}}
{{- $node := .Options.node | default "circle" -}}
{{- $data := .Options.data -}}
{{- $file := .Options.file -}}
{{- /* Get Timeline events */ -}}
{{- $events := slice -}}
{{- with .Inner -}}
{{- $events = (. | transform.Unmarshal).events -}}
{{- $content := .Inner -}}
{{ with $data }}
{{- $content = index site.Data.timeline . -}}
{{- if not $content -}}
{{- warnf "Timeline: data not found, please ensure the data file \"data/timeline/%s.{json|yml|yaml|toml}\" exists." . -}}
{{- end -}}
{{- else -}}
{{- with dict "Path" $file "Resources" .Resources | partial "function/resource.html" }}
{{- $content = .Content -}}
{{- else with $file -}}
{{- warnf "Timeline: no such data file: %s" . -}}
{{- end -}}
{{- $content = $content | transform.Unmarshal -}}
{{- end -}}
{{- $events := $content.events | default slice -}}
{{- with .Events -}}
{{- $events = . -}}
{{- end -}}
{{- $events = sort $events "timestamp" (cond $reverse "desc" "asc") -}}
{{- if not $events -}}
{{- warnf "Timeline: events is empty, executing in file %s" $.Position -}}
{{- end -}}
{{- /* Set Timeline style */ -}}
{{- $style := "" -}}
+9 -1
View File
@@ -7,5 +7,13 @@
{{- $options = .Get "width" | dict "width" | merge $options -}}
{{- $options = .Get "height" | dict "height" | merge $options -}}
{{- $options = .Get "class" | dict "class" | merge $options -}}
{{- $options = .Get "data" | dict "data" | merge $options -}}
{{- $options = .Get "file" | dict "file" | merge $options -}}
{{- end -}}
{{- dict "Options" $options "Inner" .Inner | partial "plugin/timeline.html" -}}
{{- dict
"Options" $options
"Inner" .Inner
"Resources" .Page.Resources
"Position" .Position
| partial "plugin/timeline.html"
-}}