2019-02-10 13:49:27 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2019-02-11 15:00:27 +01:00
|
|
|
"flag"
|
2019-02-18 13:05:30 +01:00
|
|
|
"fmt"
|
2019-02-11 15:00:27 +01:00
|
|
|
"os"
|
2019-02-10 13:49:27 +01:00
|
|
|
|
2019-02-27 17:33:26 +01:00
|
|
|
"gitbase.de/apairon/mark2web/config"
|
2019-02-27 15:58:10 +01:00
|
|
|
"gitbase.de/apairon/mark2web/helper"
|
2019-02-10 13:49:27 +01:00
|
|
|
)
|
|
|
|
|
2019-02-18 13:05:30 +01:00
|
|
|
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"
|
|
|
|
)
|
|
|
|
|
2019-02-27 17:33:26 +01:00
|
|
|
var log = helper.Log
|
2019-02-11 15:00:27 +01:00
|
|
|
|
2019-02-28 10:43:30 +01:00
|
|
|
var contentConfig = new(config.PathConfigTree)
|
2019-02-11 15:00:27 +01:00
|
|
|
|
2019-02-10 13:49:27 +01:00
|
|
|
func main() {
|
2019-02-28 12:13:28 +01:00
|
|
|
inDir := flag.String("in", "./", "input directory")
|
|
|
|
outDir := flag.String("out", "html", "output directory")
|
2019-02-11 15:00:27 +01:00
|
|
|
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")
|
2019-02-18 13:05:30 +01:00
|
|
|
version := flag.Bool("version", false, "print version of this executable")
|
2019-02-11 15:00:27 +01:00
|
|
|
|
|
|
|
flag.Parse()
|
2019-02-18 13:05:30 +01:00
|
|
|
if version != nil && *version {
|
|
|
|
fmt.Printf(`%11s: %s
|
|
|
|
%11s: %s
|
|
|
|
%11s: %s
|
|
|
|
`, "version", Version, "git hash", GitHash, "build time", BuildTime)
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
2019-02-11 15:00:27 +01:00
|
|
|
|
2019-02-27 17:33:26 +01:00
|
|
|
level := "info"
|
2019-02-11 15:00:27 +01:00
|
|
|
if logLevel != nil {
|
2019-02-27 17:33:26 +01:00
|
|
|
level = *logLevel
|
2019-02-11 15:00:27 +01:00
|
|
|
}
|
2019-02-27 17:33:26 +01:00
|
|
|
helper.ConfigureLogger(level)
|
2019-02-11 15:00:27 +01:00
|
|
|
|
|
|
|
if inDir == nil || *inDir == "" {
|
|
|
|
log.Panic("input directory not specified")
|
|
|
|
}
|
2019-02-12 20:04:07 +01:00
|
|
|
log.Infof("input directory: %s", *inDir)
|
2019-02-11 15:00:27 +01:00
|
|
|
|
|
|
|
if outDir == nil || *outDir == "" {
|
|
|
|
log.Panic("output directory not specified")
|
|
|
|
}
|
2019-02-12 20:04:07 +01:00
|
|
|
log.Infof("output directory: %s", *outDir)
|
2019-02-11 15:00:27 +01:00
|
|
|
|
|
|
|
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...")
|
2019-02-27 17:33:26 +01:00
|
|
|
configFilename := *inDir + "/config.yml"
|
|
|
|
err := config.ReadGlobalConfig(configFilename)
|
2019-02-11 15:00:27 +01:00
|
|
|
if err != nil {
|
2019-02-27 17:33:26 +01:00
|
|
|
log.Panicf("could not read file '%s': %s", configFilename, err)
|
2019-02-11 15:00:27 +01:00
|
|
|
}
|
2019-02-28 12:13:28 +01:00
|
|
|
config.Config.Directories.Input = *inDir
|
|
|
|
config.Config.Directories.Output = *outDir
|
2019-02-11 15:00:27 +01:00
|
|
|
|
|
|
|
log.Debugf("reading input directory %s", *inDir)
|
|
|
|
|
2019-02-14 13:46:33 +01:00
|
|
|
defaultTemplate := "base.html"
|
2019-02-12 10:21:51 +01:00
|
|
|
defaultInputFile := "README.md"
|
|
|
|
defaultOutputFile := "index.html"
|
2019-02-12 11:35:25 +01:00
|
|
|
defaultPathStrip := "^[0-9]*_(.*)"
|
2019-02-12 10:21:51 +01:00
|
|
|
defaultPathIgnoreForNav := "^_"
|
2019-02-12 11:35:25 +01:00
|
|
|
defaultFilenameStrip := "(.*).md$"
|
|
|
|
defaultFilenameIgnore := "^_"
|
2019-02-12 10:21:51 +01:00
|
|
|
defaultFilenameOutputExtension := "html"
|
|
|
|
|
2019-02-28 10:43:30 +01:00
|
|
|
defaultPathConfig := new(config.PathConfig)
|
2019-02-12 12:52:46 +01:00
|
|
|
defaultPathConfig.Template = &defaultTemplate
|
2019-02-28 10:43:30 +01:00
|
|
|
defaultPathConfig.Index = &config.IndexConfig{
|
2019-02-19 18:18:40 +01:00
|
|
|
InputFile: &defaultInputFile,
|
|
|
|
OutputFile: &defaultOutputFile,
|
|
|
|
}
|
2019-02-28 10:43:30 +01:00
|
|
|
defaultPathConfig.Path = &config.DirnameConfig{
|
2019-02-19 18:18:40 +01:00
|
|
|
Strip: &defaultPathStrip,
|
|
|
|
IgnoreForNav: &defaultPathIgnoreForNav,
|
|
|
|
}
|
2019-02-28 10:43:30 +01:00
|
|
|
defaultPathConfig.Filename = &config.FilenameConfig{
|
2019-02-19 18:18:40 +01:00
|
|
|
Strip: &defaultFilenameStrip,
|
|
|
|
Ignore: &defaultFilenameIgnore,
|
|
|
|
OutputExtension: &defaultFilenameOutputExtension,
|
|
|
|
}
|
2019-02-12 10:21:51 +01:00
|
|
|
|
2019-02-28 12:13:28 +01:00
|
|
|
helper.ReadContentDir(*inDir+"/content", *outDir, "", defaultPathConfig, contentConfig)
|
2019-02-12 10:21:51 +01:00
|
|
|
//spew.Dump(contentConfig)
|
2019-02-11 15:00:27 +01:00
|
|
|
|
2019-02-12 15:28:22 +01:00
|
|
|
//spew.Dump(navMap)
|
|
|
|
|
2019-02-28 18:36:36 +01:00
|
|
|
templateDir := *inDir + "/templates"
|
|
|
|
helper.SetTemplateDir(templateDir)
|
|
|
|
helper.RegisterFilters(templateDir + "/filters")
|
2019-02-28 12:13:28 +01:00
|
|
|
helper.ProcessContent(contentConfig, contentConfig)
|
2019-02-12 19:09:25 +01:00
|
|
|
|
2019-02-28 12:13:28 +01:00
|
|
|
helper.ProcessAssets()
|
2019-02-10 13:49:27 +01:00
|
|
|
}
|