@@ -96,19 +96,113 @@ type PageConfigEarly struct {
9696 VersionDelegees []string
9797 LanguageDelegees []string
9898
99+ // User defined params.
100+ Params maps.Params
101+
99102 Cascade []map [string ]any
100103
101104 // Content holds the content for this page.
102105 Content Source
106+
107+ // Compiled values.
108+ CascadeCompiled * maps.Ordered [page.PageMatcher , maps.Params ] `mapstructure:"-" json:"-"`
109+ }
110+
111+ const (
112+ pageMetaKeyVersions = "versions"
113+ pageMetaKeyLanguages = "languages"
114+ pageMetaKeyRoles = "roles"
115+ pageMetaKeyVersionDelegees = "versiondelegees"
116+ pageMetaKeyLanguageDelegees = "languagedelegees"
117+ pageMetaKeyRoleDelegees = "roledelegees"
118+ pageMetaKeyCascade = "cascade"
119+ pageMetaKeyPath = "path"
120+ pageMetaKeyLang = "lang"
121+ pageMetaKeyKind = "kind"
122+ )
123+
124+ func (pcfg * PageConfigEarly ) SetMetaPreFromMap (frontmatter map [string ]any , logger loggers.Logger , conf config.AllProvider ) error {
125+ // Needed for case insensitive fetching of params values.
126+ maps .PrepareParams (frontmatter )
127+ pcfg .Params = frontmatter
128+ // Check for any cascade define on itself.
129+ if cv , found := frontmatter [pageMetaKeyCascade ]; found {
130+ var err error
131+ cascade , err := page .DecodeCascade (logger , true , cv )
132+ if err != nil {
133+ return err
134+ }
135+ pcfg .CascadeCompiled = cascade
136+ }
137+
138+ // Look for path, lang, roles and kind, all of which values we need early on.
139+ if v , found := frontmatter [pageMetaKeyPath ]; found {
140+ pcfg .Path = paths .ToSlashPreserveLeading (cast .ToString (v ))
141+ }
142+ if v , found := frontmatter [pageMetaKeyLang ]; found {
143+ lang := strings .ToLower (cast .ToString (v ))
144+ if _ , ok := conf .PathParser ().LanguageIndex [lang ]; ok {
145+ pcfg .Lang = lang
146+ }
147+ }
148+ if v , found := frontmatter [pageMetaKeyKind ]; found {
149+ s := cast .ToString (v )
150+ if s != "" {
151+ pcfg .Kind = kinds .GetKindMain (s )
152+ if pcfg .Kind == "" {
153+ return fmt .Errorf ("unknown kind %q in front matter" , s )
154+ }
155+ }
156+ }
157+ if v , found := frontmatter [pageMetaKeyRoles ]; found {
158+ pcfg .Roles = cast .ToStringSlice (v )
159+ }
160+ if v , found := frontmatter [pageMetaKeyVersions ]; found {
161+ pcfg .Versions = cast .ToStringSlice (v )
162+ }
163+ if v , found := frontmatter [pageMetaKeyLanguages ]; found {
164+ pcfg .Languages = cast .ToStringSlice (v )
165+ }
166+ if v , found := frontmatter [pageMetaKeyLanguageDelegees ]; found {
167+ pcfg .LanguageDelegees = cast .ToStringSlice (v )
168+ }
169+ if v , found := frontmatter [pageMetaKeyVersionDelegees ]; found {
170+ pcfg .VersionDelegees = cast .ToStringSlice (v )
171+ }
172+ if v , found := frontmatter [pageMetaKeyRoleDelegees ]; found {
173+ pcfg .RoleDelegees = cast .ToStringSlice (v )
174+ }
175+
176+ return nil
103177}
104178
105179func (p * PageConfigEarly ) setConfigCascadeValueIfNotSet (key string , value any ) {
106180 switch key {
107- // TODO1 complement.
108- case "versions" :
181+ case pageMetaKeyVersions :
109182 if p .Versions == nil {
110183 p .Versions = types .ToStringSlicePreserveString (value )
111184 }
185+ case pageMetaKeyLanguages :
186+ if p .Languages == nil {
187+ p .Languages = types .ToStringSlicePreserveString (value )
188+ }
189+ case pageMetaKeyRoles :
190+ if p .Roles == nil {
191+ p .Roles = types .ToStringSlicePreserveString (value )
192+ }
193+ case pageMetaKeyVersionDelegees :
194+ if p .VersionDelegees == nil {
195+ p .VersionDelegees = types .ToStringSlicePreserveString (value )
196+ }
197+ case pageMetaKeyLanguageDelegees :
198+ if p .LanguageDelegees == nil {
199+ p .LanguageDelegees = types .ToStringSlicePreserveString (value )
200+ }
201+ case pageMetaKeyRoleDelegees :
202+ if p .RoleDelegees == nil {
203+ p .RoleDelegees = types .ToStringSlicePreserveString (value )
204+ }
205+
112206 }
113207}
114208
@@ -142,18 +236,14 @@ type PageConfig struct {
142236 Build BuildConfig
143237 Menus any // Can be a string, []string or map[string]any.
144238
145- // User defined params.
146- Params maps.Params
147-
148239 // The raw data from the content adapter.
149240 // TODO(bep) clean up the ContentAdapterData vs Params.
150241 ContentAdapterData map [string ]any `mapstructure:"-" json:"-"`
151242
152243 // Compiled values.
153- ConfiguredOutputFormats output.Formats `mapstructure:"-" json:"-"`
154- CascadeCompiled * maps.Ordered [page.PageMatcher , maps.Params ] `mapstructure:"-" json:"-"`
155- ContentMediaType media.Type `mapstructure:"-" json:"-"`
156- IsFromContentAdapter bool `mapstructure:"-" json:"-"`
244+ ConfiguredOutputFormats output.Formats `mapstructure:"-" json:"-"`
245+ ContentMediaType media.Type `mapstructure:"-" json:"-"`
246+ IsFromContentAdapter bool `mapstructure:"-" json:"-"`
157247
158248 LanguagesCompiledSet * maps.OrderedIntSet `mapstructure:"-" json:"-"`
159249 RolesCompiledSet * maps.OrderedIntSet `mapstructure:"-" json:"-"`
0 commit comments