copy other files

This commit is contained in:
Sebastian Frank
2019-02-12 20:04:07 +01:00
parent 7d408f5b7e
commit 8317aee801
5 changed files with 50 additions and 26 deletions

53
main.go
View File

@@ -40,6 +40,10 @@ type GlobalConfig struct {
Replace string `yaml:"Replace"`
} `yaml:"FixTemplate"`
} `yaml:"Assets"`
OtherFiles struct {
Action string `yaml:"Action"`
} `yaml:"OtherFiles"`
}
var globalConfig = new(GlobalConfig)
@@ -84,6 +88,7 @@ type PathConfigTree struct {
OutputPath string
InputFiles []string
OtherFiles []string
Config *PathConfig
Sub []*PathConfigTree
@@ -144,7 +149,7 @@ func readContentDir(inBase string, outBase string, dir string, conf *PathConfig,
inPath += "/" + dir
}
log.Noticef("reading input directory: %s", inPath)
log.Infof("reading input directory: %s", inPath)
files, err := ioutil.ReadDir(inPath)
if err != nil {
@@ -196,7 +201,7 @@ func readContentDir(inBase string, outBase string, dir string, conf *PathConfig,
outPath := outBase + "/" + stripedDir
outPath = path.Clean(outPath)
log.Noticef("calculated output directory: %s", outPath)
log.Infof("calculated output directory: %s", outPath)
tree.OutputPath = outPath
if tree.Config.This.Navname == nil {
@@ -207,12 +212,22 @@ func readContentDir(inBase string, outBase string, dir string, conf *PathConfig,
// first only files
for _, f := range files {
p := inPath + "/" + f.Name()
if strings.HasSuffix(f.Name(), ".md") {
log.Debugf(".MD %s", p)
if tree.InputFiles == nil {
tree.InputFiles = make([]string, 0)
if !f.IsDir() {
switch path.Ext(f.Name()) {
case ".md":
log.Debugf(".MD %s", p)
if tree.InputFiles == nil {
tree.InputFiles = make([]string, 0)
}
tree.InputFiles = append(tree.InputFiles, f.Name())
break
default:
log.Debugf("FIL %s", p)
if tree.OtherFiles == nil {
tree.OtherFiles = make([]string, 0)
}
tree.OtherFiles = append(tree.OtherFiles, f.Name())
}
tree.InputFiles = append(tree.InputFiles, f.Name())
}
}
@@ -312,7 +327,7 @@ func processContent(conf *PathConfigTree) {
if err != nil {
log.Panicf("could not read '%s':%s", inFile, err)
}
log.Noticef("processing input file '%s'", inFile)
log.Infof("processing input file '%s'", inFile)
newConfig := new(PathConfig)
@@ -346,7 +361,7 @@ func processContent(conf *PathConfigTree) {
}
if ignoreFile {
log.Noticef("ignoring file '%s', because of filename.ignore", inFile)
log.Infof("ignoring file '%s', because of filename.ignore", inFile)
} else {
// build output filename
@@ -433,6 +448,20 @@ func processContent(conf *PathConfigTree) {
}
}
// process other files, copy...
for _, file := range conf.OtherFiles {
switch globalConfig.OtherFiles.Action {
case "copy":
from := conf.InputPath + "/" + file
to := conf.OutputPath + "/" + file
log.Noticef("copying file from '%s' to '%s'", from, to)
err := cpy.Copy(from, to)
if err != nil {
log.Panicf("could not copy file from '%s' to '%s': %s", from, to, err)
}
}
}
for _, el := range conf.Sub {
processContent(el)
}
@@ -503,12 +532,12 @@ func main() {
if inDir == nil || *inDir == "" {
log.Panic("input directory not specified")
}
log.Noticef("input directory: %s", *inDir)
log.Infof("input directory: %s", *inDir)
if outDir == nil || *outDir == "" {
log.Panic("output directory not specified")
}
log.Noticef("output directory: %s", *outDir)
log.Infof("output directory: %s", *outDir)
if createOutDir != nil && *createOutDir {
if _, err := os.Stat(*outDir); os.IsNotExist(err) {
@@ -581,7 +610,7 @@ func main() {
for _, f := range entries {
if !f.IsDir() {
pFile := partialsPath + "/" + f.Name()
log.Noticef("registering partial: %s", pFile)
log.Infof("registering partial: %s", pFile)
pContent, err := ioutil.ReadFile(pFile)
if err != nil {
log.Panicf("could not read partial '%s': %s", pFile, err)