summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Paul <n@nc0.fr>2023-04-26 04:08:17 +0200
committerNicolas Paul <n@nc0.fr>2023-04-26 04:08:17 +0200
commit97d5f483eade5c84c07180cb3be467c7974a39f9 (patch)
tree6a3e5b8ee9074508494ca887bca9f383c6e30036
parent5e3c0bba0ff464a201e3b2677d8a7b4e795bba69 (diff)
Fix recursivity problem
The tool was not updating the output directory with nested directories' name, therefore everyhting was being generated at the root of the output directory
-rw-r--r--crocc.go17
-rw-r--r--testdata/.keep0
-rwxr-xr-xtestdata/build.sh9
3 files changed, 19 insertions, 7 deletions
diff --git a/crocc.go b/crocc.go
index 52fbd10..20f03e5 100644
--- a/crocc.go
+++ b/crocc.go
@@ -96,13 +96,17 @@ func main() {
htmlTemplate = *template.Must(template.New("html-template").Parse(string(tp)))
// Logic
- if err := Crocc(in); err != nil {
+ if err := Crocc(in, ""); err != nil {
log.Fatalf("unable to complete generation from %q: %v", in, err)
}
}
// Crocc is the function that applies to every file in a directory.
-func Crocc(root string) error {
+// child corresponds to the path of a nested subdirectory, relative to the root.
+// For example, if the root is "src" and the child is "foo/bar", the function
+// will be applied to "src/foo/bar".
+func Crocc(root string, child string) error {
+ outputPath := filepath.Join(*out, child)
files, err := os.ReadDir(root)
if err != nil {
return err
@@ -110,7 +114,6 @@ func Crocc(root string) error {
for _, file := range files {
filename := file.Name()
- log.Printf("processing %q", filename)
// Ignore template file
if filename == ".crocc.html" {
@@ -119,11 +122,11 @@ func Crocc(root string) error {
// If the file is a directory, create it in the output directory
if file.IsDir() {
- if err := TransformDirectory(root, filename, *out); err != nil {
+ if err := TransformDirectory(root, filename, outputPath); err != nil {
return err
}
- if err := Crocc(filepath.Join(root, filename)); err != nil {
+ if err := Crocc(filepath.Join(root, filename), filename); err != nil {
return err
}
@@ -135,7 +138,7 @@ func Crocc(root string) error {
filepath.Ext(filename) != ".markdown" &&
filepath.Ext(filename) != ".mdown" &&
filepath.Ext(filename) != ".Markdown" {
- if err := TransformNonMarkdownFile(root, filename, *out); err != nil {
+ if err := TransformNonMarkdownFile(root, filename, outputPath); err != nil {
return err
}
@@ -143,7 +146,7 @@ func Crocc(root string) error {
}
// Transform Markdown files into HTML
- if err := TransformMarkdownFile(root, filename, *out); err != nil {
+ if err := TransformMarkdownFile(root, filename, outputPath); err != nil {
return err
}
}
diff --git a/testdata/.keep b/testdata/.keep
deleted file mode 100644
index e69de29..0000000
--- a/testdata/.keep
+++ /dev/null
diff --git a/testdata/build.sh b/testdata/build.sh
new file mode 100755
index 0000000..940a977
--- /dev/null
+++ b/testdata/build.sh
@@ -0,0 +1,9 @@
+#!/usr/bin/env bash
+# Copyright (c) 2023 Nicolas Paul All rights reserved.
+# Use of this source code is governed by a BSD-style
+# license that can be found in the LICENSE file.
+
+
+set -e
+rm -rf testdata/dst
+./crocc -out=testdata/dst testdata/src