generator

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 7, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RootConfigDir = path.Join(userConfigDir, "fotoDen")

RootConfigDir is where the configuration files are stored.

View Source
var Verbose bool // if this is set, everything important is printed

Verbose is used toggle verbose statements - when toggled, prints what the generator is doing to console.

View Source
var WorkingDirectory, _ = os.Getwd()

WorkingDirectory is the current working directory that fotoDen was started in.

Functions

func BatchCopyFile

func BatchCopyFile(files []string, directory string, ch chan int) error

BatchCopyFile copies a list of file string names to the current WorkingDirectory by index. Returns an error if one occurs, otherwise nil. Also preserves the current extension of the file. (This is due to a NeoCities Free restriction)

func BatchImageConversion

func BatchImageConversion(files []string, prefix string, directory string, ScalingOptions ImageScale, ch chan int) error

BatchImageConversion resizes a set of images to thumbnail size and puts them into the given directory, as according to CurrentConfig. Returns an error if one occurs, otherwise nil.

func BatchImageMeta added in v0.1.0

func BatchImageMeta(files []string, directory string, ch chan int) error

BatchImageMeta takes a string array of files, and a destination directory, and generates a JSON file containing non-EXIF metadata (such as names and descriptions) of image files for fotoDen to process.

func BatchOperationOnFiles

func BatchOperationOnFiles(files []string, fn func(string, int) error, ch chan int) error

BatchOperationOnFiles takes two arguments, an array of file names, and a function that takes a string and an int.

The string will be the file name, while the int will be the index of the file in the array.

The function will iterate over every file name until the end of the array is reached, passing the file name into the function.

Also takes an int channel - it will output '1' on that channel for every file operated on.

func CopyFile

func CopyFile(file string, dest string) error

CopyFile takes three arguments - the name of the file, the name of the new file, and the destination. This assumes the file we're renaming is in the current working directory, or it is reachable via the current working directory.

Returns an error if one occurs - otherwise returns nil.

func GetArrayOfFiles

func GetArrayOfFiles(directory []os.FileInfo) []string

GetArrayOfFiles takes an array of os.FileInfo, and runs it through GetArrayOfFilesAndFolders, returning only the array of files.

func GetArrayOfFilesAndFolders

func GetArrayOfFilesAndFolders(directory []os.FileInfo) ([]string, []string)

GetArrayOfFilesAndFolders takes an array of os.FileInfo (usually from from os.Readdir()), and returns a string array of all non-directories. Also returns a string array of directories, so we don't have to copy and paste this function.

func GetArrayOfFolders

func GetArrayOfFolders(directory []os.FileInfo) []string

GetArrayOfFolders takes an array of os.FileInfo, and runs it through GetArrayOfFilesAndFolders, returning only the array of folders.

func IsolateImages

func IsolateImages(files []string) []string

IsolateImages isolates images in an array.

Checks all image files at O(n), if a file is not an image, removes it from the current slice.

func MakeFolderThumbnail

func MakeFolderThumbnail(file string, directory string) error

MakeFolderThumbnail creates a thumbnail from a file into a destination directory. This is only here to make fotoDen's command line tool look cleaner in code, and avoid importing more than needed.

func OpenConfig added in v0.2.0

func OpenConfig(configLocation string) error

OpenfotoDenConfig sets the current fotoDen generator configuration to this

func ReadJSON added in v0.1.0

func ReadJSON(filePath string, iface interface{}) error

ReadJSON reads a JSON file from a pathname, and puts it into the specified interface. Returns an error if any occur.

func RemoveItemFromStringArray

func RemoveItemFromStringArray(array []string, item string) []string

RemoveItemFromStringArray removes an item from a string array at O(n) speed.

func ResizeImage

func ResizeImage(file string, imageName string, scale ImageScale, dest string, imageFormat bimg.ImageType) error

ResizeImage resizes a single image.

You'll have to pass it a ImageScale object, which contains values for either a scale percentage, or a max height/width. In order of usage: maxheight, maxwidth, scalepercent

