{{/*
canvas-file: Simple shortcode for Canvas-protected files.
Usage (positional):
{{< canvas-file "static/slides/lecture1.pdf" "Lecture 1 Slides" >}}
{{< canvas-file "static/slides/lecture1.pdf" >}}
Behavior:
- Development (hugo server / non-production):
Renders a link to the local file with a "DEV MODE" badge.
- Production (hugo -e production):
Renders a link to the Canvas authenticated URL.
Fails the build if no Canvas URL is available.
*/}}
{{- $path := .Get 0 -}}
{{- $title := .Get 1 | default (path.Base $path) -}}
{{- $record := index .Site.Data.canvas_urls $path -}}
{{- if $record -}}
{{- $title -}}
🔒
{{- else if eq hugo.Environment "production" -}}
{{- errorf "hugo-canvas-sync: No Canvas URL for %q. Run `hugo-canvas-sync sync` before building for production." $path -}}
{{- else -}}
{{/* Development fallback: serve local file, show badge */}}
{{- $localHref := printf "/%s" $path -}}
{{- $title -}}
🔓 DEV MODE
{{- end -}}