diff --git a/partials/private/import.html b/partials/private/import.html index ea15f66..3793227 100644 --- a/partials/private/import.html +++ b/partials/private/import.html @@ -15,9 +15,9 @@ {{ with partialCached "tnd-netlifycms/private/import" . . }} {{ end }} */}} -{{/* regex101.com > https://regex101.com/r/TFA6WQ/1 */}} -{{ $pattern := "^([a-zA-Z]*) ([a-zA-Z/_-]*)$"}} -{{ $string_pattern := "^import ([a-zA-Z]*) ([a-zA-Z/_-]*)$" }} +{{/* regex101.com > https://regex101.com/r/mIrmn0/1 */}} +{{ $pattern := "^([a-zA-Z]*) ([.a-zA-Z/_-]*)$"}} +{{ $string_pattern := "^import ([a-zA-Z]*) ([.a-zA-Z/_-]*)$" }} {{/* Return variable, by default, will be the passed context */}} {{ $return := . }} {{ $type := false }} @@ -59,13 +59,32 @@ {{ if and $type $file }} {{/* We look for the matching data file located in `data/netlifycms/{Type}/{File}.yaml` */}} {{ with index site.Data.netlifycms (pluralize $type) }} - {{ with index . $file }} + {{ $with := index . $file }} + {{/* If we find a "." in the File string, it means user is trying to access a nested value. + We'll split the string and check for two nesting level max + */}} + {{ $file_split := split $file "." }} + {{ if eq (len $file_split) 2 }} + {{/* We have something like `import fields greeting.spanish */}} + {{ $with = index . (index $file_split 0) (index $file_split 1) }} + {{ else if eq (len $file_split) 3 }} + {{/* We have something like `import fields greeting.spanish.singular */}} + {{ $with = index . (index $file_split 0) (index $file_split 1) (index $file_split 2) }} + {{ end }} + + {{ with $with }} {{ $return = . }} {{ with $extend }} {{ $return = merge $return . }} {{ end }} {{ else }} - {{ partial "tnd-netlifycms/warn" (printf "We couldn't find %s/%s" $type $file) }} + {{ $message := printf "We couldn't find %s/%s" $type $file }} + {{ with $file_split }} + {{ if gt . 2 }} + {{ $message = print $message " because object depth is limited to 2" }} + {{ end }} + {{ end }} + {{ partial "tnd-netlifycms/warn" $message }} {{ end }} {{ else }} {{ partial "tnd-netlifycms/warn" (printf "We couldn't find Type %s" $type) }}