This commit is contained in:
parent
b2e0d78a2c
commit
66a9ebe452
@ -23,7 +23,7 @@ steps:
|
|||||||
image: alpine
|
image: alpine
|
||||||
commands:
|
commands:
|
||||||
- ./dist/mark2web-`cat VERSION`-linux-amd64 -version
|
- ./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:
|
when:
|
||||||
event: [ push, tag ]
|
event: [ push, tag ]
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ steps:
|
|||||||
from_secret: rsync_pass
|
from_secret: rsync_pass
|
||||||
commands:
|
commands:
|
||||||
- /mark2web -version
|
- /mark2web -version
|
||||||
- /mark2web -in website -out html -create -logLevel info
|
- /mark2web -in _website -out html -create -logLevel info
|
||||||
- '
|
- '
|
||||||
rsync -rlcgD -i -u -v --stats
|
rsync -rlcgD -i -u -v --stats
|
||||||
--delete
|
--delete
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,2 @@
|
|||||||
test.html
|
test.html
|
||||||
html/
|
html/
|
||||||
mark2web
|
|
145
mark2web/main.go
Normal file
145
mark2web/main.go
Normal file
@ -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()
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user