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 }}