2019-01-01 19:41:03 +01:00
|
|
|
package gallery
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"git.gutmet.org/finstr.git"
|
2020-10-11 13:35:13 +02:00
|
|
|
goutil "git.gutmet.org/goutil.git/misc"
|
2019-01-01 19:41:03 +01:00
|
|
|
"path/filepath"
|
|
|
|
)
|
|
|
|
|
|
|
|
const Prefix string = "photos"
|
|
|
|
|
|
|
|
type Flags struct {
|
|
|
|
single string
|
|
|
|
clean bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func Generate(f Flags) error {
|
|
|
|
var err error
|
|
|
|
galleries := []string{Prefix + f.single}
|
|
|
|
if f.single == "" {
|
|
|
|
galleries, err = goutil.DirsWithPrefix(".", Prefix)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, g := range galleries {
|
|
|
|
fmt.Println("gallery: ", g)
|
|
|
|
args := finstr.Flags{InDir: g, OutDir: filepath.Join("stage0", g), Suffix: ".md", Clean: f.clean}
|
|
|
|
err = finstr.Generate(args)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func Command() (goutil.CommandFlagsInit, goutil.CommandFunc) {
|
|
|
|
f := Flags{}
|
|
|
|
flagsInit := func(s *flag.FlagSet) {
|
|
|
|
s.StringVar(&f.single, "single", "", "only generate single gallery instead of all (e.g. -single \"Holidays\" for folder 'photosHolidays')")
|
|
|
|
s.BoolVar(&f.clean, "clean", false, "remove old files in galleries before generating (use with caution)")
|
|
|
|
}
|
|
|
|
return flagsInit, func([]string) error {
|
|
|
|
return Generate(f)
|
|
|
|
}
|
|
|
|
}
|