maxheight is first due to a restriction with CSS Flex and mixed height images, maxwidth is second for the same thing, but with flex set to column mode, scalepercent is final for when the first two don't apply.

The function will output the image to the given directory, without changing the name. It will return an error if the filename given already exists in the destination directory.

func WriteConfig added in v0.2.0

func WriteConfig(config Config, configLocation string) error

WritefotoDenConfig attempts to write CurrentConfig to a new file at configLocation.

func WriteJSON added in v0.1.0

func WriteJSON(filePath string, mode string, iface interface{}) error

WriteJSON writes a struct as a JSON file to a specified pathname. Takes a filepath, a "mode", and an interface containing something that translates to valid JSON according to encoding/json. Mode toggles between non-indented JSON, and indented JSON. Returns an error if any occur.

Types

type Album added in v0.3.0

type Album struct {
	*Folder
	ItemAmount int `json:"itemAmount"`
}

Album represents a folder, but with an extra value, ItemAmount attached to it. This currently isn't in use, but will be integrated eventually.

type Config added in v0.2.0

type Config struct {
	ImageRootDirectory string // where all images are stored (default: img)
	ImageSrcDirectory  string // where all source images are stored (default: ImageRootDirectory/src)
	ImageMetaDirectory string // where all meta files per image are stored (default: ImageRootDirectory/meta)
	ImageSizes         map[string]ImageScale
	WebSourceLocation  string // where all html/css/js files are stored for fotoDen's functionality
	WebBaseURL         string // what the base URL is (aka, fotoDen's location)
}

Config represents the configuration for fotoDen's generator, and where images will go, as well as what sizes will be generated. ImageSizes is a map with string keys containing ImageScale structs, which dictate how images will be resized.

var CurrentConfig Config

CurrentConfig represents the current generator config, and can be used as reference for any package that calls fotoDen/generator.

var DefaultConfig Config = Config{
	ImageRootDirectory: "img",
	ImageMetaDirectory: "meta",
	ImageSizes: map[string]ImageScale{
		"small":  ImageScale{ScalePercent: 0.25},
		"medium": ImageScale{ScalePercent: 0.5},
		"large":  ImageScale{ScalePercent: 0.75},
	},
	ImageSrcDirectory: "src",
	WebBaseURL:        "",
}

DefaultConfig contains a template for fotoDen to use. TODO: Move this to some kind of GeneratorConfig generator.

type Folder

type Folder struct {
	Name       string   `json:"name"`      // The name of the folder.
	Desc       string   `json:"desc"`      // The description of a folder.
	ShortName  string   `json:"shortName"` // The shortname of the folder (can be taken from the filesystem folder name)
	Type       string   `json:"type"`      // The type of folder (currently supports only album or folder)
	Thumbnail  bool     `json:"thumbnail"` // If a thumbnail exists or not. This is dictated by the generation of thumb.jpg.
	ItemAmount int      `json:"itemAmount"`
	Subfolders []string `json:"subfolders"` // Any folders that are within the folder (updated whenever the generator is called in the folder)
	Static     bool     `json:"static"`     // If the folder was generated statically, or has information inserted dynamically.
}

Folder represents a folderInfo.json file used by fotoDen. It has all the needed values for fotoDen.js to operate correctly. fotoDen/generator does not provide functions to manage this - only to read and create these.

func GenerateFolderInfo

func GenerateFolderInfo(directory string, name string) (*Folder, error)

GenerateFolderInfo generates a Folder object that can be used for folder configuration. If directory is an empty string, it does it in the current directory. Otherwise, it attempts to reach the directory from the current working directory.

If name is an empty string, it uses the target directory's name.

Does not check if folderType is valid.

Returns a Folder object if successful, and a nil error, otherwise returns a potentially incomplete object, and an error.

func (*Folder) ReadFolderInfo

func (folder *Folder) ReadFolderInfo(filePath string) error

ReadFolderInfo is a method for reading folder info from a file. Returns an error if any occur.

func (*Folder) UpdateSubdirectories

func (folder *Folder) UpdateSubdirectories(directory string) (int, error)

