github.com/vulppine/fotoDen@v0.3.0/generator/web.go (about)

     1  package generator
     2  
     3  // WebConfig is the structure of the JSON config file that fotoDen uses.
     4  type WebConfig struct {
     5  	WebsiteTitle     string         `json:"websiteTitle"`
     6  	PhotoURLBase     string         `json:"storageURL"`
     7  	ImageRootDir     string         `json:"imageRoot"`
     8  	ThumbnailFrom    string         `json:"thumbnailSize"`
     9  	DisplayImageFrom string         `json:"displayImageSize"`
    10  	Theme            bool           `json:"theme"`
    11  	Pages            []PageLink     `json:"pages"`
    12  	DownloadSizes    []string       `json:"downloadableSizes"`
    13  	ImageSizes       []WebImageSize `json:"imageSizes"`
    14  }
    15  
    16  type PageLink struct {
    17  	Title    string `json:"title"`
    18  	Location string `json:"location"`
    19  }
    20  
    21  // WebImageSize is a structure for image size types that fotoDen will call on.
    22  type WebImageSize struct {
    23  	SizeName  string `json:"sizeName"` // the semantic name of the size
    24  	Directory string `json:"dir"`      // the directory the size is stored in, relative to ImageRootDir
    25  	LocalBool bool   `json:"local"`    // whether to download it remotely or locally
    26  }
    27  
    28  // GenerateWebConfig creates a new WebConfig object, and returns a WebConfig object with a populated ImageSizes
    29  // based on the current ScalingOptions map.
    30  func GenerateWebConfig(source string) *WebConfig {
    31  
    32  	webconfig := new(WebConfig)
    33  	webconfig.PhotoURLBase = source
    34  
    35  	for k := range CurrentConfig.ImageSizes {
    36  		webconfig.ImageSizes = append(
    37  			webconfig.ImageSizes,
    38  			WebImageSize{
    39  				SizeName:  k,
    40  				Directory: k,
    41  				LocalBool: true,
    42  			},
    43  		)
    44  	}
    45  
    46  	return webconfig
    47  }
    48  
    49  // ReadWebConfig reads a JSON file containing WebConfig fields into a WebConfig struct.
    50  func (config *WebConfig) ReadWebConfig(fpath string) error {
    51  	err := ReadJSON(fpath, config)
    52  	if err != nil {
    53  		return err
    54  	}
    55  
    56  	return nil
    57  }
    58  
    59  // WriteWebConfig writes a WebConfig struct into the specified path.
    60  func (config *WebConfig) WriteWebConfig(fpath string) error {
    61  	err := WriteJSON(fpath, "multi", config)
    62  	if err != nil {
    63  		return err
    64  	}
    65  
    66  	return nil
    67  }