29 lines
No EOL
821 B
Text
29 lines
No EOL
821 B
Text
package components
|
|
|
|
var showOnceHandle = templ.NewOnceHandle()
|
|
|
|
type ScriptAssetOptions struct {
|
|
IsAsync bool
|
|
IsDefer bool
|
|
IsModule bool
|
|
DoImport bool
|
|
}
|
|
|
|
templ LoadJSAsset(assetName string, opts *ScriptAssetOptions) {
|
|
if opts == nil {
|
|
<script type="module" src={"/assets/js/" + assetName}></script>
|
|
} else {
|
|
if opts.IsModule {
|
|
if opts.DoImport {
|
|
<script type="module">
|
|
{"import \"/assets/js/\"" + assetName}
|
|
</script>
|
|
} else {
|
|
<script type="module" src={"/assets/js/" + assetName} defer?={opts.IsDefer} async?={opts.IsAsync}></script>
|
|
}
|
|
} else {
|
|
<script src={"/assets/js/" + assetName} defer?={opts.IsDefer} async?={opts.IsAsync}></script>
|
|
}
|
|
}
|
|
|
|
} |