|
15 | 15 | {{ with partialCached "tnd-netlifycms/private/import" . . }} |
16 | 16 | {{ end }} |
17 | 17 | */}} |
18 | | -{{/* regex101.com > https://regex101.com/r/TFA6WQ/1 */}} |
19 | | -{{ $pattern := "^([a-zA-Z]*) ([a-zA-Z/_-]*)$"}} |
20 | | -{{ $string_pattern := "^import ([a-zA-Z]*) ([a-zA-Z/_-]*)$" }} |
| 18 | +{{/* regex101.com > https://regex101.com/r/mIrmn0/1 */}} |
| 19 | +{{ $pattern := "^([a-zA-Z]*) ([.a-zA-Z/_-]*)$"}} |
| 20 | +{{ $string_pattern := "^import ([a-zA-Z]*) ([.a-zA-Z/_-]*)$" }} |
21 | 21 | {{/* Return variable, by default, will be the passed context */}} |
22 | 22 | {{ $return := . }} |
23 | 23 | {{ $type := false }} |
|
59 | 59 | {{ if and $type $file }} |
60 | 60 | {{/* We look for the matching data file located in `data/netlifycms/{Type}/{File}.yaml` */}} |
61 | 61 | {{ with index site.Data.netlifycms (pluralize $type) }} |
62 | | - {{ with index . $file }} |
| 62 | + {{ $with := index . $file }} |
| 63 | + {{/* If we find a "." in the File string, it means user is trying to access a nested value. |
| 64 | + We'll split the string and check for two nesting level max |
| 65 | + */}} |
| 66 | + {{ $file_split := split $file "." }} |
| 67 | + {{ if eq (len $file_split) 2 }} |
| 68 | + {{/* We have something like `import fields greeting.spanish */}} |
| 69 | + {{ $with = index . (index $file_split 0) (index $file_split 1) }} |
| 70 | + {{ else if eq (len $file_split) 3 }} |
| 71 | + {{/* We have something like `import fields greeting.spanish.singular */}} |
| 72 | + {{ $with = index . (index $file_split 0) (index $file_split 1) (index $file_split 2) }} |
| 73 | + {{ end }} |
| 74 | + |
| 75 | + {{ with $with }} |
63 | 76 | {{ $return = . }} |
64 | 77 | {{ with $extend }} |
65 | 78 | {{ $return = merge $return . }} |
66 | 79 | {{ end }} |
67 | 80 | {{ else }} |
68 | | - {{ partial "tnd-netlifycms/warn" (printf "We couldn't find %s/%s" $type $file) }} |
| 81 | + {{ $message := printf "We couldn't find %s/%s" $type $file }} |
| 82 | + {{ with $file_split }} |
| 83 | + {{ if gt . 2 }} |
| 84 | + {{ $message = print $message " because object depth is limited to 2" }} |
| 85 | + {{ end }} |
| 86 | + {{ end }} |
| 87 | + {{ partial "tnd-netlifycms/warn" $message }} |
69 | 88 | {{ end }} |
70 | 89 | {{ else }} |
71 | 90 | {{ partial "tnd-netlifycms/warn" (printf "We couldn't find Type %s" $type) }} |
|
0 commit comments