mirror of
				https://github.com/gohugoio/hugo.git
				synced 2024-05-11 05:54:58 +00:00 
			
		
		
		
	@@ -14,6 +14,7 @@
 | 
				
			|||||||
package commands
 | 
					package commands
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 | 
						"bytes"
 | 
				
			||||||
	"context"
 | 
						"context"
 | 
				
			||||||
	"encoding/json"
 | 
						"encoding/json"
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
@@ -34,6 +35,7 @@ import (
 | 
				
			|||||||
	"github.com/gohugoio/hugo/parser"
 | 
						"github.com/gohugoio/hugo/parser"
 | 
				
			||||||
	"github.com/spf13/cobra"
 | 
						"github.com/spf13/cobra"
 | 
				
			||||||
	"github.com/spf13/cobra/doc"
 | 
						"github.com/spf13/cobra/doc"
 | 
				
			||||||
 | 
						"gopkg.in/yaml.v2"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func newGenCommand() *genCommand {
 | 
					func newGenCommand() *genCommand {
 | 
				
			||||||
@@ -188,16 +190,8 @@ url: %s
 | 
				
			|||||||
			run: func(ctx context.Context, cd *simplecobra.Commandeer, r *rootCommand, args []string) error {
 | 
								run: func(ctx context.Context, cd *simplecobra.Commandeer, r *rootCommand, args []string) error {
 | 
				
			||||||
				r.Println("Generate docs data to", docsHelperTarget)
 | 
									r.Println("Generate docs data to", docsHelperTarget)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				targetFile := filepath.Join(docsHelperTarget, "docs.json")
 | 
									var buf bytes.Buffer
 | 
				
			||||||
 | 
									jsonEnc := json.NewEncoder(&buf)
 | 
				
			||||||
				f, err := os.Create(targetFile)
 | 
					 | 
				
			||||||
				if err != nil {
 | 
					 | 
				
			||||||
					return err
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
				defer f.Close()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				enc := json.NewEncoder(f)
 | 
					 | 
				
			||||||
				enc.SetIndent("", "  ")
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
				configProvider := func() docshelper.DocProvider {
 | 
									configProvider := func() docshelper.DocProvider {
 | 
				
			||||||
					conf := hugolib.DefaultConfig()
 | 
										conf := hugolib.DefaultConfig()
 | 
				
			||||||
@@ -207,7 +201,25 @@ url: %s
 | 
				
			|||||||
				}
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				docshelper.AddDocProviderFunc(configProvider)
 | 
									docshelper.AddDocProviderFunc(configProvider)
 | 
				
			||||||
				if err := enc.Encode(docshelper.GetDocProvider()); err != nil {
 | 
									if err := jsonEnc.Encode(docshelper.GetDocProvider()); err != nil {
 | 
				
			||||||
 | 
										return err
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									// Decode the JSON to a map[string]interface{} and then unmarshal it again to the correct format.
 | 
				
			||||||
 | 
									var m map[string]interface{}
 | 
				
			||||||
 | 
									if err := json.Unmarshal(buf.Bytes(), &m); err != nil {
 | 
				
			||||||
 | 
										return err
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									targetFile := filepath.Join(docsHelperTarget, "docs.yaml")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									f, err := os.Create(targetFile)
 | 
				
			||||||
 | 
									if err != nil {
 | 
				
			||||||
 | 
										return err
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									defer f.Close()
 | 
				
			||||||
 | 
									yamlEnc := yaml.NewEncoder(f)
 | 
				
			||||||
 | 
									if err := yamlEnc.Encode(m); err != nil {
 | 
				
			||||||
					return err
 | 
										return err
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										6073
									
								
								docs/data/docs.json
									
									
									
									
									
								
							
							
						
						
									
										6073
									
								
								docs/data/docs.json
									
									
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										4415
									
								
								docs/data/docs.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4415
									
								
								docs/data/docs.yaml
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
		Reference in New Issue
	
	Block a user