diff --git a/layouts/_default/_markup/render-codeblock-timeline.html b/layouts/_default/_markup/render-codeblock-timeline.html index 07971e12..cc54b5c5 100644 --- a/layouts/_default/_markup/render-codeblock-timeline.html +++ b/layouts/_default/_markup/render-codeblock-timeline.html @@ -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" +-}} diff --git a/layouts/partials/plugin/timeline.html b/layouts/partials/plugin/timeline.html index 42fe0352..241c6d8c 100644 --- a/layouts/partials/plugin/timeline.html +++ b/layouts/partials/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 := "" -}} diff --git a/layouts/shortcodes/timeline.html b/layouts/shortcodes/timeline.html index 3766fa89..4492339f 100644 --- a/layouts/shortcodes/timeline.html +++ b/layouts/shortcodes/timeline.html @@ -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" +-}}