From 66a9ebe452be328339b0f37382532c1702f6e4e3 Mon Sep 17 00:00:00 2001 From: Sebastian Frank Date: Mon, 18 Mar 2019 13:37:22 +0100 Subject: [PATCH] fixed drone ci --- .drone.yml | 4 +- .gitignore | 3 +- mark2web/main.go | 145 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 148 insertions(+), 4 deletions(-) create mode 100644 mark2web/main.go diff --git a/.drone.yml b/.drone.yml index 27c514b..52c1d52 100644 --- a/.drone.yml +++ b/.drone.yml @@ -23,7 +23,7 @@ steps: image: alpine commands: - ./dist/mark2web-`cat VERSION`-linux-amd64 -version - - ./dist/mark2web-`cat VERSION`-linux-amd64 -in example -out example_out -create -logLevel debug + - ./dist/mark2web-`cat VERSION`-linux-amd64 -in _example -out example_out -create -logLevel debug when: event: [ push, tag ] @@ -81,7 +81,7 @@ steps: from_secret: rsync_pass commands: - /mark2web -version - - /mark2web -in website -out html -create -logLevel info + - /mark2web -in _website -out html -create -logLevel info - ' rsync -rlcgD -i -u -v --stats --delete diff --git a/.gitignore b/.gitignore index a6cca11..f0566f5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ test.html -html/ -mark2web \ No newline at end of file +html/ \ No newline at end of file diff --git a/mark2web/main.go b/mark2web/main.go new file mode 100644 index 0000000..9c25594 --- /dev/null +++ b/mark2web/main.go @@ -0,0 +1,145 @@ +package main + +import ( + "flag" + "fmt" + "os" + "path" + + "gitbase.de/apairon/mark2web" + "gitbase.de/apairon/mark2web/config" + "gitbase.de/apairon/mark2web/filter" + "gitbase.de/apairon/mark2web/helper" +) + +var ( + // Version is the app's version string + Version = "UNKNOWN" + // GitHash is the current git hash for this version + GitHash = "UNKNOWN" + // BuildTime is the time of build of this app + BuildTime = "UNKNOWN" +) + +var log = helper.Log + +var contentConfig = new(config.PathConfigTree) + +func main() { + inDir := flag.String("in", "./", "input directory") + outDir := flag.String("out", "html", "output directory") + createOutDir := flag.Bool("create", false, "create output directory if not existing") + //clearOutDir := flag.Bool("clear", false, "clear output directory before generating website") + logLevel := flag.String("logLevel", "info", "log level: debug, info, warning, error") + version := flag.Bool("version", false, "print version of this executable") + + flag.Parse() + if version != nil && *version { + fmt.Printf(`%11s: %s +%11s: %s +%11s: %s +`, "version", Version, "git hash", GitHash, "build time", BuildTime) + os.Exit(0) + } + + level := "info" + if logLevel != nil { + level = *logLevel + } + helper.ConfigureLogger(level) + + if inDir == nil || *inDir == "" { + log.Panic("input directory not specified") + } + iDir := path.Clean(*inDir) + inDir = &iDir + log.Infof("input directory: %s", *inDir) + + if outDir == nil || *outDir == "" { + log.Panic("output directory not specified") + } + oDir := path.Clean(*outDir) + outDir = &oDir + log.Infof("output directory: %s", *outDir) + + if createOutDir != nil && *createOutDir { + if _, err := os.Stat(*outDir); os.IsNotExist(err) { + log.Debugf("output directory '%s' does not exist", *outDir) + log.Debugf("trying to create output directory: %s", *outDir) + err := os.MkdirAll(*outDir, 0755) + if err != nil { + log.Panic(err) + } + log.Noticef("created output directory: %s", *outDir) + } else { + log.Noticef("output directory '%s' already exists", *outDir) + } + } + + if fD, err := os.Stat(*outDir); os.IsNotExist(err) { + log.Panicf("output directory '%s' does not exist, try -create parameter or create manually", *outDir) + } else { + if fD == nil { + log.Panicf("something went wrong, could not get file handle for output dir %s", *outDir) + } else if !fD.IsDir() { + log.Panicf("output directory '%s' is not a directory", *outDir) + } + } + + log.Debug("reading global config...") + configFilename := *inDir + "/config.yml" + err := config.ReadGlobalConfig(configFilename) + if err != nil { + log.Panicf("could not read file '%s': %s", configFilename, err) + } + config.Config.Directories.Input = *inDir + config.Config.Directories.Output = *outDir + + log.Debugf("reading input directory %s", *inDir) + + defaultTemplate := "base.html" + defaultInputFile := "README.md" + defaultOutputFile := "index.html" + defaultPathStrip := "^[0-9]*_(.*)" + defaultPathIgnoreForNav := "^_" + defaultFilenameStrip := "(.*).md$" + defaultFilenameIgnore := "^_" + defaultFilenameOutputExtension := "html" + + defaultPathConfig := new(config.PathConfig) + defaultPathConfig.Template = &defaultTemplate + defaultPathConfig.Index = &config.IndexConfig{ + InputFile: &defaultInputFile, + OutputFile: &defaultOutputFile, + } + defaultPathConfig.Path = &config.DirnameConfig{ + Strip: &defaultPathStrip, + IgnoreForNav: &defaultPathIgnoreForNav, + } + defaultPathConfig.Filename = &config.FilenameConfig{ + Strip: &defaultFilenameStrip, + Ignore: &defaultFilenameIgnore, + OutputExtension: &defaultFilenameOutputExtension, + } + defaultPathConfig.Imaging = &config.ImagingConfig{ + Width: 1920, + Height: 1920, + Process: "fit", + Quality: 75, + } + + mark2web.ReadContentDir(*inDir+"/content", *outDir, "", defaultPathConfig, contentConfig) + //spew.Dump(contentConfig) + + //spew.Dump(navMap) + + templatesDir := *inDir + "/templates" + mark2web.SetTemplateDir(templatesDir) + filtersDir := templatesDir + "/filters" + if _, err := os.Stat(filtersDir); !os.IsNotExist(err) { + filter.RegisterFilters(filtersDir) + } + mark2web.ProcessContent(contentConfig, contentConfig) + + mark2web.ProcessAssets() +}