@@ -72,20 +72,13 @@ func main() {
7272 createSections ("" , schema , schema .Definitions , 1 , false )
7373}
7474
75- type Group struct {
76- File string
77- Name string
78- Content string
79- Imports * []string
80- }
81-
8275func createSections (prefix string , schema * jsonschema.Schema , definitions jsonschema.Definitions , depth int , parentIsNameObjectMap bool ) string {
8376 partialImports := & []string {}
8477 content := ""
8578 headlinePrefix := strings .Repeat ("#" , depth + 1 ) + " "
8679 anchorPrefix := strings .TrimPrefix (strings .ReplaceAll (prefix , prefixSeparator , anchorSeparator ), anchorSeparator )
8780
88- groups := map [string ]* Group {}
81+ groups := map [string ]* util. Group {}
8982
9083 for _ , fieldName := range schema .Properties .Keys () {
9184 if parentIsNameObjectMap && fieldName == nameFieldName {
@@ -206,7 +199,7 @@ func createSections(prefix string, schema *jsonschema.Schema, definitions jsonsc
206199 if groupID != "" {
207200 group , ok := groups [groupID ]
208201 if ! ok {
209- group = & Group {
202+ group = & util. Group {
210203 File : fmt .Sprintf (configPartialBasePath + "%s/%sgroup_%s.mdx" , latest .Version , prefix , groupID ),
211204 Imports : & []string {},
212205 }
@@ -232,34 +225,7 @@ func createSections(prefix string, schema *jsonschema.Schema, definitions jsonsc
232225 }
233226 }
234227
235- for groupID , group := range groups {
236- groupContent := group .Content
237-
238- if group .Name != "" {
239- groupContent = "\n " + `<div className="group-name">` + group .Name + `</div>` + "\n \n " + groupContent
240- }
241-
242- groupImportContent := ""
243- for _ , partialFile := range * group .Imports {
244- groupImportContent = groupImportContent + GetPartialImport (partialFile , group .File )
245- }
246-
247- if groupImportContent != "" {
248- groupImportContent = groupImportContent + "\n \n "
249- }
250-
251- groupFileContent := fmt .Sprintf (`%s<div className="group" data-group="%s">%s` + "\n " + `</div>` , groupImportContent , groupID , groupContent )
252-
253- err := os .MkdirAll (filepath .Dir (group .File ), os .ModePerm )
254- if err != nil {
255- panic (err )
256- }
257-
258- err = ioutil .WriteFile (group .File , []byte (groupFileContent ), os .ModePerm )
259- if err != nil {
260- panic (err )
261- }
262- }
228+ util .ProcessGroups (groups )
263229
264230 if prefix == "" {
265231 prefix = "reference"
@@ -269,7 +235,7 @@ func createSections(prefix string, schema *jsonschema.Schema, definitions jsonsc
269235
270236 importContent := ""
271237 for _ , partialFile := range * partialImports {
272- importContent = importContent + GetPartialImport (partialFile , pageFile )
238+ importContent = importContent + util . GetPartialImport (partialFile , pageFile )
273239 }
274240
275241 content = fmt .Sprintf ("%s%s" , importContent , content )
@@ -284,19 +250,6 @@ func createSections(prefix string, schema *jsonschema.Schema, definitions jsonsc
284250 return content
285251}
286252
287- func GetPartialImport (partialFile , importingFile string ) string {
288- partialImportPath , err := filepath .Rel (filepath .Dir (importingFile ), partialFile )
289- if err != nil {
290- panic (err )
291- }
292-
293- if partialImportPath [0 :1 ] != "." {
294- partialImportPath = "./" + partialImportPath
295- }
296-
297- return fmt .Sprintf (util .TemplatePartialImport , util .GetPartialImportName (partialFile ), partialImportPath )
298- }
299-
300253func GetEumValues (fieldSchema * jsonschema.Schema , required bool , fieldDefault * string ) string {
301254 enumValues := ""
302255 if fieldSchema .Enum != nil {
0 commit comments