{{/* Render Jupyter Notebook */}} {{- $path := .Get 0 -}} {{- $data := "" -}} {{- $page := .Page -}} {{- $isLocal := not (urls.Parse $path).Scheme -}} {{- $isPage := and (eq .Page.Kind "page") (not .Page.BundleType) -}} {{/* https://gohugo.io/functions/transform/unmarshal/ */}} {{- if (not $isLocal) -}} {{- with resources.GetRemote $path -}} {{- with unmarshal .Content -}}{{- $data = . -}}{{- end -}} {{- else -}} {{- errorf "Remote resource not found: %s" $path -}} {{- end -}} {{- else if (not $isPage) -}} {{- with .Page.Resources.Get $path -}} {{- with unmarshal .Content -}}{{- $data = . -}}{{- end -}} {{- else -}} {{- errorf "Local resource not found: %s" $path -}} {{- end -}} {{- else -}} {{- with resources.Get $path -}} {{- with unmarshal .Content -}}{{- $data = . -}}{{- end -}} {{- else -}} {{- errorf "Local resource not found: %s" $path -}} {{- end -}} {{- 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) -}} {{- with ($sourceContent | strings.Chomp) -}} {{ (printf "\n\n```%s\n%s\n```\n" $language .) | safeHTML -}} {{- end -}}
{{- else if eq (index $cell "cell_type") "markdown" -}} {{- $source := index $cell "source" }} {{- $sourceContent := (cond (reflect.IsSlice $source) (delimit $source "") $source) }} {{ (printf "\n%s\n" $sourceContent) | safeHTML }} {{- end -}} {{- end -}} {{- end -}}