mirror of
https://github.com/hugo-fixit/FixIt.git
synced 2026-08-25 15:58:55 +00:00
✨ Feat: add data and file params support for timeline shortcode (#595)
This commit is contained in:
@@ -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"
|
||||
-}}
|
||||
|
||||
@@ -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 := "" -}}
|
||||
|
||||
@@ -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"
|
||||
-}}
|
||||
|
||||
Reference in New Issue
Block a user