From ae9aa17e37edf61ef029a1f6768dde5738fb673c Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Mon, 7 Oct 2024 21:36:03 -0700 Subject: [PATCH] import map template --- layouts/partials/resources/importmap.html | 30 +++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 layouts/partials/resources/importmap.html diff --git a/layouts/partials/resources/importmap.html b/layouts/partials/resources/importmap.html new file mode 100644 index 0000000..4a945fd --- /dev/null +++ b/layouts/partials/resources/importmap.html @@ -0,0 +1,30 @@ +{{ $imports := dict }} + +{{ if eq 0 1 }} + {{ with $tsModuleResources := resources.Match "scripts/modules/*/*" }} + {{ range $tsModuleResources }} + {{ $resource := . }} + {{ if eq (path.Ext .) ".ts" }} + {{ $resource = . | js.Build }} + {{ end }} + + {{/* + Create imports for these scripts that look like $dirname/$basename + where basename doesn't have the extension + */}} + {{ $directoryBasename := path.Base (path.Dir $resource) }} + {{ $key := path.Join $directoryBasename (path.BaseName $resource) }} + + {{ $imports = merge $imports (dict $key $resource.RelPermalink) }} + {{ end }} + {{ end }} +{{ else }} + {{ $imports = dict "modules/" "scripts/modules/" }} +{{ end }} + +{{ $importmap := dict }} +{{ if gt (len $imports) 0 }} + {{ $importmap = dict "imports" $imports }} +{{ end }} + +{{ return $importmap }}