github.com/vulppine/fotoDen@v0.3.0/tool/wizard.go (about) 1 package tool 2 3 import ( 4 "fmt" 5 "path/filepath" 6 7 "github.com/vulppine/cmdio-go" 8 "github.com/vulppine/fotoDen/generator" 9 ) 10 11 func isBlank(input string) bool { 12 if input == "" { 13 return true 14 } 15 16 return false 17 } 18 19 func setupWebsite(loc string, theme string) (WebsiteConfig, *generator.WebConfig) { 20 fmt.Println("Wizard: Setup fotoDen website") 21 fmt.Println("Some of these are required. Do not try to skip them.") 22 w := WebsiteConfig{} 23 w.RootLocation = loc 24 25 w.Name = cmdio.ReadInputReq("What is the name of your website? (required)") 26 w.URL = cmdio.ReadInputReq("What is the URL of your website? (required)") 27 w.GeneratorConfig = setupConfig() 28 w.GeneratorConfig.WebBaseURL = w.URL 29 w.GeneratorConfig.WebSourceLocation, _ = filepath.Abs( 30 filepath.Join( 31 generator.RootConfigDir, 32 "sites", 33 w.Name, 34 "theme", 35 theme, 36 )) 37 38 src := cmdio.ReadInput("Are you going to remotely host your images? If so, type in the URL now, otherwise leave it blank to automatically use local hosting for all images") 39 s := generator.GenerateWebConfig(src) 40 s.WebsiteTitle = w.Name 41 s.Theme = true 42 43 fmt.Println("Here are your current image sizes, for reference:") 44 for k := range generator.CurrentConfig.ImageSizes { 45 fmt.Println(k) 46 } 47 s.ImageRootDir = generator.CurrentConfig.ImageSrcDirectory 48 s.ThumbnailFrom = cmdio.ReadInputReq("What size do you want your thumbnails to be? (required)") 49 s.DisplayImageFrom = cmdio.ReadInputReq("What size do you want to display your images as in a fotoDen photo viewer? (required)") 50 s.DownloadSizes = cmdio.ReadInputAsArray("What sizes do you want easily downloadable?", ",") 51 52 return w, s 53 } 54 55 func setupConfig() generator.Config { 56 config := generator.Config{} 57 58 fmt.Println("Wizard: Setup fotoDen config") 59 fmt.Println("Leave blank for default!") 60 config.ImageRootDirectory = cmdio.ReadInput("Where do you want your images to be stored in every folder?") 61 if isBlank(config.ImageRootDirectory) { 62 config.ImageRootDirectory = generator.DefaultConfig.ImageRootDirectory 63 } 64 65 config.ImageSrcDirectory = cmdio.ReadInput("Where are you going to store your source-quality images?") 66 if isBlank(config.ImageSrcDirectory) { 67 config.ImageSrcDirectory = generator.DefaultConfig.ImageSrcDirectory 68 } 69 70 config.ImageSizes = map[string]generator.ImageScale{} 71 imageSizes := cmdio.ReadInputAsArray("What image sizes do you want? Separate by comma, no spaces.", ",") 72 if imageSizes[0] != "" { 73 fmt.Printf("Image sizes detected: %v\n", imageSizes) 74 fmt.Println("Leave blank to set as zero. At least one value must be filled in. Priority: MaxHeight, MaxWidth, ScalePercent") 75 for _, val := range imageSizes { 76 var c bool 77 for c != true { 78 fmt.Println("Image size " + val) 79 imageSize := generator.ImageScale{} 80 imageSize.MaxHeight, _ = cmdio.ReadInputAsInt("Maximium height of image?") 81 imageSize.MaxWidth, _ = cmdio.ReadInputAsInt("Maximum width of image?") 82 scalePercent, _ := cmdio.ReadInputAsFloat("Image scale percent? [0 - 100%]") 83 imageSize.ScalePercent = scalePercent * 0.1 84 if imageSize.MaxHeight == 0 && imageSize.MaxWidth == 0 && imageSize.ScalePercent == 0 { 85 fmt.Println("You must set one value to a non-zero value!") 86 } else { 87 c = true 88 config.ImageSizes[val] = imageSize 89 } 90 } 91 } 92 } else { 93 config.ImageSizes = generator.DefaultConfig.ImageSizes 94 fmt.Println("Using default image sizes: ") 95 for k, v := range generator.DefaultConfig.ImageSizes { 96 fmt.Printf("Size name: %s, MaxHeight: %d, MaxWidth: %d, ScalePercent: %f\n", k, v.MaxHeight, v.MaxWidth, v.ScalePercent) 97 } 98 } 99 100 return config 101 } 102 103 func setupWebConfig(source string) *generator.WebConfig { 104 config := generator.GenerateWebConfig(source) 105 106 fmt.Println("Wizard: Setup website config") 107 config.WebsiteTitle = cmdio.ReadInput("What is the title of your website?") 108 config.PhotoURLBase = cmdio.ReadInput("Are you going to be using a remote storage provider for your photos? If so, put in the URL to the folder containing your fotoDen-structured images here.") 109 110 fmt.Println("Here are your current image sizes, for reference:") 111 for k := range generator.CurrentConfig.ImageSizes { 112 fmt.Println(k) 113 } 114 115 config.Theme = true // TODO: Make selectable themes 116 config.ImageRootDir = generator.CurrentConfig.ImageSrcDirectory 117 config.ThumbnailFrom = cmdio.ReadInput("What size do you want your thumbnails to be?") 118 config.DisplayImageFrom = cmdio.ReadInput("What size do you want to display your images as in a fotoDen photo viewer?") 119 config.DownloadSizes = cmdio.ReadInputAsArray("What sizes do you want downlodable?", ",") 120 121 return config 122 } 123 124 func generateFolderWizard(directory string) (*generator.Folder, error) { 125 folder, err := generator.GenerateFolderInfo(directory, "") 126 if checkError(err) { 127 return nil, err 128 } 129 130 fmt.Println("Wizard: Generate folder") 131 folder.Name = cmdio.ReadInput("What is the name of this folder/album?") 132 folder.Desc = cmdio.ReadInput("What is the description of this folder/album?") 133 folder.Static = cmdio.ReadInputAsBool("Will the folder/album webpages have some dynamic elements static?", "y") 134 t := cmdio.ReadInputAsBool("Will the folder have a thumbnail?", "y") 135 if t { 136 thumb := cmdio.ReadInput("Where is the thumbnail located? (direct path or relative to current working directory)") 137 if thumb == "" { 138 fmt.Println("No file detected - ignoring.") 139 } else { 140 folder.Thumbnail = true 141 generator.MakeFolderThumbnail(thumb, directory) 142 } 143 } 144 145 return folder, nil 146 } 147 148 func updateFolderWizard(fol *generator.Folder) *generator.Folder { 149 fol.Name = cmdio.ReadInput("What is the new name of this folder/album?") 150 fol.Desc = cmdio.ReadInput("What is the new description of this folder/album?") 151 152 return fol 153 }