{{/* Render Jupyter Notebook */}} {{- $path := .Get 0 -}} {{- $data := "" -}} {{- $page := .Page -}} {{/* https://gohugo.io/functions/transform/unmarshal/ */}} {{- with .Page.Resources.Get $path -}} {{- with unmarshal .Content -}} {{- $data = . -}} {{- end -}} {{- else -}} {{- errorf "Resource not found: %s" $path -}} {{- end -}} {{- $language := index $data "metadata" "language_info" "name" | default "python" -}} {{- with index $data "cells" -}} {{- range $cell := . -}} {{- if eq (index $cell "cell_type") "code" -}} {{- $source := index $cell "source" -}} {{- $sourceContent := (cond (reflect.IsSlice $source) (delimit $source "") $source) -}}
{{- partial "components/codeblock" (dict "lang" $language "content" $sourceContent) -}}
{{- $outputs := index $cell "outputs" -}} {{- with $outputs -}}
{{- range $output := . -}} {{- if eq (index $output "output_type") "display_data" -}} {{- $data := index $output "data" -}} {{- $image := index $data "image/png" -}} {{- if $image -}} image {{- end -}} {{- else if eq (index $output "output_type") "stream" -}} {{- $text := index $output "text" -}} {{- $textContent := (cond (reflect.IsSlice $text) (delimit $text "") $text) -}}
{{- $textContent -}}
{{- else if eq (index $output "output_type") "execute_result" -}} {{- $data := index $output "data" -}} {{- $text := index $data "text/plain" -}} {{- $textContent := (cond (reflect.IsSlice $text) (delimit $text "") $text) -}}
{{- $textContent -}}
{{- $html := index $data "text/html" -}} {{- if $html -}} {{- $htmlText := delimit $html "" -}}
{{- $htmlText | safeHTML -}}
{{- end -}} {{- end -}} {{- end -}}
{{- end -}}
{{- else if eq (index $cell "cell_type") "markdown" -}} {{- $source := index $cell "source" -}} {{- $sourceContent := (cond (reflect.IsSlice $source) (delimit $source "") $source) -}} {{- $sourceContent | $page.RenderString -}} {{- end -}} {{- end -}} {{- end -}}