UpdateSubdirectories updates a Folder object's subdirectories according to the given directory. If directory is an empty string, will attempt to update the Folder from the current working directory. Returns an error, if any occurs, otherwise the number of directories and a nil error.

func (*Folder) WriteFolderInfo

func (folder *Folder) WriteFolderInfo(filePath string) error

WriteFolderInfo is a method for writing fotoDen folder info to a file. Returns an error if any occur.

type ImageMeta added in v0.1.0

type ImageMeta struct {
	ImageName string // The name of an image.
	ImageDesc string // The description of an image.
}

ImageMeta provides metadata such as name and description for an image file. This is used by fotoDen on the web frontend to display custom per-image information.

func (*ImageMeta) WriteImageMeta added in v0.1.0

func (meta *ImageMeta) WriteImageMeta(folder string, name string) error

WriteImageMeta writes an ImageMeta struct to a file.

Takes two arguments: a folder destination, and a name. The name is automatically combined to create a [name].json file, in order to ensure compatibility with fotoDen. Writes the json file into the given folder.

type ImageScale

type ImageScale struct {
	MaxHeight    int
	MaxWidth     int
	ScalePercent float64
}

ImageScale represents scaling options to be used by ResizeImage. See ResizeImage for more information.

type Items added in v0.1.0

type Items struct {
	Metadata bool `json:"metadata"` // Dictates whether or not each image has its own ImageMeta object.
	// If this is false, then no metadata will be read.
	ItemsInFolder []string `json:"items"` // All the items in a folder, by name, in an array.
}

Items represents an itemsInfo.json file used by fotoDen. It is used mainly in album-type folders, and contains a bool indicating whether metadata is being used, and a string array (potentially large) of file names.

func GenerateItemInfo added in v0.1.0

func GenerateItemInfo(directory string) (*Items, error)

GenerateItemInfo generates an Items object based on the contents of the directory. This automatically strips non-images.

func (*Items) ReadItemsInfo added in v0.1.0

func (items *Items) ReadItemsInfo(filePath string) error

ReadItemsInfo is a method for reading items info from a file. Returns an error if any occur.

func (*Items) WriteItemsInfo added in v0.1.0

func (items *Items) WriteItemsInfo(filePath string) error

WriteItemsInfo is a method for writing items info to a file. Returns an error if any occur.

type PageLink struct {
	Title    string `json:"title"`
	Location string `json:"location"`
}

type WebConfig

type WebConfig struct {
	WebsiteTitle     string         `json:"websiteTitle"`
	PhotoURLBase     string         `json:"storageURL"`
	ImageRootDir     string         `json:"imageRoot"`
	ThumbnailFrom    string         `json:"thumbnailSize"`
	DisplayImageFrom string         `json:"displayImageSize"`
	Theme            bool           `json:"theme"`
	Pages            []PageLink     `json:"pages"`
	DownloadSizes    []string       `json:"downloadableSizes"`
	ImageSizes       []WebImageSize `json:"imageSizes"`
}

WebConfig is the structure of the JSON config file that fotoDen uses.

func GenerateWebConfig added in v0.1.0

func GenerateWebConfig(source string) *WebConfig

GenerateWebConfig creates a new WebConfig object, and returns a WebConfig object with a populated ImageSizes based on the current ScalingOptions map.

func (*WebConfig) ReadWebConfig added in v0.1.0

func (config *WebConfig) ReadWebConfig(fpath string) error

ReadWebConfig reads a JSON file containing WebConfig fields into a WebConfig struct.

func (*WebConfig) WriteWebConfig added in v0.1.0

func (config *WebConfig) WriteWebConfig(fpath string) error

WriteWebConfig writes a WebConfig struct into the specified path.

type WebImageSize added in v0.1.0

type WebImageSize struct {
	SizeName  string `json:"sizeName"` // the semantic name of the size
	Directory string `json:"dir"`      // the directory the size is stored in, relative to ImageRootDir
	LocalBool bool   `json:"local"`    // whether to download it remotely or locally
}

WebImageSize is a structure for image size types that fotoDen will call on.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL