Skip to content

Commit a543d2e

Browse files
Add depth to import strings WIP
Enable dots for nested objects: `- import fields myfield.subkey`. limited to 1 level for now. Fixes #10
1 parent 27a9135 commit a543d2e

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

partials/private/import.html

+16-5
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
{{ with partialCached "tnd-netlifycms/private/import" . . }}
1616
{{ end }}
1717
*/}}
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/_-]*)$" }}
2121
{{/* Return variable, by default, will be the passed context */}}
2222
{{ $return := . }}
2323
{{ $type := false }}
@@ -59,13 +59,24 @@
5959
{{ if and $type $file }}
6060
{{/* We look for the matching data file located in `data/netlifycms/{Type}/{File}.yaml` */}}
6161
{{ with index site.Data.netlifycms (pluralize $type) }}
62-
{{ with index . $file }}
62+
{{ $with := index . $file }}
63+
{{ $file_split := split $file "." }}
64+
{{ if eq (len $file_split) 2 }}
65+
{{ $with = index . (index $file_split 0) (index $file_split 1) }}
66+
{{ end }}
67+
{{ with $with }}
6368
{{ $return = . }}
6469
{{ with $extend }}
6570
{{ $return = merge $return . }}
6671
{{ end }}
6772
{{ else }}
68-
{{ partial "tnd-netlifycms/warn" (printf "We couldn't find %s/%s" $type $file) }}
73+
{{ $message := printf "We couldn't find %s/%s" $type $file }}
74+
{{ with split $file "." }}
75+
{{ if gt . 2 }}
76+
{{ $message = print $message " because object depth is limited to 2" }}
77+
{{ end }}
78+
{{ end }}
79+
{{ partial "tnd-netlifycms/warn" $message }}
6980
{{ end }}
7081
{{ else }}
7182
{{ partial "tnd-netlifycms/warn" (printf "We couldn't find Type %s" $type) }}

0 commit comments

Comments
 (0)