Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
regisphilibert committed Jan 27, 2022
2 parents 419b2c8 + b713e08 commit fdddb2b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 27 deletions.
69 changes: 42 additions & 27 deletions core/scripts/private/GetTags.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,43 +22,58 @@
{{/* Ranging on the selected scripts, apply the js transformation */}}
{{ range $script := partial "huge/scripts/private/GetSelectedScripts" $ }}
{{ with partial "huge/scripts/private/transform/_" . }}
{{/* Default assumes this is a script rather than inline */}}
{{ $tag := dict
"name" "script"
"attr" (dict
"src" .RelPermalink
"type" "text/javascript"
"crossorigin" "anonymous"
"defer" "defer"
)
{{ $inline_attr := dict }}
{{ $external_attr := dict
"src" .RelPermalink
"type" "text/javascript"
}}

{{/* If inline, we overwrite previously set $tag */}}
{{ if $script.internal }}
{{ $tag = dict
"name" "script"
"inner" .Content
}}
{{/* Following will only be applied to external scripts */}}
{{/* We test loading strategy and add the argument if set */}}
{{ with $script.load }}
{{ if ne . "none" }}
{{ $external_attr = merge $external_attr (dict
. ""
) }}
{{ end }}
{{ end }}

{{/* We test crossorigin and add the argument if set */}}
{{ with $script.crossorigin }}
{{ if ne . "none" }}
{{ $external_attr = merge $external_attr (dict
"crossorigin" .
) }}
{{ end }}
{{ end }}

{{ with $hash := .Data.Integrity }}
{{ if $script.integrity }}
{{ $tag = merge $tag (dict
"attr" (dict
"integrity" $hash
)
{{ $external_attr = merge $external_attr (dict
"integrity" $hash
) }}
{{ end }}
{{ end }}

{{/* If debug, we add a informative attributes */}}
{{ if and $debug false }}
{{ $tag = merge $tag (dict
"attr" (dict
"data-debug" slice
)
) }}
{{/* We test attributes and add append the custom arguments to the predefined ones */}}
{{ with $script.attributes }}
{{ $inline_attr = merge $inline_attr . }}
{{ $external_attr = merge $external_attr . }}
{{ end }}

{{ $tag := dict }}
{{ if $script.internal }}
{{ $tag = dict
"name" "script"
"inner" .Content
"attr" $inline_attr
}}
{{ else }}
{{ $tag = dict
"name" "script"
"attr" $external_attr
}}
{{ end }}

{{ $tags = $tags | append $tag }}
{{ end }}
{{ end }}
Expand Down
13 changes: 13 additions & 0 deletions core/scripts/private/ParseScript.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,17 @@
{{ $params := $script.params | default dict }}
{{ $shims := $script.shims | default slice }}
{{ $target := $script.target | default "esnext" }}
{{ $crossorigin := $script.crossorigin | default "anonymous" }}
{{ $attributes := $script.attributes | default dict }}
{{ $load := "defer" }}
{{/* As this will add a boolean attribute, we want to limit it to defer or async */}}
{{ with $script.load }}
{{ if eq . "defer" "async" "none" }}
{{ $load = . }}
{{ end }}
{{ end }}


{{ $data = dict
"name" $name
"path" $script.path
Expand All @@ -64,6 +74,9 @@
"params" $params
"shims" $shims
"target" $target
"crossorigin" $crossorigin
"attributes" $attributes
"load" $load
}}
{{ end }}

Expand Down

0 comments on commit fdddb2b

Please sign in to comment.