much better
This commit is contained in:
@@ -27,7 +27,7 @@ func Generate(cfg *config.Config) GenerateResult {
|
||||
}
|
||||
cfg.AbsRoot = abs
|
||||
|
||||
var outputBase string
|
||||
var outputDir string
|
||||
|
||||
if cfg.AppendMode || cfg.SingleFile {
|
||||
absOutput, err := filepath.Abs(cfg.OutputPath)
|
||||
@@ -49,18 +49,17 @@ func Generate(cfg *config.Config) GenerateResult {
|
||||
return result
|
||||
}
|
||||
|
||||
outputBase = absOutput
|
||||
outputDir = absOutput
|
||||
} else {
|
||||
absOutput, err := filepath.Abs(cfg.OutputPath)
|
||||
if err != nil {
|
||||
result.Error = fmt.Errorf("resolve output path: %w", err)
|
||||
return result
|
||||
}
|
||||
absOutput = filepath.Join(filepath.Dir(absOutput), filepath.Base(absOutput)+"_dirmd")
|
||||
|
||||
if !cfg.AppendMode {
|
||||
if _, err := os.Stat(absOutput); err == nil && !cfg.Force {
|
||||
result.Error = fmt.Errorf("output %s exists (enable force)", absOutput)
|
||||
if _, err := os.Stat(absOutput); err == nil && !cfg.Force {
|
||||
if info, err2 := os.Stat(absOutput); err2 == nil && !info.IsDir() {
|
||||
result.Error = fmt.Errorf("output %s exists and is not a directory (enable force)", absOutput)
|
||||
return result
|
||||
}
|
||||
}
|
||||
@@ -71,7 +70,7 @@ func Generate(cfg *config.Config) GenerateResult {
|
||||
}
|
||||
|
||||
cfg.OutputPath = absOutput
|
||||
outputBase = absOutput
|
||||
outputDir = absOutput
|
||||
}
|
||||
|
||||
walkResult, err := walker.Run(cfg)
|
||||
@@ -96,6 +95,10 @@ func Generate(cfg *config.Config) GenerateResult {
|
||||
result.Files = generated
|
||||
} else {
|
||||
indexPath := cfg.OutputPath
|
||||
if !cfg.AppendMode && !cfg.SingleFile {
|
||||
indexPath = filepath.Join(outputDir, "index_"+repoName+".md")
|
||||
}
|
||||
|
||||
if err := renderer.Write(walkResult, indexPath, cfg.AppendMode, cfg.SingleFile); err != nil {
|
||||
result.Error = err
|
||||
return result
|
||||
@@ -106,7 +109,7 @@ func Generate(cfg *config.Config) GenerateResult {
|
||||
if cfg.ProtonDrive {
|
||||
remoteDir := cfg.DrivePath
|
||||
if remoteDir == "" {
|
||||
remoteDir = "/my-files/md/" + filepath.Base(outputBase)
|
||||
remoteDir = "/my-files/md/" + filepath.Base(outputDir)
|
||||
}
|
||||
|
||||
if err := drive.CheckAuth(); err != nil {
|
||||
@@ -121,6 +124,9 @@ func Generate(cfg *config.Config) GenerateResult {
|
||||
}
|
||||
} else {
|
||||
indexPath := cfg.OutputPath
|
||||
if !cfg.AppendMode && !cfg.SingleFile {
|
||||
indexPath = filepath.Join(outputDir, "index_"+repoName+".md")
|
||||
}
|
||||
if err := drive.Upload(indexPath, remoteDir); err != nil {
|
||||
result.Error = fmt.Errorf("drive upload: %w", err)
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user